Cycle: answer each measure's latest periods after a run, so the first reader finds them stored
This commit is contained in:
@@ -124,3 +124,27 @@ def _last_load(repositories) -> datetime | None:
|
||||
"""The start of the domain's last load: what's known now, and stable until the next load."""
|
||||
_, ((last,),) = repositories.dbt_query_repository.rows(select(func.max(LOADS.c.inicio)))
|
||||
return last
|
||||
|
||||
|
||||
def answer_latest(project: str, repositories, manifest: Path, *, kinds: tuple[str, ...] = ("semestre", "mes"), latest: int = 2,
|
||||
today: date | None = None) -> int:
|
||||
"""Answers and stores each measure's `latest` periods of each kind started by `today`, asked as the dashboard asks them
|
||||
(every fact dated, what is known at the last load), so the first reader after a load finds them stored. The answers it
|
||||
gave; a measure whose rule is still undecided is skipped."""
|
||||
today = today or date.today()
|
||||
known = _last_load(repositories)
|
||||
periods = [p for kind in kinds
|
||||
for p in sorted((p for p in repositories.dim_periodo_repository.list(limit=10000, tipo=kind) if p.inicio <= today),
|
||||
key=lambda p: p.inicio)[-latest:]]
|
||||
given = 0
|
||||
for definition in definitions_of(project, manifest).values():
|
||||
answer_of, _ = ANSWERS[scoring_of(definition)]
|
||||
for period in periods:
|
||||
try:
|
||||
answer_of(project, definition, Question(definition.url, period.periodo_id, None, known),
|
||||
parameters=repositories.def_parametro_repository, periods=repositories.dim_periodo_repository,
|
||||
history=repositories.history_repository, queries=repositories.dbt_query_repository)
|
||||
except UndecidedRule:
|
||||
break
|
||||
given += 1
|
||||
return given
|
||||
|
||||
Reference in New Issue
Block a user