flexops.costing.tariff_csv_to_dict

flexops.costing.tariff_csv_to_dict(source: str | Path | DataFrame, *, write_to: str | Path | None = None) → dict

Convert an EECO rate_data CSV (or DataFrame) into the dict load_tariff takes.

Reads a tariff CSV in EECO’s rate_data column schema (utility, type, name, month_start/end, weekday_start/end, hour_start/end, a charge column, basic_charge_limit…) and returns the equivalent {"tariff_data": [records]} structure that load_tariff() accepts. Does no charge math — a pure schema conversion, for authoring or importing tariffs in the common CSV exchange format instead of hand-typed JSON.

Parameters:
  • source – A path to a rate_data CSV, or an already-loaded DataFrame with the same columns (e.g. read and pre-filtered by the caller). Both go through the same column validation.

  • write_to – If given, also persist the converted tariff as a JSON tariff file at this path (loadable thereafter via load_tariff()). The dict is returned either way.

Returns:

A {"tariff_data": [records]} dict equivalent to the CSV.

Raises:

FlexDataError – If the CSV cannot be read or is missing required columns; the message names the file and column.