"""Replay explicitly reviewed SNEL 2015 station observations; no current MW inference."""
from decimal import Decimal
from typing import Any
from energy_data_retrieval.pv_catalogue.catalogue import canonical_json
from .catalogue import stable_id
from .gppd import evidence_record
from .owner_technical import enrich_reviewed
SOURCE_ID = "snel-annual-2015-20261111"
[docs]
def french_number(value: str) -> float:
"""Parse report decimal commas and grouping spaces, rejecting invalid ratings."""
number = Decimal(value.replace(" ", "").replace("\u00a0", "").replace(",", "."))
if not number.is_finite() or number < 0:
raise ValueError("Require finite nonnegative report value")
return float(number)
[docs]
def facts(entry: dict[str, Any]) -> list[dict[str, Any]]:
"""Retain report cells and units; average available MW is not operational MW."""
units = {
"commissioning_period": None,
"installed_groups": "groups",
"groups_in_service": None,
"groups_unavailable": None,
"installed_mw": "MW",
"average_available_mw": "MW",
"availability_percent": "%",
"gross_generation_mwh": "MWh",
}
cells = entry["cells"]
if set(cells) != set(units) or not entry.get("identity_basis"):
raise ValueError("Require reviewed identity and all eight report cells")
if not isinstance(cells["installed_groups"], int) or cells["installed_groups"] <= 0:
raise ValueError("Require positive installed generating group count")
if french_number(cells["availability_percent"]) > 100:
raise ValueError("Availability percentage exceeds 100")
if "TOTAL" in entry["source_name"].upper():
raise ValueError("Aggregate rows are not stations")
result = []
for key, unit in units.items():
value = french_number(cells[key]) if unit in {"MW", "%", "MWh"} else cells[key]
result.append(
dict(
key=key,
value=value,
unit=unit,
basis="2015 annual report; historical observation, not current operation",
locator=entry["locator"] + "; column " + key,
uncertainty="Source precision retained; no independent measurement verification",
)
)
result.append(
dict(
key="gross_generation_gwh",
value=float(Decimal(str(french_number(cells["gross_generation_mwh"]))) / 1000),
unit="GWh",
basis="2015 gross generation; exact unit conversion MWh / 1000",
locator=entry["locator"] + "; PRODUCTION BRUTE MWh",
uncertainty="Retains reported MWh precision; not net or modeled generation",
)
)
return result
[docs]
def new_record(entry: dict[str, Any], *, now: str) -> dict[str, Any]:
"""Create a reviewed accession, with unresolved scope excluded from totals."""
if entry["decision"] != "reviewed_new" or entry["record_id"] is not None:
raise ValueError("New identity review required")
return evidence_record(
{
"record_id": stable_id("projects", "reviewed-accession", entry["accession"]),
"entity_type": "projects",
"name": entry["name"],
"country_code": "COD",
"record_scope": "plant",
"capacity_scope": "SNEL station; physical overlap unresolved",
"aggregation_role": "unresolved",
"status": "unknown",
"status_as_of": now[:10],
"status_date_basis": "Review date; historical report does not establish current status",
"technology": "unknown",
"historical_capacity_mw": french_number(entry["cells"]["installed_mw"]),
"capacity_reference_year": 2015,
"external_ids_json": "{}",
"extensions_json": canonical_json(
{
"snel_2015_assertions": {
"source_id": SOURCE_ID,
"facts": facts(entry),
"identity_basis": entry["identity_basis"],
"accession": entry["accession"],
}
}
),
},
source_id=SOURCE_ID,
now=now,
locator=entry["locator"],
)