utility-tariffs-lib 0.1.0__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {utility_tariffs_lib-0.1.0/utility_tariffs_lib.egg-info → utility_tariffs_lib-0.3.0}/PKG-INFO +1 -1
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/README.md +33 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/tariff/__init__.py +2 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/tariff/definition.py +26 -1
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/tariff/definition_parse.py +55 -4
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/tariff/engine.py +19 -1
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/tariff/period_bill.py +6 -2
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/tariffranking/search.py +6 -3
- utility_tariffs_lib-0.3.0/lib/tariffstore/__init__.py +22 -0
- utility_tariffs_lib-0.3.0/lib/tariffstore/aclient.py +285 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/tariffstore/client.py +56 -164
- utility_tariffs_lib-0.3.0/lib/tariffstore/core.py +261 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/tariffstore/price_client.py +33 -36
- utility_tariffs_lib-0.3.0/lib/tariffstore/price_rules.py +43 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/tariffstore/prices.py +3 -2
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/tariffstore/schema.py +40 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/pyproject.toml +1 -1
- utility_tariffs_lib-0.3.0/tests/test_async_client.py +304 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/tests/test_price_client.py +42 -1
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/tests/test_prices.py +12 -6
- utility_tariffs_lib-0.3.0/tests/test_prices_bord_gais.py +89 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/tests/test_schema.py +29 -0
- utility_tariffs_lib-0.3.0/tests/test_sources_at.py +65 -0
- utility_tariffs_lib-0.3.0/tests/test_sources_bord_gais.py +207 -0
- utility_tariffs_lib-0.3.0/tests/test_sources_br.py +55 -0
- utility_tariffs_lib-0.3.0/tests/test_sources_ca_manitoba.py +43 -0
- utility_tariffs_lib-0.3.0/tests/test_sources_ca_nb.py +42 -0
- utility_tariffs_lib-0.3.0/tests/test_sources_ch.py +103 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/tests/test_sources_ie.py +88 -0
- utility_tariffs_lib-0.3.0/tests/test_sources_in.py +125 -0
- utility_tariffs_lib-0.3.0/tests/test_sources_sg.py +48 -0
- utility_tariffs_lib-0.3.0/tests/test_sources_zm.py +55 -0
- utility_tariffs_lib-0.3.0/tests/test_status.py +80 -0
- utility_tariffs_lib-0.3.0/tests/test_status_docs.py +117 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/tests/test_sync_core.py +12 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/tests/test_sync_run.py +30 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/tests/test_tariffs_through_lib.py +47 -8
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0/utility_tariffs_lib.egg-info}/PKG-INFO +1 -1
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/utility_tariffs_lib.egg-info/SOURCES.txt +16 -0
- utility_tariffs_lib-0.1.0/lib/tariffstore/__init__.py +0 -13
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/LICENSE +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/README.md +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/__init__.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/py.typed +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/tariff/accumulator.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/tariff/bands.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/tariff/bill_days.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/tariff/billing.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/tariff/compile.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/tariff/config.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/tariff/defaults.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/tariff/definition_savings.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/tariff/demand.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/tariff/index.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/tariff/periods.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/tariff/price_curve.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/tariff/price_series.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/tariff/price_stats.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/tariff/price_timeline.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/tariff/reprice.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/tariff/savings.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/tariff/slot_history.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/tariff/slots.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/tariff/stored_energy.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/tariff/windows.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/tariffranking/__init__.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/tariffstore/compile.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/tariffstore/index.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/tariffstore/layout.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/timeutil/__init__.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/lib/timeutil/real_time.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/setup.cfg +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/tests/test_build.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/tests/test_client.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/tests/test_compile.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/tests/test_eia861_map.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/tests/test_end_to_end.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/tests/test_index.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/tests/test_lib_release_notes.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/tests/test_packaging.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/tests/test_price_format.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/tests/test_prices_comed.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/tests/test_prices_energinet.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/tests/test_prices_energy_charts.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/tests/test_prices_energyzero.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/tests/test_prices_runner.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/tests/test_repo_rules.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/tests/test_sources_dk.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/tests/test_sources_electric_ireland.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/tests/test_sources_gb.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/tests/test_sources_hq.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/tests/test_sources_other.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/tests/test_sources_pt.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/tests/test_sources_us.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/tests/test_stored_tariffs.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/tests/test_urdb_convert.py +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/utility_tariffs_lib.egg-info/dependency_links.txt +0 -0
- {utility_tariffs_lib-0.1.0 → utility_tariffs_lib-0.3.0}/utility_tariffs_lib.egg-info/top_level.txt +0 -0
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Tariff prices
|
|
2
2
|
|
|
3
|
+
> **Note on the data.** The tariffs here are gathered by the methods described in this
|
|
4
|
+
> repository, and each source has its own way of being read. Some sources will need updating over
|
|
5
|
+
> time and may change significantly. We will try to keep on top of as many as we can. The list is
|
|
6
|
+
> not exhaustive, because not every tariff is easy to gather. We will try to add more over time.
|
|
7
|
+
>
|
|
8
|
+
> **No manually entered tariffs.** A tariff typed in by hand goes out of date without notice, so
|
|
9
|
+
> this store holds only tariffs that a source reads from a published page, file or feed. If you know
|
|
10
|
+
> a place that publishes tariffs, [suggest a source](../../issues/new?template=suggestion.md). Feedback
|
|
11
|
+
> is welcome there too.
|
|
12
|
+
|
|
3
13
|
Open, versioned electricity tariff definitions, an index to find them by country, provider and
|
|
4
14
|
tariff, and a small library that fetches one, checks it and hands it to a bill engine. Each tariff
|
|
5
15
|
is a JSON document. No tariff contains code or formulas.
|
|
@@ -69,6 +79,29 @@ mine = {"name": "My tariff", "effective_from": "2026-01-01",
|
|
|
69
79
|
definition = store.custom_definition("IE", mine, date.today())
|
|
70
80
|
```
|
|
71
81
|
|
|
82
|
+
## How tariffs are kept current
|
|
83
|
+
|
|
84
|
+
Nothing is typed in again by hand once a source is added. The sources are read on a schedule by
|
|
85
|
+
plain Python on a GitHub runner, with no AI and no private machine:
|
|
86
|
+
|
|
87
|
+
| What | When | Result |
|
|
88
|
+
| --- | --- | --- |
|
|
89
|
+
| Supplier and regulator sources (`sync.yml`) | Mondays 05:17 UTC | One pull request when a price changed. A person reviews and merges it |
|
|
90
|
+
| US plans (`sync-us.yml`) | The 3rd of each month, 04:43 UTC | One pull request with the plans in force |
|
|
91
|
+
| Dynamic price feeds (`prices.yml`) | Daily at 06:17, 15:17 and 17:17 UTC | New complete days committed to the `prices` branch. A day is rewritten only when its prices change |
|
|
92
|
+
|
|
93
|
+
A source that cannot be read opens an issue labelled `sync-failed` and does not stop the others.
|
|
94
|
+
The store is synced whether or not any integration is released. Clients read the files as they
|
|
95
|
+
stand, so an older client sees new prices without an update.
|
|
96
|
+
A price change is a new numbered revision, never an edit of a published one.
|
|
97
|
+
|
|
98
|
+
Each weekly run also records when every source was read, on its own `status` branch (the file
|
|
99
|
+
`sources.json`), so `main` holds no timestamps and a quiet week needs no pull request. For each
|
|
100
|
+
source it keeps the time of the last attempt, the last successful read, the last time it wrote a
|
|
101
|
+
new tariff or revision, and whether the last attempt worked. A failed source keeps its earlier
|
|
102
|
+
good times. The format is in `docs/format.md`. The monthly US sync and the price feeds are not
|
|
103
|
+
recorded there yet: a feed's newest day is already visible in its own index.
|
|
104
|
+
|
|
72
105
|
## Working on it
|
|
73
106
|
|
|
74
107
|
python3 -m scripts.build # rewrite the indexes after editing a tariff or a country block
|
|
@@ -13,6 +13,7 @@ from .engine import (
|
|
|
13
13
|
BillInputs,
|
|
14
14
|
CheckFailed,
|
|
15
15
|
Line,
|
|
16
|
+
MissingLoad,
|
|
16
17
|
MissingPeak,
|
|
17
18
|
MissingSeries,
|
|
18
19
|
PricedBill,
|
|
@@ -100,6 +101,7 @@ __all__ = [
|
|
|
100
101
|
"BillInputs",
|
|
101
102
|
"CheckFailed",
|
|
102
103
|
"Line",
|
|
104
|
+
"MissingLoad",
|
|
103
105
|
"MissingPeak",
|
|
104
106
|
"MissingPrice",
|
|
105
107
|
"MissingSeries",
|
|
@@ -220,6 +220,30 @@ class Demand:
|
|
|
220
220
|
rounding: NodeRounding
|
|
221
221
|
|
|
222
222
|
|
|
223
|
+
@dataclass(frozen=True)
|
|
224
|
+
class LoadBand:
|
|
225
|
+
"""One row of a connected load charge: the price per kW for a load up to *upto_kw*."""
|
|
226
|
+
|
|
227
|
+
upto_kw: Decimal | None # included. None for the last band, which has no top
|
|
228
|
+
price: Decimal # per kW
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
@dataclass(frozen=True)
|
|
232
|
+
class ConnectedLoad:
|
|
233
|
+
"""A charge on the load a customer is connected for, in kW, such as a sanctioned load.
|
|
234
|
+
|
|
235
|
+
The load is not measured by the meter, so the caller gives it for *load* in `BillInputs`. The
|
|
236
|
+
band the load falls in sets one price, and that price applies to every kW (the whole load, not
|
|
237
|
+
each slice of it). A load below *min_kw* is billed as *min_kw*.
|
|
238
|
+
"""
|
|
239
|
+
|
|
240
|
+
load: str # the name the load is given under, in `BillInputs` and in a check
|
|
241
|
+
bands: tuple[LoadBand, ...] # from the lowest load, the last without a top
|
|
242
|
+
per: str # "period": once for the bill, or "month": for each month of it
|
|
243
|
+
min_kw: Decimal # the least load billed, 0 for none
|
|
244
|
+
rounding: NodeRounding
|
|
245
|
+
|
|
246
|
+
|
|
223
247
|
@dataclass(frozen=True)
|
|
224
248
|
class Bound:
|
|
225
249
|
"""Wraps one node and sets a floor (`minimum`) or a cap (`maximum`) on its amount.
|
|
@@ -266,7 +290,7 @@ class Sum:
|
|
|
266
290
|
|
|
267
291
|
Node = (
|
|
268
292
|
EnergyByBand | SeriesEnergy | TieredEnergy | ExportCredit | PerDay | PerPeriod | PerKwh
|
|
269
|
-
| Demand | Bound | Adjust | Tax | Sum
|
|
293
|
+
| Demand | ConnectedLoad | Bound | Adjust | Tax | Sum
|
|
270
294
|
)
|
|
271
295
|
|
|
272
296
|
|
|
@@ -279,6 +303,7 @@ class Check:
|
|
|
279
303
|
export_kwh: Decimal | Mapping[str, Decimal] # one total, or the kWh in each export band
|
|
280
304
|
expected_total: Decimal
|
|
281
305
|
peak_kw: Mapping[str, Decimal] = field(default_factory=dict) # kW by demand window
|
|
306
|
+
load_kw: Mapping[str, Decimal] = field(default_factory=dict) # connected kW by load name
|
|
282
307
|
|
|
283
308
|
|
|
284
309
|
@dataclass(frozen=True)
|
|
@@ -36,6 +36,7 @@ from .definition import (
|
|
|
36
36
|
Block,
|
|
37
37
|
Bound,
|
|
38
38
|
Check,
|
|
39
|
+
ConnectedLoad,
|
|
39
40
|
DefinitionError,
|
|
40
41
|
Demand,
|
|
41
42
|
EnergyByBand,
|
|
@@ -43,6 +44,7 @@ from .definition import (
|
|
|
43
44
|
ExportPrices,
|
|
44
45
|
ImportPrices,
|
|
45
46
|
InputSpec,
|
|
47
|
+
LoadBand,
|
|
46
48
|
Node,
|
|
47
49
|
NodeRounding,
|
|
48
50
|
PerDay,
|
|
@@ -122,7 +124,8 @@ def parse_definition(data: object) -> TariffDefinition:
|
|
|
122
124
|
import_prices, export_prices = _prices(doc)
|
|
123
125
|
period, total = _bill(doc.child("bill"), inputs)
|
|
124
126
|
_check_bands(total, _names(import_prices))
|
|
125
|
-
|
|
127
|
+
named = (set(demand_windows(total)), connected_loads(total))
|
|
128
|
+
checks = _checks(doc, import_prices, export_prices, named)
|
|
126
129
|
complete = doc.choice("completeness", ("complete", "partial")) == "complete"
|
|
127
130
|
if complete and not checks:
|
|
128
131
|
raise DefinitionError("completeness", "complete needs at least one entry in checks")
|
|
@@ -553,6 +556,12 @@ def demand_windows(total: Node) -> dict[str, Zone]:
|
|
|
553
556
|
return windows
|
|
554
557
|
|
|
555
558
|
|
|
559
|
+
def connected_loads(total: Node) -> set[str]:
|
|
560
|
+
"""The names of the connected loads a bill tree uses."""
|
|
561
|
+
nodes = (node for node, _ in _children_of(total, "bill.total"))
|
|
562
|
+
return {node.load for node in nodes if isinstance(node, ConnectedLoad)}
|
|
563
|
+
|
|
564
|
+
|
|
556
565
|
def _blocks(fields: Fields) -> dict[str, Block]:
|
|
557
566
|
blocks: list[tuple[str, Block]] = []
|
|
558
567
|
for name, _ in fields.items():
|
|
@@ -647,6 +656,38 @@ def _hours(fields: Fields) -> tuple[time, time]:
|
|
|
647
656
|
return start, end
|
|
648
657
|
|
|
649
658
|
|
|
659
|
+
def _load_bands(fields: Fields) -> tuple[LoadBand, ...]:
|
|
660
|
+
rows: list[LoadBand] = []
|
|
661
|
+
for name, _ in fields.items():
|
|
662
|
+
if not _NODE_NAME.match(name):
|
|
663
|
+
raise DefinitionError(fields.at(name), "is not a valid name")
|
|
664
|
+
row = fields.child(name)
|
|
665
|
+
row.only(required=("price",), optional=("upto_kw",))
|
|
666
|
+
top = row.money("upto_kw") if row.has("upto_kw") else None
|
|
667
|
+
rows.append(LoadBand(top, row.money("price")))
|
|
668
|
+
if not rows:
|
|
669
|
+
raise DefinitionError(fields.path, "needs at least one band")
|
|
670
|
+
rows.sort(key=lambda band: (band.upto_kw is None, band.upto_kw or Decimal(0)))
|
|
671
|
+
tops = [band.upto_kw for band in rows]
|
|
672
|
+
if tops[-1] is not None or None in tops[:-1] or len(set(tops)) != len(tops) or (
|
|
673
|
+
tops[0] is not None and tops[0] <= 0
|
|
674
|
+
):
|
|
675
|
+
raise DefinitionError(
|
|
676
|
+
fields.path, "needs rising tops above 0 and a last band with no upto_kw"
|
|
677
|
+
)
|
|
678
|
+
return tuple(rows)
|
|
679
|
+
|
|
680
|
+
|
|
681
|
+
def _connected_load(fields: Fields, depth: int) -> Node:
|
|
682
|
+
fields.only(required=("kind", "load", "bands"), optional=("per", "min_kw", "round"))
|
|
683
|
+
name = fields.text("load")
|
|
684
|
+
if not _NODE_NAME.match(name):
|
|
685
|
+
raise DefinitionError(fields.at("load"), "must be a lower case name")
|
|
686
|
+
per = fields.choice("per", _PER) if fields.has("per") else "month"
|
|
687
|
+
least = fields.money("min_kw") if fields.has("min_kw") else Decimal(0)
|
|
688
|
+
return ConnectedLoad(name, _load_bands(fields.child("bands")), per, least, _rounding(fields))
|
|
689
|
+
|
|
690
|
+
|
|
650
691
|
def _bound(kind: str) -> Callable[[Fields, int], Node]:
|
|
651
692
|
def parse(fields: Fields, depth: int) -> Node:
|
|
652
693
|
fields.only(required=("kind", "amount", "of"), optional=("per", "round"))
|
|
@@ -695,6 +736,7 @@ _NODE_PARSERS: dict[str, Callable[[Fields, int], Node]] = {
|
|
|
695
736
|
"per_day": _per_day,
|
|
696
737
|
"per_kwh": _per_kwh,
|
|
697
738
|
"demand": _demand,
|
|
739
|
+
"connected_load": _connected_load,
|
|
698
740
|
"per_period": _per_period,
|
|
699
741
|
"minimum": _bound("minimum"),
|
|
700
742
|
"maximum": _bound("maximum"),
|
|
@@ -705,11 +747,12 @@ _NODE_PARSERS: dict[str, Callable[[Fields, int], Node]] = {
|
|
|
705
747
|
|
|
706
748
|
|
|
707
749
|
def _checks(
|
|
708
|
-
doc: Fields, import_prices: ImportPrices, export_prices: ExportPrices,
|
|
750
|
+
doc: Fields, import_prices: ImportPrices, export_prices: ExportPrices,
|
|
751
|
+
named: tuple[Collection[str], Collection[str]],
|
|
709
752
|
) -> dict[str, Check]:
|
|
710
753
|
if not doc.has("checks"):
|
|
711
754
|
return {}
|
|
712
|
-
bands = _Bands(_names(import_prices), _names(export_prices),
|
|
755
|
+
bands = _Bands(_names(import_prices), _names(export_prices), named[0], named[1])
|
|
713
756
|
fields = doc.child("checks")
|
|
714
757
|
checks: dict[str, Check] = {}
|
|
715
758
|
for name, _ in fields.items():
|
|
@@ -723,6 +766,7 @@ class _Bands(NamedTuple):
|
|
|
723
766
|
imported: Collection[str]
|
|
724
767
|
exported: Collection[str]
|
|
725
768
|
windows: Collection[str]
|
|
769
|
+
loads: Collection[str]
|
|
726
770
|
|
|
727
771
|
|
|
728
772
|
def _names(prices: ImportPrices | ExportPrices) -> set[str]:
|
|
@@ -732,7 +776,7 @@ def _names(prices: ImportPrices | ExportPrices) -> set[str]:
|
|
|
732
776
|
def _check(fields: Fields, bands: _Bands) -> Check:
|
|
733
777
|
fields.only(
|
|
734
778
|
required=("period_days", "import_kwh_by_band", "export_kwh", "expected_total"),
|
|
735
|
-
optional=("peak_kw",),
|
|
779
|
+
optional=("peak_kw", "load_kw"),
|
|
736
780
|
)
|
|
737
781
|
# A plain export figure is paid at the base export price. An object names the bands.
|
|
738
782
|
export: Decimal | dict[str, Decimal]
|
|
@@ -747,6 +791,7 @@ def _check(fields: Fields, bands: _Bands) -> Check:
|
|
|
747
791
|
export_kwh=export,
|
|
748
792
|
expected_total=fields.signed("expected_total"),
|
|
749
793
|
peak_kw=_peaks(fields, bands),
|
|
794
|
+
load_kw=_loads(fields, bands),
|
|
750
795
|
)
|
|
751
796
|
|
|
752
797
|
|
|
@@ -756,6 +801,12 @@ def _peaks(fields: Fields, bands: _Bands) -> dict[str, Decimal]:
|
|
|
756
801
|
return _kwh_by_band(fields.child("peak_kw"), bands.windows, "a demand window")
|
|
757
802
|
|
|
758
803
|
|
|
804
|
+
def _loads(fields: Fields, bands: _Bands) -> dict[str, Decimal]:
|
|
805
|
+
if not fields.has("load_kw"):
|
|
806
|
+
return {}
|
|
807
|
+
return _kwh_by_band(fields.child("load_kw"), bands.loads, "a connected load")
|
|
808
|
+
|
|
809
|
+
|
|
759
810
|
def _kwh_by_band(by_band: Fields, bands: Collection[str], what: str) -> dict[str, Decimal]:
|
|
760
811
|
kwh: dict[str, Decimal] = {}
|
|
761
812
|
for band, _ in by_band.items():
|
|
@@ -20,6 +20,7 @@ from .definition import (
|
|
|
20
20
|
Adjust,
|
|
21
21
|
Block,
|
|
22
22
|
Bound,
|
|
23
|
+
ConnectedLoad,
|
|
23
24
|
Demand,
|
|
24
25
|
EnergyByBand,
|
|
25
26
|
ExportCredit,
|
|
@@ -47,6 +48,10 @@ class MissingPeak(ValueError):
|
|
|
47
48
|
"""A bill has a demand charge and no peak kW was given for its window."""
|
|
48
49
|
|
|
49
50
|
|
|
51
|
+
class MissingLoad(ValueError):
|
|
52
|
+
"""A bill has a connected load charge and no load in kW was given for its name."""
|
|
53
|
+
|
|
54
|
+
|
|
50
55
|
class MissingSeries(ValueError):
|
|
51
56
|
"""A bill has a series energy node and no cost was given for its series."""
|
|
52
57
|
|
|
@@ -65,6 +70,9 @@ class BillInputs:
|
|
|
65
70
|
# The highest half-hour kW in each demand window of the bill. A window the tree uses and this
|
|
66
71
|
# leaves out is refused, never priced as zero.
|
|
67
72
|
peak_kw: Mapping[str, Decimal] = field(default_factory=dict)
|
|
73
|
+
# The kW a customer is connected for, by the name a connected load node gives it. A load the
|
|
74
|
+
# tree uses and this leaves out is refused, never priced as zero.
|
|
75
|
+
load_kw: Mapping[str, Decimal] = field(default_factory=dict)
|
|
68
76
|
# The cost of the import kWh under each price series the tree names, from `series_cost`. A
|
|
69
77
|
# series the tree uses and this leaves out is refused, never priced as zero.
|
|
70
78
|
import_cost_by_series: Mapping[str, Decimal] = field(default_factory=dict)
|
|
@@ -102,7 +110,7 @@ def verify_checks(definition: TariffDefinition) -> None:
|
|
|
102
110
|
for name, check in definition.checks.items():
|
|
103
111
|
inputs = BillInputs(
|
|
104
112
|
check.period_days, check.period_days, check.import_kwh_by_band, check.export_kwh,
|
|
105
|
-
peak_kw=check.peak_kw,
|
|
113
|
+
peak_kw=check.peak_kw, load_kw=check.load_kw,
|
|
106
114
|
)
|
|
107
115
|
total = price_bill(definition, inputs).total
|
|
108
116
|
if total != check.expected_total:
|
|
@@ -177,6 +185,8 @@ class _Pricer:
|
|
|
177
185
|
return self._per_kwh(node)
|
|
178
186
|
if isinstance(node, Demand):
|
|
179
187
|
return self._demand(node)
|
|
188
|
+
if isinstance(node, ConnectedLoad):
|
|
189
|
+
return self._connected_load(node)
|
|
180
190
|
if isinstance(node, PerPeriod):
|
|
181
191
|
return self._per_period(node)
|
|
182
192
|
return None
|
|
@@ -255,6 +265,14 @@ class _Pricer:
|
|
|
255
265
|
amount = node.price * self._inputs.peak_kw[node.window] * months
|
|
256
266
|
return Line("demand", self._round(amount, node.rounding))
|
|
257
267
|
|
|
268
|
+
def _connected_load(self, node: ConnectedLoad) -> Line:
|
|
269
|
+
if node.load not in self._inputs.load_kw:
|
|
270
|
+
raise MissingLoad(f"no load in kW was given for {node.load!r}")
|
|
271
|
+
kw = max(self._inputs.load_kw[node.load], node.min_kw)
|
|
272
|
+
band = next((b for b in node.bands if b.upto_kw is None or kw <= b.upto_kw), node.bands[-1])
|
|
273
|
+
months = Decimal(self._months) if node.per == "month" else Decimal(1)
|
|
274
|
+
return Line("connected_load", self._round(band.price * kw * months, node.rounding))
|
|
275
|
+
|
|
258
276
|
def _per_period(self, node: PerPeriod) -> Line:
|
|
259
277
|
amount = node.amount * self._months if node.per == "month" else node.amount
|
|
260
278
|
if node.share == "days_in_period":
|
|
@@ -13,7 +13,7 @@ from __future__ import annotations
|
|
|
13
13
|
|
|
14
14
|
import calendar
|
|
15
15
|
from collections.abc import Callable, Mapping
|
|
16
|
-
from dataclasses import dataclass
|
|
16
|
+
from dataclasses import dataclass, field
|
|
17
17
|
from datetime import date
|
|
18
18
|
from decimal import Decimal
|
|
19
19
|
|
|
@@ -32,6 +32,8 @@ class PeriodRules:
|
|
|
32
32
|
months: int | None = None # calendar months in one bill period
|
|
33
33
|
start_month: int | None = None # a month a period starts in
|
|
34
34
|
is_holiday: Callable[[date], bool] = no_holidays
|
|
35
|
+
# The kW the customer is connected for, by name, for a tariff with a connected load charge.
|
|
36
|
+
load_kw: Mapping[str, Decimal] = field(default_factory=dict)
|
|
35
37
|
|
|
36
38
|
|
|
37
39
|
@dataclass(frozen=True)
|
|
@@ -111,7 +113,9 @@ def price_period(
|
|
|
111
113
|
else:
|
|
112
114
|
export = _decimal(sum(day.total("export") for day in days))
|
|
113
115
|
length = (through - first).days + 1
|
|
114
|
-
inputs = BillInputs(
|
|
116
|
+
inputs = BillInputs(
|
|
117
|
+
length, (following - first).days, bands, export, months, load_kw=rules.load_kw
|
|
118
|
+
)
|
|
115
119
|
return PeriodBill(
|
|
116
120
|
first_day=first,
|
|
117
121
|
next_first_day=following,
|
|
@@ -14,8 +14,8 @@ export rate of 0 is a real choice for it.
|
|
|
14
14
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
|
-
from collections.abc import Callable, Sequence
|
|
18
|
-
from dataclasses import dataclass, replace
|
|
17
|
+
from collections.abc import Callable, Mapping, Sequence
|
|
18
|
+
from dataclasses import dataclass, field, replace
|
|
19
19
|
from datetime import date, timedelta
|
|
20
20
|
from decimal import Decimal
|
|
21
21
|
from enum import Enum
|
|
@@ -122,6 +122,8 @@ class Usage:
|
|
|
122
122
|
history: SlotHistory
|
|
123
123
|
spans: Sequence[DayRange]
|
|
124
124
|
is_holiday: Callable[[date], bool] = no_holidays
|
|
125
|
+
# The kW the customer is connected for, by name, for plans with a connected load charge.
|
|
126
|
+
load_kw: Mapping[str, Decimal] = field(default_factory=dict)
|
|
125
127
|
|
|
126
128
|
|
|
127
129
|
def price_ranges(usage: Usage, definition: TariffDefinition) -> Decimal:
|
|
@@ -137,7 +139,8 @@ def price_ranges(usage: Usage, definition: TariffDefinition) -> Decimal:
|
|
|
137
139
|
export = Decimal(repr(round(sum(d.total("export") for d in days), 6)))
|
|
138
140
|
length = (span.last - span.first).days + 1
|
|
139
141
|
inputs = BillInputs(
|
|
140
|
-
length, span.period_days, import_by_band(days, definition, is_holiday), export
|
|
142
|
+
length, span.period_days, import_by_band(days, definition, is_holiday), export,
|
|
143
|
+
load_kw=usage.load_kw,
|
|
141
144
|
)
|
|
142
145
|
total += price_bill(definition, inputs).total
|
|
143
146
|
return total
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""The stored tariff format: its validator, its index, the compile step and a client.
|
|
2
|
+
|
|
3
|
+
Standard library only, and no import from `lib.tariff`, so the sync scripts, the checks and any
|
|
4
|
+
client share exactly one definition of the format. `Store` and `PriceStore` are the blocking
|
|
5
|
+
clients, and `AsyncStore` and `AsyncPriceStore` the same clients for an event loop.
|
|
6
|
+
"""
|
|
7
|
+
from .aclient import (
|
|
8
|
+
AsyncFolderCache,
|
|
9
|
+
AsyncMemoryCache,
|
|
10
|
+
AsyncPriceStore,
|
|
11
|
+
AsyncStore,
|
|
12
|
+
session_reader,
|
|
13
|
+
)
|
|
14
|
+
from .client import FolderCache, MemoryCache, Store, StoreError, folder_reader, url_reader
|
|
15
|
+
from .compile import CompileError, compile_area
|
|
16
|
+
from .price_client import PriceStore
|
|
17
|
+
from .schema import checksum, validate_country, validate_tariff
|
|
18
|
+
|
|
19
|
+
__all__ = ["AsyncFolderCache", "AsyncMemoryCache", "AsyncPriceStore", "AsyncStore",
|
|
20
|
+
"CompileError", "FolderCache", "MemoryCache", "PriceStore", "Store", "StoreError",
|
|
21
|
+
"checksum", "compile_area", "folder_reader", "session_reader", "url_reader",
|
|
22
|
+
"validate_country", "validate_tariff"]
|