OCR only on the pages without text; otherwise routes; batches on Dask through its own API

This commit is contained in:
Roberto Treviño
2026-11-27 19:17:49 -06:00
parent 385cc5b80b
commit 0c78f8cf7d
5 changed files with 82 additions and 45 deletions
+2 -4
View File
@@ -11,7 +11,6 @@ from the valid studies.
from pathlib import Path
import pandas as pd
from joblib import Parallel, delayed
from models import cluster
from models.tea.eeg.analysis import analyze
@@ -48,9 +47,8 @@ def _one(key: str, edf: bytes, age: float) -> dict:
def measure(studies) -> list[dict]:
"""Each study's verdict and features, in listing order, each a task on the cluster
(models.cluster)."""
with cluster.batch(): # each task carries its recording: workers see no local folder
return Parallel(n_jobs=cluster.jobs())(delayed(_one)(key, Path(path).read_bytes(), age)
for key, path, age in studies) # fmt: skip
# each task carries its recording: workers see no local folder
return cluster.run(_one, ((key, Path(path).read_bytes(), age) for key, path, age in studies))
def tables(measured: list[dict]) -> dict[str, pd.DataFrame]:
+3 -5
View File
@@ -15,7 +15,6 @@ from pathlib import Path
import mlflow.pyfunc
import pandas as pd
from joblib import Parallel, delayed
from models import cluster
from models.tea.eeg import analysis, curves, reference
@@ -43,10 +42,9 @@ class Baseline(mlflow.pyfunc.PythonModel):
def analyze() -> int:
"""Every hospital EEG not analysed yet; then gold's TEA tables are rebuilt."""
pending = eeg.pending()
with cluster.batch(): # one task per EEG, carrying its recording (models.cluster)
tasks = (delayed(analysis.analyze)(eeg.signal(r["edf"]), r["birth_date"])
for r in pending) # fmt: skip
done = Parallel(n_jobs=cluster.jobs())(tasks)
done = cluster.run(
analysis.analyze, ((eeg.signal(r["edf"]), r["birth_date"]) for r in pending)
) # one task per EEG
found = dict(zip((r["edf"] for r in pending), done, strict=True))
eeg.save_analyses(found)
silver.build(["tea_eeg_analyses+", "tea_eeg_metrics+"])