4056297608
The Calcular riesgos button runs the domain score job, which only scored the curves: the association scores that become the RiskAssessments were written by the tea_eeg job alone, so a platform driven from the buttons had champions and no risk analyses. The domain routine now ends with the association, score relates it, and the gold build after a score is the TEA selection that includes the association tables.
83 lines
3.2 KiB
Python
83 lines
3.2 KiB
Python
from datetime import date
|
|
|
|
import dagster as dg
|
|
import pytest
|
|
from pydantic import ValidationError
|
|
|
|
from models.definitions import ScopeConfig, after_ingest
|
|
from models.tea.jobs import ASSOCIATION, JOBS, MODELS
|
|
from persistance import eeg
|
|
|
|
|
|
def test_scope_validation():
|
|
assert eeg.Scope().mode == "pending"
|
|
assert eeg.Scope(mode="first_n", n=3).n == 3
|
|
good = "p1|2024-05-06"
|
|
assert eeg.Scope(mode="ids", ids=[good]).ids == [good]
|
|
bad = [
|
|
{"mode": "first_n"},
|
|
{"mode": "first_n", "n": 0},
|
|
{"mode": "first_n", "n": 2, "ids": [good]},
|
|
{"mode": "ids"},
|
|
{"mode": "ids", "ids": [good], "n": 1},
|
|
{"mode": "ids", "ids": ["nobar"]},
|
|
{"mode": "ids", "ids": ["p|2024-5-6"]},
|
|
{"mode": "ids", "ids": ["|2024-05-06"]},
|
|
{"mode": "ids", "ids": [f"p{i}|2024-05-06" for i in range(501)]},
|
|
{"mode": "pending", "n": 1},
|
|
{"mode": "pending", "ids": [good]},
|
|
{"mode": "other"},
|
|
{"extra": 1},
|
|
]
|
|
for kwargs in bad:
|
|
with pytest.raises(ValidationError):
|
|
eeg.Scope(**kwargs)
|
|
assert len(eeg.Scope(mode="ids", ids=[f"p{i}|2024-05-06" for i in range(500)]).ids) == 500
|
|
with pytest.raises(ValidationError, match="first_n needs n"):
|
|
ScopeConfig(mode="first_n").model()
|
|
|
|
|
|
def test_the_domain_routine_scores_the_curves_then_relates_the_association():
|
|
assert JOBS.routine() == [*MODELS, ASSOCIATION]
|
|
|
|
|
|
def test_after_ingest_requests_a_run_only_with_pending_eegs():
|
|
skip = after_ingest("r1", lambda: False)
|
|
assert isinstance(skip, dg.SkipReason)
|
|
request = after_ingest("r1", lambda: True)
|
|
assert isinstance(request, dg.RunRequest)
|
|
assert request.run_key == "after-ingest-r1"
|
|
scope = request.run_config["ops"]["tea_analyze_studies"]["config"]["scope"]
|
|
assert scope == {"mode": "pending"}
|
|
assert request.tags["domain"] == "tea" and request.tags["triggered_by"] == "r1"
|
|
|
|
|
|
def test_tea_eeg_first_n_selects_exactly_n_pending_studies(fresh_platform):
|
|
with fresh_platform.begin() as con:
|
|
con.exec_driver_sql("create table silver.person (person_id text, birth_date text)")
|
|
con.exec_driver_sql("insert into silver.person values ('p1', '2023-01-01')")
|
|
con.exec_driver_sql("create table silver.eeg (person_id text, study_date text, edf text)")
|
|
con.exec_driver_sql(
|
|
"insert into silver.eeg values (?, ?, ?)",
|
|
[
|
|
("p1", "2025-01-01", "c"),
|
|
("p1", "2025-02-01", "b"),
|
|
("p1", "2025-03-01", "a"),
|
|
("p1", "2025-04-01", "d"),
|
|
("p1", "2025-05-01", None),
|
|
],
|
|
)
|
|
con.exec_driver_sql("create table bronze.eeg_analysis (edf text)")
|
|
con.exec_driver_sql("insert into bronze.eeg_analysis values ('b')")
|
|
|
|
birth = date(2023, 1, 1)
|
|
assert eeg.select(eeg.Scope(mode="first_n", n=2)) == [
|
|
{"edf": "a", "birth_date": birth},
|
|
{"edf": "c", "birth_date": birth},
|
|
]
|
|
assert eeg.select(eeg.Scope(mode="ids", ids=["p1|2025-02-01"])) == [
|
|
{"edf": "b", "birth_date": birth}
|
|
]
|
|
with pytest.raises(LookupError, match="has no signal"):
|
|
eeg.select(eeg.Scope(mode="ids", ids=["p1|2025-05-01"]))
|