Files read by hash; fractional Weibull solved and fitted to convergence; recurrence reads its reference cohorts from the platform

This commit is contained in:
Roberto Treviño
2026-11-26 14:25:53 -06:00
parent f305cdd044
commit 76eb8cc8af
8 changed files with 258 additions and 211 deletions
+7 -16
View File
@@ -43,11 +43,9 @@ from core.pipeline import (
matches,
validate,
)
from persistance import config_log, nodes, silver
from persistance import config_log, files, nodes, silver
MIN_WORDS = 5 # fewer than this from a PDF means it has no text layer
# Files kept whole (catalog `file` fields), once each, keyed by their content hash.
FILES = {"key": {"data_type": "text"}, "content": {"data_type": "binary"}}
READ_COLUMNS = { # declared, so a load where every file read cleanly still has `error`
"text": {"data_type": "text", "nullable": True},
"ocr": {"data_type": "bool"},
@@ -95,13 +93,11 @@ def read_file(content: bytes) -> dict:
def run_read(p: str, node: Read):
"""The input's rows with the file column replaced by its text; each file read once."""
rows = list(nodes.rows(p, node.inputs[0]))
keys = {}
for row in rows:
content = row.pop(node.column)
row["key"] = hashlib.sha256(content).hexdigest() if content else None
keys[row["key"]] = content
found = nodes.cached("read_cache", set(keys) - {None})
new = {k: c for k, c in keys.items() if k and k not in found}
for row in rows: # the source kept the file; the row carries its hash
row["key"] = row.pop(node.column) or None
keys = {r["key"] for r in rows} - {None}
found = nodes.cached("read_cache", keys)
new = {k: files.content(k) for k in keys - set(found)}
with ProcessPoolExecutor() as pool:
read = dict(zip(new, pool.map(read_file, new.values()), strict=True))
nodes.remember("read_cache", [{"key": k, **r} for k, r in read.items()], READ_COLUMNS)
@@ -389,14 +385,10 @@ def run_target(p: str, node: Target, kinds: dict[str, str]):
linked = {r[RECORD]: r for r in nodes.rows(p, link)}
person = {k: r["person_id"] for k, r in linked.items()}
model, study = catalog.model(node.entity), catalog.studies()[node.entity]
observations, held_rows, files = [], [], {}
kept = [n for n, f in study.fields.items() if f.type == "file"]
observations, held_rows = [], []
for i in (i for i in node.inputs if i != link):
for row in nodes.rows(p, i):
values = {f: row.get(f) for f in model.model_fields if row.get(f) is not None}
for name in (n for n in kept if n in values): # kept once, named by its hash
files[key := hashlib.sha256(values[name]).hexdigest()] = values[name]
values[name] = key
held = json.loads(row.get(HELD) or "[]") + validate(node.entity, values)
if row[RECORD] not in person:
held.append("no identity linked to this record")
@@ -414,7 +406,6 @@ def run_target(p: str, node: Target, kinds: dict[str, str]):
if (value := getattr(clean, name)) is not None:
observations.append({**base, "instance": instance, "field": name,
catalog.value_column(field): value}) # fmt: skip
nodes.remember("files", [{"key": k, "content": c} for k, c in files.items()], FILES)
nodes.stage("observation", p, node.id, observations, silver.OBSERVATION)
return nodes.stage("held", p, node.id, held_rows, silver.HELD_ROWS)