Dokumentation · Data og kilder
The declaration loader
DeclarationGridEmission from Energi Data Service into fx.factor_hour, as B11 built it (docs/architecture/phase-1.md §8; research docs/research/R2-energi-data-service.md §1, §2.2). The specification says what each rule is; this page
says where things are and how to run them. Since B51 (docs/architecture/phase-2.md §2.1, §2.2) the loader serves any
dataset of the service from a description of it ("A dataset, described", below), and every call of every dataset keeps
one pace, the service's.
| Part | Where |
|---|---|
| Client, file reader, window decoder, host guard, metadata, test doubles | libs/sources/src/elo_sources/eds/ (the decoder the loader and compare-declarations share: decode.py) |
| The loader, its window arithmetic, the command | services/worker/src/elo_worker/eds/ (loader.py, windows.py, runtime.py, __main__.py) |
| What a dataset is to the loader; the declaration's description | services/worker/src/elo_worker/eds/dataset.py (Dataset, DECLARATION, decode_rows) |
| One pace for the service | services/worker/src/elo_worker/eds/pace.py (ingest.service_pace, migration 0190_service_pace) |
| Slices of a job | services/worker/src/elo_worker/eds/slices.py |
| The declaration's two jobs | services/worker/src/elo_worker/jobs/eds_load.py (eds-load), eds_monthly_repull.py (eds-monthly-repull); the prices' two below |
| The transmission factors (B80) | eds/transmission.py (TRANSMISSION), eds/registry.py, jobs/eds_tx_load.py (eds-tx-load), jobs/eds_tx_monthly.py (eds-tx-monthly), migration 0320_factor_dataset_te, make status's status.transmission; the generated extract tools/src/elo_devtools/synth/transmission.py and its load demo_load.load_transmission |
| The municipal share (B81) | eds/recoverage.py (describe(codes, state_key=), window_days), migration 0323_municipal_share (ref.municipality, fx.re_coverage_hour and its history, ingest.municipality_setting, ingest.municipality_state); the generated extract tools/src/elo_devtools/synth/recoverage.py and its load demo_load.load_recoverage. The wanted set, the two descriptions and the jobs are B91's (next row) |
| The wanted set and its load (B91) | eds/recoverage.py (refresh, begin_catch_up, join, members, counts, catching_up, describe_set, describe_catch_up), jobs/eds_recoverage.py (eds-recoverage), jobs/eds_recoverage_monthly.py (eds-recoverage-monthly), Windows.repull_from_first_day (dataset.py, read by DatasetLoader.repull), make status's status.municipal_share. No migration |
| The transmission mix (B82) | eds/mix.py (TRANSMISSION_MIX, emission_inputs_pending), eds/registry.py, jobs/eds_tx_mix.py (eds-tx-mix), jobs/eds_tx_mix_weekly.py (eds-tx-mix-weekly), jobs/eds_tx_mix_monthly.py (eds-tx-mix-monthly), migration 0330_mix_dataset (fx.mix_hour.dataset, the key, calc.mix_hours), make status's status.transmission_mix; the generated extract tools/src/elo_devtools/synth/transmission_mix.py and its load demo_load.load_txmix |
| The grid's mix (B53) | eds/mix.py (GRIDMIX, the bounds of completeness), eds/registry.py, jobs/eds_mix.py (eds-mix), jobs/eds_mix_weekly.py (eds-mix-weekly), jobs/eds_mix_monthly.py (eds-mix-monthly), migrations 0215_grid_mix and 0216_mix_reference; the generated extract tools/src/elo_devtools/synth/mix.py |
| The prices (B52) | eds/prices.py (ELSPOTPRICES, DAYAHEADPRICES, below), eds/registry.py (the datasets by name), jobs/eds_prices.py (eds-prices), jobs/eds_prices_monthly.py (eds-prices-monthly), migration 0200_spot_prices; the generated extract tools/src/elo_devtools/synth/prices.py |
compare-declarations | tools/src/elo_devtools/validate/ |
| Tests | services/worker/tests/test_b91_wanted_set.py, services/worker/tests/test_b81_municipal_share.py, services/api/tests/test_b81_storage.py, tools/tests/test_b81_recoverage.py, services/worker/tests/test_b80_transmission.py, test_b80_status.py, services/api/tests/test_b80_factor_constraint.py, tools/tests/test_b80_extract.py, test_b80_demo.py, services/worker/tests/test_b53_grid_mix.py, test_b53_status.py, tools/tests/test_b53_mix_extract.py, services/worker/tests/test_b52_spot_prices.py, test_b52_status.py, tools/tests/test_b52_prices_extract.py, libs/sources/tests/test_eds_client.py, libs/sources/tests/test_eds_decode.py, services/worker/tests/test_eds_loader.py, services/worker/tests/test_b51_one_pace.py, tools/tests/test_validate_declarations.py |
Every table B11 writes is B03's (fx.*, ingest.dataset_state, raw.*, ops.data_version). B11's one migration,
0080_eds_loader_state (block 0080-0099, after the review B11v), adds columns only: ingest.dataset_state.cooldown_level,
in_flight, generated, observed_at, and generated on fx.factor_hour and fx.factor_hour_history.
Running
| What | How |
|---|---|
| The daily run (04:30, §1.2) | the job eds-load; by hand python -m elo_worker.eds load |
| The monthly re-pull (2nd of a month, 03:00) | the job eds-monthly-repull; by hand python -m elo_worker.eds repull |
| Files (the frozen extract, a snapshot) | python -m elo_worker.eds files fixtures/factors [--from 2026-02] [--to 2026-03]; no call is made. Another dataset: --dataset Elspotprices (B52); the generated prices: python -m elo_devtools.synth prices --out DIR, then files DIR --dataset <name> |
| A dataset by hand (B52) | python -m elo_worker.eds load [DATASET] and repull [DATASET]: DeclarationGridEmission (the default), Elspotprices, DayAheadPrices, DeclarationGridmix (B53), DeclarationTransmissionEmission (B80), DeclarationTransmissionGridmix (B82) |
| The prices (B52) | the jobs eds-prices (14:10 daily) and eds-prices-monthly (the 2nd, 03:20), below |
| The transmission factors (B80) | the jobs eds-tx-load (04:35 daily) and eds-tx-monthly (the 2nd, 03:10); by hand python -m elo_worker.eds load DeclarationTransmissionEmission and repull …, and files DIR --dataset DeclarationTransmissionEmission for the generated extract (python -m elo_devtools.synth transmission --out DIR); below |
| The transmission mix (B82) | the jobs eds-tx-mix (05:00 daily), eds-tx-mix-weekly (Sunday 05:45) and eds-tx-mix-monthly (the 2nd, 04:00); by hand python -m elo_worker.eds load DeclarationTransmissionGridmix and repull …, and files DIR --dataset DeclarationTransmissionGridmix for the generated extract (python -m elo_devtools.synth txmix --out DIR); below |
| The municipal shares, files (B81) | python -m elo_worker.eds files DIR --dataset ReCoverageMunicipality --municipalities 998,999 [--from …] [--to …]: the codes named, each a row of ref.municipality; a row of another municipality in a file is skipped. The generated extract: python -m elo_devtools.synth recoverage --out DIR. No live command: the wanted set is loaded by the jobs eds-recoverage (09:30 daily) and eds-recoverage-monthly (the 2nd, 03:15), below |
| After 24 November 2026 | python -m elo_devtools.validate compare-declarations --snapshot data/validation/declarations-2026-11-15 --database-url <a login that may read fx.factor_hour>; the lead records the result as docs/adr/ADR-003-declaration-restatement.md |
DATABASE_URL is the worker's. A job applies at most 30 windows and queues its successor (B51, "Slices" below); a
command run by hand applies every window of its run. The scheduling is B09's (elo_worker.schedule, Europe/Copenhagen, a check of the
database at every idle tick, not a timer: docs/daily-run.md): the times above are those of §1.2. In the demo stack
(ELO_DEMO=1) none of the jobs of Energi Data Service runs (the declaration's two, the prices' two, the mix's three and the transmission factors' two); make demo loads the files (§8).
ELO_EDS_BASE_URL (default https://api.energidataservice.dk) is the service's address. ELO_EDS_SPACING_S (default
60, a whole number of seconds from 1 to 3600) is the least time between the starts of two calls to it, of any dataset and
any process: migrate installs it as the owner in ingest.pace_setting.eds_spacing_s at every run, as the Eloverblik
pace, and every process reads it from there, never from its own environment (B51v-05). While tests run (pytest, or
ELO_FORBID_LIVE_API=1) the client accepts a local address only and refuses the real host in every spelling.
What a run does
Windows. Whole local days; the bounds are local midnights (§2). At most 468 days (67 392 rows, nine tenths of the budget
of 75 000 rows a response, B95f: it was 121 days under 17 500). The first load is from 1 January five years back (2020-12-31T23:00Z in 2026: 5 windows, 10 useful data calls — each window over 17 500 rows takes 1 boundary remainder — and 1 of metadata at 60 s, or 12 calls across 2 slices at 310 s); the daily run
the last 120 local days, today included (17 280 rows, one request); an outage longer than that is repaired from the end
of what was loaded (ingest.dataset_state.loaded_through); the monthly re-pull starts on 1 January of the previous year (2 windows, 4 data calls and 1 of metadata on 2 December 2026).
A response that reaches the budget is discarded and its window halved; the halves go into the run in the direction of
the stretch the window grows (B51w-01): the older half first when the window starts at what is loaded or applied (an
oldest-first load, a forward repair of a newest-first dataset), the newer half first when it ends there (a newest-first
load), the dataset's own direction when it touches neither.
Pace (B51: one for the service). At most one call per ELO_EDS_SPACING_S (60 s) to the service, of every dataset,
the metadata calls included: a 429 answered to one dataset cools every dataset down. The start is reserved in the one row
ingest.service_pace (next_start_at, cooldown_until, cooldown_level, in_flight) and committed before the call;
the completion moves it to a spacing after the response. One call is in flight, whatever process makes it (B51v-05):
a call holds the service's turn, the session advisory lock elo.eds.service, from its reservation to the transaction that
records its completion; another process waits for the turn (polling once a second, so the worker's stop ends the wait)
and then reads the row, so it sees a cooldown the first call's 429 set. After the wait for its start a call reads the
cooldown again. The pace columns of ingest.dataset_state are no longer read
or written; migration 0190_service_pace carried their latest deadlines, the highest level and a call in flight into
the row, so a cooldown running at the migration runs on. 429: the later of Retry-After plus 10 seconds and the local back-off (60 s ×
2^cooldown_level, capped at 900 s; the cap never applies to Retry-After; both forms of the header); the level goes up
by one with each 429 and back to 0 with the next applied response. 503, no response, a damaged response: Retry-After
plus 10 seconds or 60 seconds. Deadlines never move earlier. Three failures of one window in a row end the run
(WindowFailed); the next run waits for the stored deadline and continues the back-off from the stored level.
Across a restart. The deadlines, cooldown_level and in_flight are columns of ingest.service_pace. in_flight is
set with the reservation and cleared with the recorded completion; a run that finds it set (the process died before, during
or after a send, or before the response's transaction committed) counts that call as sent and starts the next one no earlier
than a minute from then. The clock is the host's (elo_sources.eds.Clock, simulated in the tests).
Applying a window (one transaction, with the record of the request): upsert on (price area, allocation, hour). A row
whose values, version or unexpected columns differ goes to fx.factor_hour_history first (cause 1); a key of the
window that the response no longer has goes there and is deleted (cause 2); a row that did not change is not touched
(it keeps the response that showed it). Numbers are compared at the scale of the columns (6 decimals). ops.data_version
goes up once when anything changed. A complete empty window removes what it held: the response is the truth about its window.
Only complete responses. total must equal the number of records and be below the budget; rows must be on the
hour, inside the window, in a known price area, with one row per key and values that fit the columns. Otherwise nothing of
the window is applied: a damaged response is asked for again (counts as a failure of the window), an unreadable one stops
the run (WindowFailed).
Numbers. Exact decimals from the response to the database: JSON numbers are read as Decimal, a factor value is rounded
to 6 decimals half away from zero (as PostgreSQL rounds a cast to numeric(p,6), whatever the process's decimal context) by
elo_sources.eds.decode.to_column, the function compare-declarations rounds with, and refused if the rounded value does not
fit its column.
Columns. An unexpected column is kept in extras (jsonb; a number with the digits it was delivered with) and listed in
ingest.dataset_state.columns_seen; make status (B09) reports columns_seen minus the expected and HourDK. An expected
column that is missing, in the rows or in the metadata's column list, stops the dataset: status = 2, nothing applied, a
DatasetStopped for this and every later run until a person sets it back
(UPDATE ingest.dataset_state SET status = 1 WHERE dataset = 'DeclarationGridEmission', as elo_owner).
Metadata. Each run reads /meta/dataset/DeclarationGridEmission first; lastMetadataUpdate is stored in
meta_last_update (and on each row loaded, fx.factor_hour.meta_updated_at), the SHA-256 of caution in
caution_sha256, and a different caution sets caution_changed_at. The text itself is not stored. A failed metadata
call is recorded and does not stop the run.
Files. The loader reads <dir>/DeclarationGridEmission/<yyyy-mm>.json.gz and _meta.json: a month file is the window
of its Danish month, applied exactly as a response is. The retrieval time is the file's _request.retrievedAt, else
_meta.json's _retrievedAt; a file with neither is refused.
Generated or real. A file that carries _generated (the frozen extract) is recorded as a demo load,
raw.fetch.source = 9, and its rows have fx.factor_hour.generated = true; a live response and any other file are source 3
and generated = false. The column is on every current and history row, so a query returns it with the values. A database
holds one origin or the other for the dataset, never both: ingest.dataset_state.generated is set by the first window
applied, and a load of the other origin is refused with OriginRefused before anything is written or called (a live run
into the demo database makes no call). The demo and CI hold generated factors, the owner's database real ones; to change
a database's origin, empty it and its history and set generated back to NULL, as elo_owner.
An older snapshot never rolls current back. A live response is what the service says now and is always applied. A file
retrieved before ingest.dataset_state.observed_at (the latest retrieval time applied, live or file) is applied only if it
changes nothing; a month of it that would change, add or remove a row is refused whole with StaleSnapshot. A key that
vanished upstream stays vanished. The exception is a database made for the validation of §9.4: whoever creates it marks it
with ALTER DATABASE <name> SET elo.purpose = 'validation' (only the database's owner or a superuser can; the loader reads
the mark from pg_db_role_setting, so a SET in a session does not count), and file mode then applies any snapshot.
What is recorded. Each call: raw.fetch (endpoint dataset/DeclarationGridEmission, meta/dataset/... or
file/..., the window as request_key) and one raw.fetch_item with dataset_window, the outcome (1 ok, 2 empty,
4 permanent, 5 retry later, 6 unreadable) and the three row counters. raw.payload (§3.1) keeps the body of an item that
inserted, changed or removed a row and of one refused as unreadable: dataset, total and each record's known columns as
delivered (decode.payload_body), never an unknown column or another field; a refused one also keeps the loader's own
reason, and a body that is not JSON keeps only that. Of metadata that stopped the dataset it keeps the names of the missing
expected columns, never a text of the metadata. Logs carry allowlisted fields only (loader.LOG_FIELDS).
A dataset, described
What B52, B53, B80 and B81 add for a dataset is a Dataset (elo_worker/eds/dataset.py), a job module that hands it to
elo_worker.eds.slices.run_slice, and their tables; the loader, the pace, the record of every call, the state's row,
the file mode and the slices are this code. A description has these fields; the declaration's own, DECLARATION, is
the example:
| Field | What it says | DECLARATION |
|---|---|---|
name | The dataset as the API names it: /dataset/<name>, /meta/dataset/<name>, the folder of its files; and, unless state_key names another, the row of ingest.dataset_state, the advisory lock elo.eds.<name>, the endpoints raw.fetch records | DeclarationGridEmission |
state_key (B81) | The row of ingest.dataset_state, the advisory lock elo.eds.<state_key>, the recorded endpoints (dataset/<state_key>, meta/dataset/<state_key>, file/<state_key>) and the chain's key (payload.dataset of a successor). The service's path and the metadata call stay the name's. Two descriptions of one dataset are two states of it: a retried attempt skips only what an earlier attempt applied under its own description's endpoint. state_name is the key in use | None: the name |
filter (B81) | The request's filter, ((column, (value, …)), …) (request_filter is the request's form) | the price areas: {"PriceArea":["DK1","DK2"]}, the bytes every request sent |
payload (B81) | What raw.payload keeps of a response that wrote or was refused: records, its known columns as delivered; none, only its dataset and total (a damaged response is then asked again, never read again from the database) | records |
table, conflict | The table and its primary key, on which a row is upserted | fx.factor_hour; dataset, price_area, allocation, hour_utc |
constants | Columns with one value on every row, in the key or not (outside the key they are compared as values) | dataset = 1 |
keys | The response's key columns as Columns, the time column first | HourUTC → hour_utc (time), PriceArea → price_area (area), FuelAllocationMethod → allocation (code: 125% 1, 200% 2, Total 3) |
values | The response's other kept columns, compared at the scale of their table column | CO2PerkWh → co2_g numeric(12,6) and the five other factors; Version → version (code: Initial 1, Preliminary 2, Final 3; a missing one refuses the response) |
known_unused | Columns known and not kept (never extras) | HourDK |
replacement (history) | row: a changed row goes to the history table with cause 1, a vanished one with cause 2; set: the window's rows are replaced without history (phase-2.md §2.4, the mix) | row (fx.factor_hour_history) |
step_minutes | The grid of the time column | 60 (DayAheadPrices: 15) |
windows | days local days a request; first_day(today); last_day (exclusive) of a dataset that ended; newest_first; daily_days; ahead_days | 468 days (B95f; 121 before); 1 January five years back; none; oldest first; 120; 0 |
sort | The request's sort | HourUTC,PriceArea,FuelAllocationMethod |
decode | Only for a decoder shared with other code | the shared elo_sources.eds.decode (compare-declarations reads with it, B11v-06) |
A Column is (source, name, kind, sql): the response's column, the table's, how its value is read, the table column's
type. Kinds: time (a …UTC wall time, on the grid, inside the window), area (a code of ref.price_area), code (a
name of the column's codes, stored as its number; another name refuses the response), text, member (B81: a key
column whose value must be one the request's filter named for its column; another value refuses a live response, and
in file mode the row is skipped, as a snapshot may hold every municipality), int (smallint, int,
bigint, refused outside the type), number (an exact decimal rounded half away from zero to numeric(p,6), refused
when it does not fit). null: keep (default) stores NULL, refuse refuses the response, skip stores no row (a stored
row of its key is removed with the window: phase-2.md §2.3, a price that is null). A key column is never NULL. Every
table a description names has generated, extras, retrieved_at, meta_updated_at and fetch_id; a history table
has the same and superseded_at, cause.
The scope of a replacement (B81) is the description's constants and its filter's members: a changed row goes to
the history, and a key the response no longer holds is removed, only among the rows of the constants' values and of
the members the request named (_Sql.of, a member column's = ANY (…)). A filter on another column (the price areas')
scopes nothing, as before, so the statements of every description of phase 1 and 2 are what they were.
Every other dataset is read by decode_rows from its columns: total equal to the records and below the budget, one
row per key, on the grid, inside the window, a known price area, a value that fits its column, an unknown column in
extras as delivered, a missing expected column (in the rows or the metadata) stopping that dataset alone.
A month file has a row limit of its own (B51v-07): FILE_ROW_BUDGET, 100 000 rows (file_row_budget). A file is not
halved as a response is, but it is applied in one transaction and decoded in memory; 100 000 is about twice the largest
month of a dataset of phase 2 (B53's mix, about 45 000 rows; the declaration's 4 464). A file that holds more is refused by
its month: WindowFailed("<yyyy-mm>: the file holds more than 100000 rows, the limit of a month file"). A loader given
an explicit row_budget holds a file to it too (the lower of the two): an explicit budget is never ignored.
What counts as loaded (loaded_from, loaded_through; B51v-01, B51w-01). The stretch of local days that holds what
was loaded: what the row held when the run began, and the windows the run applied, merged where they touch. A window
that does not touch it is applied and counts once the stretch reaches it. A slice that ends before then hands what it
applied apart from the stretch to its successor (applied in the chain's payload), and the slice that reaches the
stretch merges it, so no slice forgets what an earlier one of its chain applied. So the two never span a day that was not
applied, whatever the order of the windows, and a run beside a gap leaves the gap open.
When the stretch lies wholly before the dataset's first day (loaded_through earlier than first_day(today): an old
file load, a dataset left alone for years), no window of a run touches it. The first window applied at or after the first
day then starts the stretch again: from it on, loaded_from is the first day of what is loaded within the dataset's range
(the API's window), not of every row the table holds. The older rows stay in the table; they are no longer counted as
loaded, because nothing joins them to the range the runs keep.
The windows of a run (windows.plan). A run's own window starts on since (the daily run: the last daily_days
local days, today included; the monthly re-pull: 1 January of the previous year), or at the end of what was loaded if
that is earlier, and ends with today plus ahead_days, never after last_day. While the dataset is not loaded from its
first day the run goes on with the first load: oldest first, the whole range (the declaration, as phase 1), or newest
first, its own window and then back from the oldest day loaded, so that a run killed and run again asks no window of the
first load twice (the mix; and see "A retried attempt" below). A repair after an outage (what is loaded ends before since) goes forward from what is
loaded, oldest first whatever the direction, so that each window it applies counts at once.
Slices (slices.py, phase-2.md §2.2). A job applies at most 30 windows, then queues a job of its own kind with the
rest, a chain: {"dataset", "slice", "origin", "windows": [[first, after], ...], "slot"?, "repull_on"?, "applied"?}.
applied is what the chain applied apart from what is loaded, [[first, after], ...] (B51w-01). windows are
the windows still to make, exactly as the run planned or halved them, so a successor never asks for what is loaded
(B51v-01); origin is the job that started the chain; repull_on the day of a re-pull whose rest it carries. The dedup
key is <kind>:<slot>:<slice>, or <kind>:job-<origin>:<slice> for a job without a slot (B51v-08). The successor is due
from the instant it is queued; the declaration lane makes its own due jobs known before each claim, due from their slot's
opening, so a daily job whose slot opened during a slice runs before the successor (B51v-03, docs/daily-run.md). The
detail of a job's run says next_slice when it queued a successor, carried_by (a job id) when it added its rest to a
chain, and slice when it was one.
A retried attempt asks no window its job applied before (B53, the lead's ruling on the mix's first load, which is
73 windows and about 7 hours at the measured pace since B95f; it was 431 calls). A job whose attempt died (the worker killed) or was released (the worker's stop, make up
during the first load: the queue releases the job and it is due again at once) is claimed again with the same payload.
That attempt does not ask again a window that an earlier attempt of the same job applied: the loader decides it from
the record of the requests (raw.fetch of this dataset made while an earlier attempt of the job ran, whose item
says ok or no data, i.e. the window's own transaction committed; a window that was halved is covered by its applied
halves), never from the state's stretch, so a re-pull's slice still asks again the windows that were loaded before its
job began. A window so skipped counts as a window of the slice (resumed in the run's detail), goes into the run's cover
and the state's stretch as an applied window does (so loaded_from/loaded_through end as they would without the
kill, also when the earlier attempt's stretch lay apart from what is loaded), and costs no call; the metadata is read
again. The first slice of a job (no windows in its payload) plans from the state as before, and now also skips its own
window that the dead attempt applied: a slice of 30 windows killed after the 7th asks the windows it had not applied, never
one twice. (Before B53 an attempt asked every window of its payload
again, "idempotent": 12 windows of 30 asked again after a kill at the 12th.) A slice that is retried applies at most
30 windows itself, so with the dead attempt's it may have made more than 30 calls in all.
One chain per dataset (B51v-04). While a chain of the dataset is queued, a run of any of its jobs (the daily job, the
re-pull) makes its own window only, from since, and adds what it leaves after 30 windows to the end of that chain; it
never queues a second one. Its windows count as loaded only where they touch what is loaded: beside an oldest-first first
load that is not finished, the daily job's window stays outside loaded_through until the chain reaches it, so the gap
is never hidden; beside a newest-first one, the daily job's window touches what is loaded and extends it, and the chain
goes on below.
last_full_repull_on is stamped when a re-pull has ended, its last slice included (B51v-06).
A chain that failed (three attempts used up) is taken up again from what remains (B51v-06). A chain of a first load or
of a repair: by the dataset's next daily job, within a day, which plans from what is loaded. A chain that carries a
re-pull (its windows are loaded already, so what is loaded does not show them): queued again with its own windows, under
its own key, by the declaration lane's check, 1 hour after it failed, then 6 hours, 1 day and daily (PARK_DELAYS, as a
failed scheduled job), and only while no chain of its dataset is queued. Its windows are dates: neither the next month
nor 1 January loses one. It is taken up at most 8 times (PARK_TRIES, as a parked chunk: 1 hour, 6 hours, then six
times daily), and not at all once a later re-pull of its dataset has ended (last_full_repull_on later than its
repull_on; B51w-02). The check that decides so writes the reason into the detail of the failed job's last attempt,
given_up (the number of take-ups) or superseded (the later re-pull's day), and never looks at that job again.
The prices (B52)
Two datasets, one table (price.spot, phase-2.md §2.3), described in elo_worker/eds/prices.py: Elspotprices
(PT1H, no longer updated; its last record of DK1 is HourUTC 2025-09-30T21:00) before the seam, DayAheadPrices
(PT15M, updated daily; its first record of DK1 is TimeUTC 2025-09-30T22:00) from it. The seam is local midnight of
1 October 2025, 2025-09-30T22:00Z, and a check of the table (dataset = 1 AND resolution = 60 before it,
dataset = 2 AND resolution = 15 from it, the start a multiple of the resolution to the microsecond): no gap and no
double hour are properties of price.spot, and each loader keeps to its side of the seam by its windows (first_day,
last_day), a row the response puts outside its window refusing the response.
Elspotprices | DayAheadPrices | |
|---|---|---|
| Columns | HourUTC, HourDK (known, not kept), PriceArea, SpotPriceDKK, SpotPriceEUR | TimeUTC, TimeDK, PriceArea, DayAheadPriceDKK, DayAheadPriceEUR |
price.spot | dataset 1, resolution 60, dkk_per_mwh, eur_per_mwh | dataset 2, resolution 15 |
| Windows | 1 406 local days (67 488 rows at 48 a day), from 1 January 2021, to the seam: 2 windows (3 data calls: 2 on the 1 406-day window and 1 on the 328-day one), once | 351 local days (67 392 rows at 192 a day), from the seam, to the end of tomorrow: 2 windows on 26 November 2026 (3 data calls: 2 on the 351-day window and 1 on the 73-day one; +1 remainder on the newest window once it returns over 17 500 rows, e.g. 92 local days spanning autumn DST with tomorrow published on 16 December 2026: 17 672 rows vs 17 480 unpublished) |
| Daily run | none: it is loaded in full once and left alone (no call, not even its metadata) | the last 7 local days to the end of tomorrow, 1 call (tomorrow's prices are published about 13:00) |
| Monthly | – | from the later of the seam and 1 January of the previous year (3 data calls — 2 on the 351-day window and 1 on the newest — on 2 December 2026; 4 data calls once the newest window passes 17 500 rows) |
A null DKK price is not stored (null="skip": its interval has no price, a stored row of its key is removed with
its window) and make status counts the expected intervals without a price; a null EUR price is NULL. A negative
price is stored with its sign. A changed or vanished price goes to price.spot_history first with its cause (1, 2),
and ops.data_version goes up once.
eds-prices is a job of two datasets: it runs Elspotprices while that is not loaded in full and no chain of it is
queued, then DayAheadPrices (the first load of the history after its own window, as the declaration's).
DayAheadPrices loads every day whatever Elspotprices does (B52f, B52v-01): the dataset that ended runs in a
transaction of its own and its failure (DatasetStopped, WindowFailed, LoaderBusy, any error) is caught and named in
the job's detail (datasets.Elspotprices.failed: the class, reason: the loader's own sentence), what it applied and
queued stays, and make status flags it until a run of it succeeds or it is loaded in full; the job's outcome is
DayAheadPrices's. The cost while Elspotprices fails: a window that fails three times is 1 metadata call and 3 data
calls a day, a dataset that is stopped none (the loader refuses before it calls), and DayAheadPrices' 2 beside them;
a stop is set back by a person (UPDATE ingest.dataset_state SET status = 1 WHERE dataset = 'Elspotprices', as
elo_owner). Each loader
applies at most 30 windows in a slice and queues the rest as a chain of its own, under the key
<kind>:<slot>:<dataset>:<slice> (run_slice(..., per_dataset=True)): the two chains of one slot never share a key.
A successor's payload names its dataset and the job runs that dataset alone. A job without a slot keys its successors
<kind>:job-<origin>:<dataset>:<slice>. The detail of a job's run holds the sums
and each dataset's own under datasets. Tomorrow's prices are published about 13:00 and the job runs at 14:10; when they are not there yet the response is
complete all the same (it holds the days up to today) and is applied, and the day is not asked again that day. The next
day's run asks the last 7 days again and fills it (2 calls a day, one of metadata and one of data), and a cost needs a
price only where there is a reading, which is a day old at the least. make status never counts today or tomorrow as
holes. The first load on 26 November 2026 is 6 calls of data, and each loader reads
the metadata of its dataset once, 8 calls in all (41 minutes at 310 s; 9 calls at 60 s or 10 across 2 slices at 310 s once DayAheadPrices' newest window passes 17 500 rows).
The extract of the demo and CI is generated at load, not committed (tools/src/elo_devtools/synth/prices.py): the cases
the rules need (hours before the seam and quarters from it, negative prices, an hour with one quarter missing, a null
price in each dataset, no price for the last two days) are at fixed places, and make demo loads it through the loader's
file mode (demo_load.load_prices), so every row is generated and no call is made.
The transmission factors (B80)
DeclarationTransmissionEmission (TE, PT1H) into fx.factor_hour as dataset 2, described in
elo_worker/eds/transmission.py (docs/architecture/municipality-method.md §3.1, §3.3, §3.4). It is the declaration's
twin for the electricity that passes through the transmission grid, excluding what a municipality's own renewable
production covered: the same eleven columns, "only the data differ" (R2 §2.2.7). The municipal methods read it (B83);
no answer of phase 1 or 2 does (every reader of the table that names a dataset says dataset = 1).
| The description | The declaration's with its name and its constant changed and nothing else (dataclasses.replace(DECLARATION, name=…, constants=(("dataset", 2),), decode=None)): the same table and history table, key (dataset, price_area, allocation, hour_utc), columns, windows and row replacement. It has no decoder of its own: the declaration's shared one checks the name DeclarationGridEmission, so TE is read by decode_rows from the same columns, which checks this description's name |
| The table | fx.factor_hour, CHECK (dataset IN (1, 2)) (migration 0320_factor_dataset_te; 0008 had dataset = 1); the history table has the column without a check. The privileges are as they were |
| Its own, besides the data | The state row of ingest.dataset_state (DeclarationTransmissionEmission: loaded_from/loaded_through, generated, status, columns_seen, the notice), the advisory lock elo.eds.DeclarationTransmissionEmission, the recorded endpoints dataset/… (file/… in file mode) and meta/dataset/…. The pace is the service's one |
| Windows | 468 local days (67 392 rows at 144 a day, nine tenths of the budget of 75 000; halved when a response reaches it; B95f: 121 days and 18 calls before), oldest first, from 1 January 2021 (2020-12-31T23:00Z): 5 windows (10 useful data calls, 2 per window; 11 calls total at 60 s, or 12 across 2 slices at 310 s) for the first load on 26 November 2026 (2 156 days) |
eds-tx-load | daily 04:35: the last 120 local days, one call of data and one of metadata; the first load is this job's alone (in slices of 30 windows, a chain eds-tx-load:<slot>:<slice> for what is left) |
eds-tx-monthly | the 2nd of each month, 03:10: from 1 January of the previous year, 2 windows (4 data calls, 2 per window) and 1 of metadata on 2 December 2026; on a dataset not loaded from its first day it ends at once, {"skipped": "awaiting_first_load"} |
| The two traps of a shared table | A reload of a window of GE leaves TE's rows of the same hours untouched, in the table and in the history, and the reverse. The loader scopes a replacement, a history row and a vanished row to the description's constants, and dataset is among them (_Sql.of): test_b80_a_reload_of_a_ge_window_*, test_b80_a_reload_of_a_te_window_*. A changed TE row leaves one history row of dataset 2 (cause 1; 2 when it vanished) and changes no row of dataset 1 |
| Generated extract | python -m elo_devtools.synth transmission --out DIR (synth/transmission.py; not committed: make demo, the demo load and CI generate it at load): the shape of the frozen GE extract (144 rows a day, the versions by the age of the hour, no row for the last days) with every value column different from GE's of the same hour (CO2 a quarter higher, other constants for the gases and incineration CO2, loss factors 1,0145 and 1,0387), so that a test tells the datasets apart. demo_load.load_transmission loads it through the file mode (raw.fetch.source = 9, every row generated) for the months of the frozen GE extract; the origin of TE's rows is checked with the prices' and the mix's before any file of them is loaded. The demo load's counts say each dataset apart: factor_rows is GE's, transmission_rows TE's |
make status | The declaration's lines as they were (declaration: …), and TE's under its own name (DeclarationTransmissionEmission: …): the origin, the latest hour of dataset 2, loaded from and through, the hours after the latest still without a factor, the notice, ! for not loaded outside the demo, stopped, unknown columns; two more runs, "transmission run" (! when it has never succeeded outside the demo) and "transmission monthly re-pull". The cooldown is the service's, said once |
The municipal share (B81)
ReCoverageMunicipality (RE, PT1H, published about ten days behind) into fx.re_coverage_hour, described in
elo_worker/eds/recoverage.py (docs/architecture/municipality-method.md §3.1, §3.3, §3.7, §4): per municipality and UTC
hour the share of its consumption that its own renewable production covered (REshare → re_share_pct, a
percentage), that energy (REekWhKeep → re_kwh_keep) and the consumption (ConsumptionkWh → consumption_kwh).
The municipal methods read the share (B83); no answer of phase 1 or 2 does.
| The description | recoverage.describe(codes, state_key=None): the filter {"MunicipalityNo": [codes, sorted, each once]}, MunicipalityNo → municipality_code a key column of kind member, the three values null="keep", HourDK known and not kept, row replacement into fx.re_coverage_hour_history, payload="none". One request per window names every municipality of the description. The set and the catch-up of §3.1 are two descriptions with two state keys (ReCoverageMunicipality, ReCoverageMunicipality+catchup), built by B91 from ingest.municipality_state |
| Windows | 67 500 div (24 k) local days for k municipalities (window_days, B95f): at most 67 488 rows a call, k more on the 25-hour day. 2 812 days for one, 937 for three, 28 for 98. Newest first, from 1 January five years back (TE's first day), the daily run the last 30 local days |
| What is stored | As delivered: a NULL share and one outside 0 to 100 are stored (numeric(12,6), no check on the range) and read as pending by the calculation, never corrected here. A row of a municipality the request did not name refuses the response (live) or is skipped (file mode) |
| The trap of the shared table | A reload of 999 changes no row of 998, in the table or the history: the replacement is scoped to the members the request named (test_b81_a_reload_of_999_*). Without that scope, measured, the reload of 999 removed all 24 rows of 998 in its window |
| Privacy (§4) | No row of raw.* and no job payload names a municipality: the request's key is the window, the endpoint the description's state key, a kept body is {"dataset", "total"}, a chain's payload holds windows. The client keeps the query (the filter) out of httpx's own log line of each request (QueryOutOfLog): before B81 that line, at INFO, carried every request's URL, and RE's URL names its municipalities (test_b81_no_row_of_raw_and_no_job_payload_holds_zz8_or_zz9) |
ref.municipality | The 98 municipalities of the saved sample derived_grid-area-and-municipality-to-price-area_2026-08.json (its 99 codes less the placeholder 999); name_da NULL until the lead's ruling on the names (§3.3). A demo or test municipality is a row with generated: the demo load adds 999 and 998 through ref.add_generated_municipality(code, name), the owner's function (the worker only reads ref), which refuses a code of the reference and a database that holds real shares |
| The setting and the state | ingest.municipality_setting: one row, municipalities (auto or the list, sorted, each code once: installed by migrate from ELO_MUNICIPALITIES, B92) and names (ELO_MUNICIPALITY_NAMES, B92); ingest.municipality_state: per municipality its state (0 no longer wanted, 1 waiting, 2 catching up, 3 in the set), reason (1 the list, 2 a root) and wanted_since (B91 writes it) |
| Generated extract | python -m elo_devtools.synth recoverage --out DIR (synth/recoverage.py; not committed): 999 and 998, 24 rows a day from 1 January 2021, shares with hours of exactly 0 and exactly 100 in both, one NULL share (NULL_HOUR, 999, 2025-03-12T10:00Z), one above 100 (ABOVE_HOUR, 998, 2025-06-18T11:00Z, 104,5), no row for the last ten days before the anchor, no row of 998 on GAP_DAY (17 September 2025). demo_load.load_recoverage adds the two rows of ref.municipality and loads the extract through the file mode with the filter of the two (raw.fetch.source = 9, every row generated); the origin is checked with the other extracts' before any file is loaded; the counts give recoverage_rows |
The wanted set and its load (B91)
Which municipalities are loaded is the owner's rule (docs/architecture/municipality-method.md §3.2): the setting
ingest.municipality_setting, auto (the default, and the only value the repository holds) or a list of codes (B92
installs it from ELO_MUNICIPALITIES). Under auto the wanted set is **the usable codes of the E17 roots of every
account**: the municipality_code of a root's current master-data version, usable when it is a row of
ref.municipality; a child, a root of another type and a root without a usable code want nothing.
| When the set is computed | At the start of every run of eds-recoverage (recoverage.refresh, its own transaction), into ingest.municipality_state. A code newly wanted, or wanted again after state 0, waits (state 1, wanted_since now); a wanted code keeps its state and takes the current reason (1 the list, 2 a root); a code no longer wanted gets state 0 and is in no later request. Every code at state 0 loses its rows of fx.re_coverage_hour and of the history in the same run (B92: fx.forget_municipality(code), the owner's function, which the worker may execute: it refuses a code whose state is not 0 and deletes from those two tables only; the worker's role has no DELETE on the history). The state row stays, with state 0. B92f: the refresh locks ingest.municipality_state (SHARE ROW EXCLUSIVE) before it reads the wanted set, so the set it writes is the set it read; and the function refuses a code that is wanted now by ingest.wanted_municipalities(), the one SQL rule of the wanted codes (the worker's wanted is held equal to it by a test). Both jobs, eds-recoverage and eds-recoverage-monthly, hold the advisory lock elo.eds.recoverage for their whole run, from the reading of the members to the last write; make account-remove refuses while it is held, and a job that starts during a removal waits for its commit |
| A catch-up begins | When none is under way (no municipality in state 2 and no chain of the catch-up queued), the waiting ones begin one together (state 2) and the catch-up's state row (ReCoverageMunicipality+catchup) is cleared: its stretch was another membership's. A municipality wanted while a catch-up runs waits for it to join |
| The two descriptions | Built at each run from the states: the set (state 3) under the dataset's name, the catch-up (state 2) under ReCoverageMunicipality+catchup; each its own state row, lock, recorded endpoint and chain (B81), one request per window naming every member, one metadata call per run. A description without a member does not run |
| The set | Its last 30 local days, 1 data call while it has at most 24 municipalities (for 98 municipalities, 2 windows of 28 and 2 days: 2 calls on the 28-day window and 1 on the 2-day one, 3 data calls); its first load only if its stretch was lost |
| The catch-up | An ordinary first load, newest first: its own last 30 days, then back to 1 January five years back in windows of 67 500 div (24 k) days (B95f; windows.days_for): 4 calls (30d + 2 126d: 1 + 2 data + 1 meta) for one municipality, 8 at 60 s or 9 across 2 slices at 310 s for three (on 26 November 2026; 76 × 28 + 2 + 26 days = 78 windows: 160 calls across 5 slices at 60 s or 181 calls across 26 slices at 310 s for 98) |
| The joining | When the catch-up's stretch runs from the first day through the set's last day (a set without a member has no stretch and takes the catch-up's), its municipalities join the set (state 3), in one transaction (recoverage.join), at the end of the run or of the catch-up's slice that reached the first day. So the first load of an install is one catch-up of the whole wanted set, and a municipality added later is loaded without a call for the others' history |
| Slices, a retried attempt | At most 30 windows a slice; the rest a chain of its description, keyed eds-recoverage:<slot>:<state key>:<slice>, whose payload names no municipality: a successor rebuilds its description from the states when it runs (membership changes only at the joining), and ends at once, {"skipped": "no_members"}, when the description has none. A retried attempt skips what an earlier attempt of its job applied under its own description's endpoint: killed after the set's window, the retry asks that window no second time and every window of the catch-up |
eds-recoverage-monthly | The 2nd, 03:15: the set from its first day (Windows.repull_from_first_day): RE has no version and was republished whole on 5 November 2026, so only a whole reload sees a restatement; 3 windows (6 data calls, 2 per window) and 1 of metadata for three municipalities on 2 December 2026. It ends at once with {"skipped": "awaiting_first_load"} while the set has no member or is not loaded from its first day; a catch-up is not its concern |
| What a job records | Counts only: municipalities (waiting, catching up, in the set), added, dropped, begun, joined, and each description's own detail under its state key (datasets). No log line, detail or payload names a municipality (§4; test_b91_no_captured_log_line_or_record_of_a_run_holds_a_municipality searches the worker's whole log of a load at DEBUG) |
| For B82 | recoverage.catching_up(connection): a municipality waits or catches up (the rule that holds eds-tx-mix's first load back, §3.4) |
make status (§3.6), in the section "energi data service": the setting (auto, or "a list of n"); the set and the
catch-up, each with its origin, what is loaded and its last run (stopped and unknown columns flagged); per municipality
of ingest.municipality_state its label (the name ref.municipality has, otherwise the code: the owner's terminal),
its state in words, why it is wanted ("wanted for n root(s)", "wanted by the list"), its newest hour and, in the set,
the hours before it without a row; ! per municipality the shares missing or outside 0-100 with the first and last
hour; plainly the rows the last monthly reload restated; ! the E17 roots without a usable municipality, by mp_id.
A municipality not loaded yet is a plain line, "waiting" or "catching up". Under a list only (B92): ! n metering point(s) in a municipality the list leaves out: mp …, by mp_id: their hours are noMunicipality
(municipality_not_loaded) under the municipal methods; never under auto.
The setting's path (B92). ELO_MUNICIPALITIES is set in the shell of make up or in .env.local
(docs/operations.md, the settings) and installed by migrate as the owner: the one writer of the value, which stores
it normalised (sorted, each code once, no space), so that the worker's recoverage.setting() and
calc.mp_municipality's string_to_array(municipalities, ',') read the same set
(services/api/tests/test_b92_setting.py::test_the_workers_set_and_the_functions_wanted_are_equal). An item that is
not three digits refuses the start before the upgrade, a code that is no row of ref.municipality after it, each
naming its position and never its value. A changed setting raises ops.data_version.
The transmission mix (B82)
DeclarationTransmissionGridmix (TM, PT1H) into fx.mix_hour as dataset 2, described in elo_worker/eds/mix.py
(docs/architecture/municipality-method.md §3.1, §3.3, §3.4, §3.5). It is the grid mix's twin for the electricity that
passes through the transmission grid, excluding what a municipality's own renewable production covered: the same
columns, "only the data differ" (R2). The municipal split reads it (B87); no answer of phase 1 or 2 does.
| The description | GRIDMIX with its name and its constant changed and nothing else (dataclasses.replace(GRIDMIX, name="DeclarationTransmissionGridmix", constants=(("dataset", 2),)); a test pins it): the same table, columns, windows of 30 local days newest first (about 49 000 rows a window at the snapshot's densest month, 1 624 rows a day, below the budget of 75 000; B95f), set replacement and no history. GRIDMIX itself gains constants dataset = 1 and dataset first in conflict, so its upsert meets the new key and its replacement is scoped to its own dataset |
| The table | fx.mix_hour: dataset smallint NOT NULL DEFAULT 1 CHECK (dataset IN (1, 2)), the first column of the key (dataset, price_area, hour_utc, connected_area, report_grp_code), migration 0330_mix_dataset; every stored row is dataset 1. calc.mix_hours, the only SQL reader, reads dataset = 1 in both its reads until B87 gives it the parameter, so every answer of mix.structure, mix.series and report.footprint is what it was, also with TM loaded beside (test_b82_mix_dataset.py; B78's and B66's tests) |
| Its own, besides the data | The state row DeclarationTransmissionGridmix of ingest.dataset_state, the advisory lock elo.eds.DeclarationTransmissionGridmix, the recorded endpoints dataset/… (file/… in file mode) and meta/dataset/…, a chain eds-tx-mix:<slot>:<slice> of its own. The pace is the service's one |
| The two traps of a shared table | A reload of a window of GM in which an hour has fewer rows leaves that hour's TM rows as they were (fetch ids and retrieval times included), and the reverse. The loader scopes a replacement to the description's constants (_Sql.of), and dataset is among them: test_b82_a_reload_of_a_gm_window_*, test_b82_a_reload_of_a_tm_window_* |
eds-tx-mix | daily 05:00: the last 14 local days, 2 calls of data (1 and 1 boundary remainder while today's unpublished tail keeps the response over 17 500 rows; 1 from lag 3) and 1 of metadata; the first load is this job's alone, newest first, in slices of 30 windows or 35 minutes (a chain eds-tx-mix:<slot>:<slice>): 73 windows, 146 useful data calls at lag under 3 days (145 from lag 3) and 5 to 25 of metadata (151 calls / 2 h 31 min across 5 slices at 60 s, 171 calls / 14 h 44 min across 25 slices at 310 s), on 26 November 2026. It begins the first load only when TE is loaded from its first day and no municipality waits or catches up (§3.4: the transmission factors' 12 calls and the municipal share's first catch-up come first): before that it ends at once, {"skipped": "awaiting_emission_inputs"}, its slot covered, with no call. "Waits" is recoverage.catching_up (a state 1 or 2 in ingest.municipality_state) or a municipality the setting wants that is not yet in the set (on a first start the mix's slot, 05:00, comes before the share's, 09:30, so the state is empty: the setting and the roots say what will wait; emission_inputs_pending). A chain that has begun goes on, and a dataset loaded from its first day is run every day, whatever waits |
eds-tx-mix-weekly | Sunday 05:45: the last 120 local days, 8 data calls (4 windows, 2 calls each) and 1 of metadata at 60 s (9 calls, or 2 slices / 10 calls at 310 s); on a dataset not loaded from its first day it ends at once, {"skipped": "awaiting_first_load"} |
eds-tx-mix-monthly | the 2nd of each month, 04:00: from 1 January of the previous year, 24 windows (23 of 30 days and 1 of 11 days on 2 December 2026: 47 useful data calls): 2 slices / 49 calls at 60 s, or 8 slices / 55 calls at 310 s; awaiting_first_load as the weekly |
| Generated extract | python -m elo_devtools.synth txmix --out DIR (synth/transmission_mix.py; not committed: make demo, the demo load and CI generate it at load): GM's extract under TM's name, with the same hours, versions and cases at the same places (an unknown code, an unknown connected area, a negative share, an hour without rows, a NULL share and a NULL version, a short Final hour, the Initial tail), and the shares drawn from another seed (which imports an hour holds follows it), so that a test tells the datasets apart. demo_load.load_txmix loads it through the file mode (raw.fetch.source = 9, every row generated); the origin of each dataset of the table is checked on its own rows (MIX_ROWS, TXMIX_ROWS) before any file of any extract is loaded. The counts say each apart: mix_rows is GM's, txmix_rows TM's. The stack check loads October and November 2026 of it (deploy/smoke.py, check_generated_transmission_mix) |
make status | The grid mix's lines word for word as they were (DeclarationGridmix: …), and TM's under its own name from its own state row and rows (MIX_PASS is one pass per dataset: m.dataset = :n): the origin, the newest hour, loaded from and through, the newest complete hour, the hours not complete by version (plain), the hours without a row, the hours not declared yet, and ! for the codes, connected areas, negative shares and missing shares or versions it holds. While eds-tx-mix is held back (a dataset with no state row says DeclarationTransmissionGridmix: not loaded; one that has begun loading keeps its block): eds-tx-mix: awaiting the emission's inputs (…), a plain line, not !, whenever it is held back (B82f), naming the input that waits: the transmission factors are not loaded from their first day, a municipality waits or catches up, or the municipal share has not run for every wanted municipality: eds-recoverage must succeed first (the municipality is wanted and eds-recoverage has not yet joined it to the set, so a failing eds-recoverage holds the first load). The runs' part names the skipped run (its last run was skipped: it waits for the emission's inputs …). The demo stack, where nothing is scheduled, says nothing of it. Not loaded and not held back is ! as the grid mix's is. Three more runs: "transmission mix run", "transmission mix weekly run", "transmission mix monthly re-pull" |
The grid's mix (B53)
DeclarationGridmix (PT1H) into fx.mix_hour (phase-2.md §2.1, §2.3, §2.4), described in elo_worker/eds/mix.py. A row
is one hour, price area, connected area and report group code: SharePPM (parts per million of the hour's consumption in
the price area; as delivered, with its sign), ShareMWh, CO2Emission (kg), ReportGrp (the group's name as
delivered: never a key, FossilGas and Fossil gas both occur), Version (Initial, Preliminary, Final); HourDK is
known and not kept.
| Table | fx.mix_hour, PK (price_area, hour_utc, connected_area, report_grp_code), migration 0215_grid_mix; about 3 million rows and 0.5 GB on the owner's stack. elo_worker SELECT, INSERT, UPDATE, DELETE; elo_api SELECT |
| Windows | 30 local days (45 033 and 45 463 rows for the snapshot's January and February 2025, 1 453 to 1 624 a day: about 49 000 rows a window, below the budget of 75 000; halved when a response reaches it; B95f: it was 5 days), from 1 January 2021, newest first |
| First load | 73 windows (the run's own 14 days and 72 of 30 days, 146 useful data calls at lag under 3 days, 145 from lag 3) and a call of metadata a slice on 26 November 2026 (it was 431 of 5 days): 151 calls / 2 h 31 min across 5 slices at one call a minute, 171 calls / 14 h 44 min across 25 slices at the measured 5 minutes (docs/operations.md section 2; 150 / 170 from lag 3), in slices of 30 windows or about 35 minutes of calls (loader.SLICE_TIME): eds-mix asks its own 14 days (1 window) and goes on from the oldest day loaded; the newest months have a mix after the first slice. The daily jobs of the lane (eds-load 04:30, eds-prices 14:10, eds-mix 04:45) run between the slices |
eds-mix | daily 04:45: the last 14 local days, 2 data calls (1 and 1 boundary remainder while today's unpublished tail keeps it over 17 500 rows; 1 from lag 3) and 1 of metadata |
eds-mix-weekly | Sunday 05:15: the last 120 days (run_slice(..., mode="load", days=120)), 8 data calls (4 windows, 2 calls each) and 1 of metadata at 60 s (9 calls, or 2 slices / 10 calls at 310 s) |
eds-mix-monthly | the 2nd of each month, 03:40: from 1 January of the previous year, 24 windows (23 of 30 days and 1 of 11 days on 2 December 2026: 47 useful data calls): 2 slices / 49 calls at 60 s (49 minutes), 8 slices / 55 calls at 310 s (4 h 44 min) |
| The first load is the daily job's alone (B53f) | A job that reloads runs only on a dataset loaded from its first day (loaded_from at or before the description's first day, and no chain queued that is not a re-pull's): the monthly re-pull, the mix's weekly 120 days, and the declaration's and the prices' monthly re-pulls (run_slice, for every dataset) otherwise end at once without a call, their slot covered, their detail {"skipped": "awaiting_first_load"}. On the first make up after the 2nd of a month the monthly job is due from an earlier instant than the daily job and would otherwise claim the lane first and begin the first load as a re-pull; beside the first load's chain a re-pull would add its windows, with other bounds, to it. make status says the skip as a plain line under the job |
| One chain | The three jobs are one dataset and so one chain (B51v-04): once the first load is made, a re-pull's chain beside a run is added to, never a second one. A person re-pulls with python -m elo_worker.eds repull DeclarationGridmix |
The set, not the row (§2.4): replacement="set". The rows of an hour and price area are replaced as a set in the
window's transaction: a row the response no longer holds for an hour is removed, an hour that a reload no longer holds is
removed (a window answered with nothing removes what it held), a changed row (a share, a version, a name) is updated in
place, and ops.data_version goes up once when anything changed. No history is kept (every hour's set changes at
least twice, Initial, Preliminary, Final, which would triple the largest table of the install); phase 3's lock adds it.
What the service delivers is stored as it is. A report group code ref.mix_code does not know, a connected area
ref.code (list connected_area) does not know and a negative share are rows like any other, with their sign; make status lists them (below) and the calculation (B58) handles them (§3.3 steps 3 and 6). A SharePPM, a Version, a
ShareMWh, a CO2Emission or a ReportGrp that is missing is stored as NULL (null="keep", B53f: one row must not
refuse a window of 5 days and stop the first load), and **an hour with a NULL share or a NULL version is not
complete** (eds.mix.is_complete; a share that is not there is never read as zero). The key is the code, never the name.
The three reference seeds (migration 0216_mix_reference, data and not code, R2 §2.2.4: "bør anvendes som en
parameterfil"): ref.mix_group (the eight groups of §3.3 with sort, renewable_share and nuclear: wind, solar,
hydro and biomass 1, waste 0,55, nuclear 0 with nuclear true, fossil and other 0; since migration 0315_mix_fossil_split (B78) nine groups: gas and coal_oil in the place of fossil, with a column family), ref.mix_code (the 17 codes of R2
§2.2.4, each in one group), and the list connected_area of ref.code (DK1, DK2, DE, GE, NO, NO2, SE,
SE3, SE4, NL, GB). Not B53's: whether an hour is complete, the energy of a group, the shares (B58, §3.3);
eds/mix.py holds the bounds of completeness (999 900 to 1 000 100 ppm, §3.3 step 1) only because make status counts
the hours that are not complete with them.
make status (section "energi data service", after the prices): the origin, what is loaded and the newest hour; the
newest complete hour; the hours of the loaded range that are not complete by version (the lowest version of the hour's
rows) and price area, and the hours without a row up to the newest hour, and the hours after it, not declared yet. **Counts
of incomplete hours are plain lines, not !**: the newest hours are incomplete by nature, and from which day they are
complete is the lead's to record on the owner's stack. A ! is: a report group code ref.mix_code does not know, a
connected area ref.code does not know, a row with a negative share and a row with no share or no version (each with its count and its first and last hour), a
dataset not loaded (outside the demo) or stopped, an unknown column, a failed run of one of the three jobs.
The extract of the demo and CI is generated at load, not committed (tools/src/elo_devtools/synth/mix.py, about 650 000
rows for 1 January 2024 to two days before the anchor, a month file of at most 20 000 rows): every code of ref.mix_code,
imports, one unknown code (R99), one unknown connected area (PL), complete hours summing to 999 950 to 1 000 000,
Initial hours at the end that sum to less than half, an hour with no rows, an hour with a negative share, and one Final
hour that is short; make demo loads it through the loader's file mode (demo_load.load_mix), so every row is
generated and no call is made.
compare-declarations
Compares fx.factor_hour for the Danish local dates --from (default 2025-01-01) to --to (default 2026-11-04) with a
snapshot of tools/snapshot_declarations.py. It refuses a range for which the snapshot lacks a month, and a month file the
loader would refuse (it reads them with the loader's decoder). It reads in a read-only
transaction and writes only its output (standard output, or --output). The report has a table of rows per Danish month and
snapshot version (unchanged, changed, of which values and version, missing live), the rows only the database has, and per gas
(CO2, CH4, N2O) the largest absolute and the largest relative difference with the hour, area and method where it occurs.
Its first lines give the origin of each side (real or generated, from fx.factor_hour.generated and the files' _generated)
and, when either side holds generated rows, say that the comparison is no evidence about Energinet's restatement.
For the next epics
B52, B53 (done): describe the dataset (above), write a job module
elo_worker/jobs/eds_<…>.pywhoseKINDstarts witheds-(the worker's declaration lane takes every such kind,elo_worker.__main__.EDS_KINDS) and whoserunisrun_slice(context, payload, kind=KIND, loader=build_loader(context.engine, clock=clock, dataset=…), mode="load" or "repull"), and add the slot toelo_worker.schedule.SCHEDULED. A weekly window of 120 days isrun_slice(..., mode="load", days=120); a re-pull from another day than 1 January isloader.run(windows)withwindows.plan. The generated extract loads throughDatasetLoader(engine, dataset).load_files(root), from<root>/<name>/<yyyy-mm>.json.gzand_meta.json.test_b19_lanes.pyasserts the lane's kinds (the declaration's two, the prices' two, the mix's three): a neweds-job changes that fact (phase-2.md §9 row 1). A dataset goes ineds/registry.py, and in its successors' key only if one of its jobs runs more than one.B09 (done):
eds-load04:30 daily andeds-monthly-repullthe 2nd at 03:00 (Europe/Copenhagen) are scheduled, not in the demo stack;make demoloadsfixtures/factorswithpython -m elo_worker.eds files fixtures/factors(orDeclarationLoader(engine).load_files(...)). A first load blocks the job runner for about 19 minutes (18 calls a minute apart); the job makes its own connections, so it holds no claim transaction while it waits.make statusreadsingest.dataset_state(status,loaded_*,columns_seen,caution_changed_at,last_run_at).B12a: a factor row can have NULL values (the API's
nullis stored as delivered); an hour without a row has no factor.fx.factor_hour.version1 Initial, 2 Preliminary, 3 Final;retrieved_atis when the value was first retrieved (a row that did not change is not touched).B12b:
elo_devtools.validateexists; add the validation next todeclarations.py.make validatemarks the throwaway database it creates withALTER DATABASE <name> SET elo.purpose = 'validation'before it loads the snapshot.B12a and the API:
fx.factor_hour.generatedsays whether a factor is generated; return it with the values.
Kilde: docs/declarations.md i løsningens
repository.