Merge P2: the ADOS-2 association model (tea-lib Firth/ordinal port), MLflow model, bronze and gold

Hospital gate with the association step passed on SQLite (65 min) and Postgres (80 min, peak 5.2 GB): all 15 pairs match relacion_ados2 and all 470 scores relacion_ados2_paciente.
This commit is contained in:
2026-11-29 18:50:53 -06:00
7 changed files with 100 additions and 2 deletions
+8
View File
@@ -77,3 +77,11 @@ models:
values: [electrode, zone]
- name: site
data_tests: [not_null]
- name: tea_associations
columns:
- name: key
data_tests: [unique, not_null]
- name: tea_association_scores
columns:
- name: key
data_tests: [unique, not_null]
@@ -0,0 +1,21 @@
-- depends_on: {{ ref('eeg') }}
{% if staged_exists('eeg_association_scores') %}
select
a.key, a.model, a.eeg_id, a.pair, a.z, a.probability, a.reference_probability,
e.person_id, e.study_date
from {{ source('bronze', 'eeg_association_scores') }} as a
join {{ ref('eeg') }} as e
on a.eeg_id = {{ dbt.concat(['e.person_id', "'|'", 'cast(e.study_date as ' ~ dbt.type_string() ~ ')']) }}
{% else %}
select
cast(null as {{ dbt.type_string() }}) as key,
cast(null as {{ dbt.type_string() }}) as model,
cast(null as {{ dbt.type_string() }}) as eeg_id,
cast(null as {{ dbt.type_string() }}) as pair,
cast(null as {{ dbt.type_float() }}) as z,
cast(null as {{ dbt.type_float() }}) as probability,
cast(null as {{ dbt.type_float() }}) as reference_probability,
cast(null as {{ dbt.type_string() }}) as person_id,
cast(null as date) as study_date
where 1 = 0
{% endif %}
@@ -0,0 +1,32 @@
{% if staged_exists('eeg_associations') %}
select
a.key, a.model, a.level, a.n_cohort, a.biomarker, a.zone, a.kind, a.outcome_code,
a.event, a.method, a.n, a.odds_ratio, a.ci_low, a.ci_high, a.p, a.q,
a.sens_model, a.sens_odds_ratio, a.same_direction, a.reason,
cast(substr(a.model, 23) as integer) as champion_version
from {{ source('bronze', 'eeg_associations') }} as a
{% else %}
select
cast(null as {{ dbt.type_string() }}) as key,
cast(null as {{ dbt.type_string() }}) as model,
cast(null as {{ dbt.type_string() }}) as level,
cast(null as bigint) as n_cohort,
cast(null as {{ dbt.type_string() }}) as biomarker,
cast(null as {{ dbt.type_string() }}) as zone,
cast(null as {{ dbt.type_string() }}) as kind,
cast(null as {{ dbt.type_string() }}) as outcome_code,
cast(null as {{ dbt.type_string() }}) as event,
cast(null as {{ dbt.type_string() }}) as method,
cast(null as bigint) as n,
cast(null as {{ dbt.type_float() }}) as odds_ratio,
cast(null as {{ dbt.type_float() }}) as ci_low,
cast(null as {{ dbt.type_float() }}) as ci_high,
cast(null as {{ dbt.type_float() }}) as p,
cast(null as {{ dbt.type_float() }}) as q,
cast(null as {{ dbt.type_string() }}) as sens_model,
cast(null as {{ dbt.type_float() }}) as sens_odds_ratio,
cast(null as {{ dbt.type_boolean() }}) as same_direction,
cast(null as {{ dbt.type_string() }}) as reason,
cast(null as integer) as champion_version
where 1 = 0
{% endif %}
+2
View File
@@ -8,6 +8,8 @@ sources:
- name: eeg_metrics
- name: eeg_sites
- name: eeg_scores
- name: eeg_associations
- name: eeg_association_scores
- name: eeg_checks
- name: review_log
- name: staged__identity
+35
View File
@@ -282,3 +282,38 @@ def study(eeg_id: str) -> dict | None:
found = [dict(m) for m in metrics]
return {"id": eeg_id, "valid": head["valid"], "level": head["level"],
"age_months": head["age_months"], "metrics": found} # fmt: skip
ASSOCIATIONS = {
"key": {"data_type": "text"},
"model": _text(),
"level": _text(),
"n_cohort": {"data_type": "bigint"},
**{c: _text() for c in ("biomarker", "zone", "kind", "outcome_code", "event", "method")},
"n": {"data_type": "bigint"},
**{c: _number() for c in ("odds_ratio", "ci_low", "ci_high", "p", "q")},
"sens_model": _text(),
"sens_odds_ratio": _number(),
"same_direction": {"data_type": "bool", "nullable": True},
"reason": _text(),
}
ASSOCIATION_SCORES = {
"key": {"data_type": "text"},
**{c: _text() for c in ("model", "eeg_id", "pair")},
**{c: _number() for c in ("z", "probability", "reference_probability")},
}
def _save_association(name: str, version: int, rows: list[dict], columns: dict) -> None:
with engine().begin() as con:
if inspect(con).has_table(name, schema="bronze"):
con.execute(text(f"delete from bronze.{name}"))
_write(name, [{**row, "model": f"tea.ados2_association/{version}"} for row in rows], columns)
def save_associations(version: int, rows: list[dict]) -> None:
_save_association("eeg_associations", version, rows, ASSOCIATIONS)
def save_association_scores(version: int, rows: list[dict]) -> None:
_save_association("eeg_association_scores", version, rows, ASSOCIATION_SCORES)
+1 -1
Submodule WebApi updated: f830003abd...9e5aa20092
+1 -1
Submodule models updated: 8c910e7500...e71a7baac5