From de334f8308b9b62775f964c8986ed8eafe79b255 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Senart?= <> Date: Mon, 3 Feb 2025 22:18:46 +0100 Subject: [PATCH] [#31] Add cost computation --- README.md | 6 +- addons/gazpar2haws/DOCS.md | 248 ++++++++++++++++++++++++ addons/gazpar2haws/config.yaml | 23 +-- addons/gazpar2haws/config.yaml.template | 23 +-- config/configuration.template.yaml | 6 +- config/configuration.yaml | 6 +- tests/config/configuration.yaml | 6 +- tests/test_pricer.py | 102 +++++----- 8 files changed, 317 insertions(+), 103 deletions(-) diff --git a/README.md b/README.md index 593e42d..bd4176c 100644 --- a/README.md +++ b/README.md @@ -381,7 +381,7 @@ pricing: - id: reduced start_date: "2023-06-01" # Date of the price. Format is "YYYY-MM-DD". value: 0.0550 - - id: standard + - id: normal start_date: "2023-06-01" # Date of the price. Format is "YYYY-MM-DD". value: 0.20 consumption_prices: @@ -389,7 +389,7 @@ pricing: value: 0.07790 value_unit: "€" base_unit: "kWh" - vat_id: standard + vat_id: normal - start_date: "2023-07-01" value: 0.05392 - start_date: "2023-08-01" @@ -431,7 +431,7 @@ pricing: value: 0.00837 value_unit: "€" base_unit: "kWh" - vat_id: standard + vat_id: normal - start_date: "2024-01-01" value: 0.01637 ``` diff --git a/addons/gazpar2haws/DOCS.md b/addons/gazpar2haws/DOCS.md index 1a98577..5107d6e 100644 --- a/addons/gazpar2haws/DOCS.md +++ b/addons/gazpar2haws/DOCS.md @@ -33,3 +33,251 @@ devices: | devices[].timezone | Timezone of the GrDF data | No | Europe/Paris | | devices[].last_days | Number of days of history data to retrieve | No | 365 days | | devices[].reset | Rebuild the history. If true, the data will be reset before the first data retrieval. If false, the data will be kept and new data will be added | No | false | + +## Cost configuration + +Gazpar2HAWS is able to compute and publish cost history to Home Assistant. + +The cost computation is based in gas prices defined in the configuration files. + +The pricing configuration is broken into 5 sections: +- vat: Value added tax definition. +- consumption_prices: All the gas price history in €/kWh. +- subscription_prices: The subscription prices in €/month (or year). +- transport_prices: The fixed prices in €/month (or year) to transport the gas. +- energy_taxes: Various taxes on energy in €/kWh. + +Below, many examples illustrates how to use pricing configuration for use cases from the simplest to the most complex. + + +Example 1: A fixed consumption price +--- + +The given price applies at the given date, after and before. + +The default unit is € per kWh. + +**Formula:** +```math +cost[€] = quantity[kWh] * price[€/kWh] +``` + + +```yaml +consumption_prices: + - start_date: "2023-06-01" # Date of the price. Format is "YYYY-MM-DD". + value: 0.07790 # Default unit is €/kWh. +``` + +Example 2: A fixed consumption price in another unit +--- + +*value_unit* is the price unit (default: €). +*base_unit* is the denominator unit (default: kWh). + +**Formula:** +```math +cost[€] = \frac{quantity[kWh] * price[¢/MWh] * converter\_factor[¢->€]} {converter\_factor[MWh->kWh]} +``` + + +```yaml +consumption_prices: + - start_date: "2023-06-01" # Date of the price. Format is "YYYY-MM-DD". + value: 7790.0 # Unit is now ¢/MWh. + value_unit: "¢" + base_unit: "MWh" +``` + +Example 3: Multiple prices over time +--- + +```yaml +consumption_prices: + - start_date: "2023-06-01" # Date of the price. Format is "YYYY-MM-DD". + value: 0.07790 # Default unit is €/kWh. + - start_date: "2024-01-01" + value: 0.06888 # Default unit is €/kWh. +``` + +Price is 0.07790 before 2024-01-01. + +Price is 0.06888 on 2024-01-01 and after. + + +Example 4: Price is given excluding tax +--- + +The *normal* value added tax (*vat*) rate is 20%. + +```yaml +vat: + - id: normal + start_date: "2023-06-01" # Date of the price. Format is "YYYY-MM-DD". + value: 0.20 # It is the tax rate in [0, 1.0] <==> [0% - 100%]. +consumption_prices: + - start_date: "2023-06-01" # Date of the price. Format is "YYYY-MM-DD". + value: 0.07790 # Default unit is €/kWh. + vat_id: "normal" # Reference to the vat rate that is applied for this period. +``` + +**Formula:** +```math +cost[€] = quantity[kWh] * price[€/kWh] * (1 + vat[normal]) +``` + +Example 5: Subscription price +--- + +A fixed montly subscription is due over consumption. + +Subscription *vat* tax may be different than the consumption *vat* tax. + +```yaml +vat: + - id: normal + start_date: "2023-06-01" # Date of the price. Format is "YYYY-MM-DD". + value: 0.20 # It is the tax rate in [0, 1.0] <==> [0% - 100%]. + - id: reduced + start_date: "2023-06-01" # Date of the price. Format is "YYYY-MM-DD". + value: 0.0550 +consumption_prices: + - start_date: "2023-06-01" # Date of the price. Format is "YYYY-MM-DD". + value: 0.07790 # Default unit is €/kWh. + vat_id: "normal" # Reference to the vat rate that is applied for this period. +subscription_prices: + - start_date: "2023-06-01" # Date of the price. Format is "YYYY-MM-DD". + value: 19.83 + value_unit: "€" + base_unit: "month" + vat_id: "reduced" +``` + +**Formula:** +```math +cost[€] = quantity[kWh] * cons\_price[€/kWh] * (1 + vat[normal]) + sub\_price * (1 + vat[reduced]) +``` + + +Example 6: Transport price +--- + +A fixed yearly transport may be charged as well. + +```yaml +vat: + - id: normal + start_date: "2023-06-01" # Date of the price. Format is "YYYY-MM-DD". + value: 0.20 # It is the tax rate in [0, 1.0] <==> [0% - 100%]. + - id: reduced + start_date: "2023-06-01" # Date of the price. Format is "YYYY-MM-DD". + value: 0.0550 +consumption_prices: + - start_date: "2023-06-01" # Date of the price. Format is "YYYY-MM-DD". + value: 0.07790 # Default unit is €/kWh. + vat_id: "normal" # Reference to the vat rate that is applied for this period. +transport_prices: + - start_date: "2023-06-01" # Date of the price. Format is "YYYY-MM-DD". + value: 34.38 + value_unit: "€" + base_unit: "year" + vat_id: reduced +``` +**Formula:** +```math +cost[€] = quantity[kWh] * cons\_price[€/kWh] * (1 + vat[normal]) + trans\_price * (1 + vat[reduced]) +``` + +Example 7: Energy taxes +--- + +Consumption may be taxed by additional taxes (known as energy taxes). + +```yaml +vat: + - id: normal + start_date: "2023-06-01" # Date of the price. Format is "YYYY-MM-DD". + value: 0.20 # It is the tax rate in [0, 1.0] <==> [0% - 100%]. + - id: reduced + start_date: "2023-06-01" # Date of the price. Format is "YYYY-MM-DD". + value: 0.0550 +consumption_prices: + - start_date: "2023-06-01" # Date of the price. Format is "YYYY-MM-DD". + value: 0.07790 # Default unit is €/kWh. + vat_id: "normal" # Reference to the vat rate that is applied for this period. +energy_taxes: + - start_date: "2023-06-01" # Date of the price. Format is "YYYY-MM-DD". + value: 0.00837 + value_unit: "€" + base_unit: "kWh" + vat_id: normal +``` +**Formula:** +```math +cost[€] = quantity[kWh] * (cons\_price[€/kWh] + ener\_taxes[€/kWh])* (1 + vat[normal]) +``` + +Example 8: All in one +--- + +In the price list, the first item properties are propagated to the next items in the list. If their values does not change, it is not required to repeat them. + +```yaml +vat: + - id: reduced + start_date: "2023-06-01" # Date of the price. Format is "YYYY-MM-DD". + value: 0.0550 + - id: normal + start_date: "2023-06-01" # Date of the price. Format is "YYYY-MM-DD". + value: 0.20 +consumption_prices: + - start_date: "2023-06-01" # Date of the price. Format is "YYYY-MM-DD". + value: 0.07790 + value_unit: "€" + base_unit: "kWh" + vat_id: normal + - start_date: "2023-07-01" + value: 0.05392 + - start_date: "2023-08-01" + value: 0.05568 + - start_date: "2023-09-01" + value: 0.05412 + - start_date: "2023-10-01" + value: 0.06333 + - start_date: "2023-11-01" + value: 0.06716 + - start_date: "2023-12-01" + value: 0.07235 + - start_date: "2024-01-01" + value: 0.06888 + - start_date: "2024-02-01" + value: 0.05972 + - start_date: "2024-03-01" + value: 0.05506 + - start_date: "2024-04-01" + value: 0.04842 + - start_date: "2025-01-01" + value: 0.07807 +subscription_prices: + - start_date: "2023-06-01" # Date of the price. Format is "YYYY-MM-DD". + value: 19.83 + value_unit: "€" + base_unit: "month" + vat_id: reduced + - start_date: "2023-07-01" + value: 20.36 +transport_prices: + - start_date: "2023-06-01" # Date of the price. Format is "YYYY-MM-DD". + value: 34.38 + value_unit: "€" + base_unit: "year" + vat_id: reduced +energy_taxes: + - start_date: "2023-06-01" # Date of the price. Format is "YYYY-MM-DD". + value: 0.00837 + value_unit: "€" + base_unit: "kWh" + vat_id: normal + - start_date: "2024-01-01" + value: 0.01637 +``` diff --git a/addons/gazpar2haws/config.yaml b/addons/gazpar2haws/config.yaml index ba8b178..e53dbfa 100644 --- a/addons/gazpar2haws/config.yaml +++ b/addons/gazpar2haws/config.yaml @@ -25,7 +25,7 @@ options: - id: reduced start_date: "2023-06-01" # Date of the price. Format is "YYYY-MM-DD". value: 0.0550 - - id: standard + - id: normal start_date: "2023-06-01" # Date of the price. Format is "YYYY-MM-DD". value: 0.20 consumption_prices: @@ -33,29 +33,13 @@ options: value: 0.07790 value_unit: "€" base_unit: "kWh" - vat_id: standard + vat_id: normal - start_date: "2023-07-01" value: 0.05392 - start_date: "2023-08-01" value: 0.05568 - start_date: "2023-09-01" value: 0.05412 - - start_date: "2023-10-01" - value: 0.06333 - - start_date: "2023-11-01" - value: 0.06716 - - start_date: "2023-12-01" - value: 0.07235 - - start_date: "2024-01-01" - value: 0.06888 - - start_date: "2024-02-01" - value: 0.05972 - - start_date: "2024-03-01" - value: 0.05506 - - start_date: "2024-04-01" - value: 0.04842 - - start_date: "2025-01-01" - value: 0.07807 subscription_prices: - start_date: "2023-06-01" # Date of the price. Format is "YYYY-MM-DD". value: 19.83 @@ -75,7 +59,7 @@ options: value: 0.00837 value_unit: "€" base_unit: "kWh" - vat_id: standard + vat_id: normal - start_date: "2024-01-01" value: 0.01637 schema: @@ -121,4 +105,3 @@ schema: value_unit: str? # Unit of the tax: €, ¢. base_unit: str? # Base unit of the tax: Wh, kWh, MWh, m³, l vat_id: str? # Identifier of the VAT rate. - diff --git a/addons/gazpar2haws/config.yaml.template b/addons/gazpar2haws/config.yaml.template index 62de73f..48ef9ac 100644 --- a/addons/gazpar2haws/config.yaml.template +++ b/addons/gazpar2haws/config.yaml.template @@ -25,7 +25,7 @@ options: - id: reduced start_date: "2023-06-01" # Date of the price. Format is "YYYY-MM-DD". value: 0.0550 - - id: standard + - id: normal start_date: "2023-06-01" # Date of the price. Format is "YYYY-MM-DD". value: 0.20 consumption_prices: @@ -33,29 +33,13 @@ options: value: 0.07790 value_unit: "€" base_unit: "kWh" - vat_id: standard + vat_id: normal - start_date: "2023-07-01" value: 0.05392 - start_date: "2023-08-01" value: 0.05568 - start_date: "2023-09-01" value: 0.05412 - - start_date: "2023-10-01" - value: 0.06333 - - start_date: "2023-11-01" - value: 0.06716 - - start_date: "2023-12-01" - value: 0.07235 - - start_date: "2024-01-01" - value: 0.06888 - - start_date: "2024-02-01" - value: 0.05972 - - start_date: "2024-03-01" - value: 0.05506 - - start_date: "2024-04-01" - value: 0.04842 - - start_date: "2025-01-01" - value: 0.07807 subscription_prices: - start_date: "2023-06-01" # Date of the price. Format is "YYYY-MM-DD". value: 19.83 @@ -75,7 +59,7 @@ options: value: 0.00837 value_unit: "€" base_unit: "kWh" - vat_id: standard + vat_id: normal - start_date: "2024-01-01" value: 0.01637 schema: @@ -121,4 +105,3 @@ schema: value_unit: str? # Unit of the tax: €, ¢. base_unit: str? # Base unit of the tax: Wh, kWh, MWh, m³, l vat_id: str? # Identifier of the VAT rate. - diff --git a/config/configuration.template.yaml b/config/configuration.template.yaml index a16752c..f15740e 100644 --- a/config/configuration.template.yaml +++ b/config/configuration.template.yaml @@ -29,7 +29,7 @@ pricing: - id: reduced start_date: "2023-06-01" # Date of the price. Format is "YYYY-MM-DD". value: 0.0550 - - id: standard + - id: normal start_date: "2023-06-01" # Date of the price. Format is "YYYY-MM-DD". value: 0.20 consumption_prices: @@ -37,7 +37,7 @@ pricing: value: 0.07790 value_unit: "€" base_unit: "kWh" - vat_id: standard + vat_id: normal - start_date: "2023-07-01" value: 0.05392 - start_date: "2023-08-01" @@ -79,6 +79,6 @@ pricing: value: 0.00837 value_unit: "€" base_unit: "kWh" - vat_id: standard + vat_id: normal - start_date: "2024-01-01" value: 0.01637 diff --git a/config/configuration.yaml b/config/configuration.yaml index 6f439bd..a39c28b 100644 --- a/config/configuration.yaml +++ b/config/configuration.yaml @@ -26,7 +26,7 @@ pricing: - id: reduced start_date: "2023-06-01" # Date of the price. Format is "YYYY-MM-DD". value: 0.0550 - - id: standard + - id: normal start_date: "2023-06-01" # Date of the price. Format is "YYYY-MM-DD". value: 0.20 consumption_prices: @@ -34,7 +34,7 @@ pricing: value: 0.07790 value_unit: "€" base_unit: "kWh" - vat_id: standard + vat_id: normal - start_date: "2023-07-01" value: 0.05392 - start_date: "2023-08-01" @@ -76,6 +76,6 @@ pricing: value: 0.00837 value_unit: "€" base_unit: "kWh" - vat_id: standard + vat_id: normal - start_date: "2024-01-01" value: 0.01637 diff --git a/tests/config/configuration.yaml b/tests/config/configuration.yaml index 942a60b..c856730 100644 --- a/tests/config/configuration.yaml +++ b/tests/config/configuration.yaml @@ -24,7 +24,7 @@ pricing: - id: reduced start_date: "2023-06-01" # Date of the price. Format is "YYYY-MM-DD". value: 0.0550 - - id: standard + - id: normal start_date: "2023-06-01" # Date of the price. Format is "YYYY-MM-DD". value: 0.20 consumption_prices: @@ -32,7 +32,7 @@ pricing: value: 0.07790 value_unit: "€" base_unit: "kWh" - vat_id: standard + vat_id: normal - start_date: "2023-07-01" value: 0.05392 - start_date: "2023-08-01" @@ -74,6 +74,6 @@ pricing: value: 0.00837 value_unit: "€" base_unit: "kWh" - vat_id: standard + vat_id: normal - start_date: "2024-01-01" value: 0.01637 diff --git a/tests/test_pricer.py b/tests/test_pricer.py index f534e72..2aa1532 100644 --- a/tests/test_pricer.py +++ b/tests/test_pricer.py @@ -34,7 +34,7 @@ def test_get_consumption_price_array_inside(self): vat_rate_array_by_id = { "reduced": VatRateArray(id="reduced", start_date=start_date, end_date=end_date), - "standard": VatRateArray(id="standard", start_date=start_date, end_date=end_date), + "normal": VatRateArray(id="normal", start_date=start_date, end_date=end_date), } consumption_price_array = Pricer.get_consumption_price_array( @@ -48,7 +48,7 @@ def test_get_consumption_price_array_inside(self): assert consumption_price_array.end_date == end_date assert consumption_price_array.value_unit == "€" assert consumption_price_array.base_unit == "kWh" - assert consumption_price_array.vat_id == "standard" + assert consumption_price_array.vat_id == "normal" assert len(consumption_price_array.value_array) == 6 assert consumption_price_array.value_array[start_date] == 0.05568 assert consumption_price_array.value_array[end_date] == 0.05568 @@ -61,7 +61,7 @@ def test_get_consumption_price_array_accross_middle(self): vat_rate_array_by_id = { "reduced": VatRateArray(id="reduced", start_date=start_date, end_date=end_date), - "standard": VatRateArray(id="standard", start_date=start_date, end_date=end_date), + "normal": VatRateArray(id="normal", start_date=start_date, end_date=end_date), } consumption_price_array = Pricer.get_consumption_price_array( @@ -75,7 +75,7 @@ def test_get_consumption_price_array_accross_middle(self): assert consumption_price_array.end_date == end_date assert consumption_price_array.value_unit == "€" assert consumption_price_array.base_unit == "kWh" - assert consumption_price_array.vat_id == "standard" + assert consumption_price_array.vat_id == "normal" assert len(consumption_price_array.value_array) == 17 assert consumption_price_array.value_array[start_date] == 0.05568 assert consumption_price_array.value_array[end_date] == 0.05412 @@ -88,7 +88,7 @@ def test_get_consumption_price_array_accross_start(self): vat_rate_array_by_id = { "reduced": VatRateArray(id="reduced", start_date=start_date, end_date=end_date), - "standard": VatRateArray(id="standard", start_date=start_date, end_date=end_date), + "normal": VatRateArray(id="normal", start_date=start_date, end_date=end_date), } consumption_price_array = Pricer.get_consumption_price_array( @@ -102,7 +102,7 @@ def test_get_consumption_price_array_accross_start(self): assert consumption_price_array.end_date == end_date assert consumption_price_array.value_unit == "€" assert consumption_price_array.base_unit == "kWh" - assert consumption_price_array.vat_id == "standard" + assert consumption_price_array.vat_id == "normal" assert len(consumption_price_array.value_array) == 12 assert consumption_price_array.value_array[start_date] == 0.07790 assert consumption_price_array.value_array[end_date] == 0.07790 @@ -115,7 +115,7 @@ def test_get_consumption_price_array_accross_end(self): vat_rate_array_by_id = { "reduced": VatRateArray(id="reduced", start_date=start_date, end_date=end_date), - "standard": VatRateArray(id="standard", start_date=start_date, end_date=end_date), + "normal": VatRateArray(id="normal", start_date=start_date, end_date=end_date), } consumption_price_array = Pricer.get_consumption_price_array( @@ -129,7 +129,7 @@ def test_get_consumption_price_array_accross_end(self): assert consumption_price_array.end_date == end_date assert consumption_price_array.value_unit == "€" assert consumption_price_array.base_unit == "kWh" - assert consumption_price_array.vat_id == "standard" + assert consumption_price_array.vat_id == "normal" assert len(consumption_price_array.value_array) == 12 assert consumption_price_array.value_array[start_date] == 0.04842 assert consumption_price_array.value_array[end_date] == 0.07807 @@ -142,7 +142,7 @@ def test_get_consumption_price_array_outside(self): vat_rate_array_by_id = { "reduced": VatRateArray(id="reduced", start_date=start_date, end_date=end_date), - "standard": VatRateArray(id="standard", start_date=start_date, end_date=end_date), + "normal": VatRateArray(id="normal", start_date=start_date, end_date=end_date), } consumption_price_array = Pricer.get_consumption_price_array( @@ -156,7 +156,7 @@ def test_get_consumption_price_array_outside(self): assert consumption_price_array.end_date == end_date assert consumption_price_array.value_unit == "€" assert consumption_price_array.base_unit == "kWh" - assert consumption_price_array.vat_id == "standard" + assert consumption_price_array.vat_id == "normal" assert len(consumption_price_array.value_array) == 48 assert consumption_price_array.value_array[start_date] == 0.05392 assert consumption_price_array.value_array[end_date] == 0.05412 @@ -169,7 +169,7 @@ def test_get_consumption_price_array_before(self): vat_rate_array_by_id = { "reduced": VatRateArray(id="reduced", start_date=start_date, end_date=end_date), - "standard": VatRateArray(id="standard", start_date=start_date, end_date=end_date), + "normal": VatRateArray(id="normal", start_date=start_date, end_date=end_date), } consumption_price_array = Pricer.get_consumption_price_array( @@ -183,7 +183,7 @@ def test_get_consumption_price_array_before(self): assert consumption_price_array.end_date == end_date assert consumption_price_array.value_unit == "€" assert consumption_price_array.base_unit == "kWh" - assert consumption_price_array.vat_id == "standard" + assert consumption_price_array.vat_id == "normal" assert len(consumption_price_array.value_array) == 5 assert consumption_price_array.value_array[start_date] == 0.07790 assert consumption_price_array.value_array[end_date] == 0.07790 @@ -196,7 +196,7 @@ def test_get_consumption_price_array_after(self): vat_rate_array_by_id = { "reduced": VatRateArray(id="reduced", start_date=start_date, end_date=end_date), - "standard": VatRateArray(id="standard", start_date=start_date, end_date=end_date), + "normal": VatRateArray(id="normal", start_date=start_date, end_date=end_date), } consumption_price_array = Pricer.get_consumption_price_array( @@ -210,7 +210,7 @@ def test_get_consumption_price_array_after(self): assert consumption_price_array.end_date == end_date assert consumption_price_array.value_unit == "€" assert consumption_price_array.base_unit == "kWh" - assert consumption_price_array.vat_id == "standard" + assert consumption_price_array.vat_id == "normal" assert len(consumption_price_array.value_array) == 5 assert consumption_price_array.value_array[start_date] == 0.07807 assert consumption_price_array.value_array[end_date] == 0.07807 @@ -229,17 +229,17 @@ def test_get_vat_rate_array_by_id(self): assert len(vat_rate_array_by_id) == 2 assert vat_rate_array_by_id.get("reduced") is not None - assert vat_rate_array_by_id.get("standard") is not None + assert vat_rate_array_by_id.get("normal") is not None assert vat_rate_array_by_id.get("reduced").start_date == start_date assert vat_rate_array_by_id.get("reduced").end_date == end_date assert len(vat_rate_array_by_id.get("reduced").value_array) == 6 assert vat_rate_array_by_id.get("reduced").value_array[start_date] == 0.055 assert vat_rate_array_by_id.get("reduced").value_array[end_date] == 0.055 - assert vat_rate_array_by_id.get("standard").start_date == start_date - assert vat_rate_array_by_id.get("standard").end_date == end_date - assert len(vat_rate_array_by_id.get("standard").value_array) == 6 - assert vat_rate_array_by_id.get("standard").value_array[start_date] == 0.2 - assert vat_rate_array_by_id.get("standard").value_array[end_date] == 0.2 + assert vat_rate_array_by_id.get("normal").start_date == start_date + assert vat_rate_array_by_id.get("normal").end_date == end_date + assert len(vat_rate_array_by_id.get("normal").value_array) == 6 + assert vat_rate_array_by_id.get("normal").value_array[start_date] == 0.2 + assert vat_rate_array_by_id.get("normal").value_array[end_date] == 0.2 # ---------------------------------- def test_get_time_unit_convertion_factor(self): @@ -247,54 +247,54 @@ def test_get_time_unit_convertion_factor(self): dt = date(2023, 8, 20) assert math.isclose( - self._pricer.get_time_unit_convertion_factor(TimeUnit.YEAR, TimeUnit.MONTH, dt), 12, rel_tol=1e-6 + Pricer.get_time_unit_convertion_factor(TimeUnit.YEAR, TimeUnit.MONTH, dt), 12, rel_tol=1e-6 ) assert math.isclose( - self._pricer.get_time_unit_convertion_factor(TimeUnit.MONTH, TimeUnit.YEAR, dt), 1 / 12, rel_tol=1e-6 + Pricer.get_time_unit_convertion_factor(TimeUnit.MONTH, TimeUnit.YEAR, dt), 1 / 12, rel_tol=1e-6 ) assert math.isclose( - self._pricer.get_time_unit_convertion_factor(TimeUnit.YEAR, TimeUnit.DAY, dt), 365, rel_tol=1e-6 + Pricer.get_time_unit_convertion_factor(TimeUnit.YEAR, TimeUnit.DAY, dt), 365, rel_tol=1e-6 ) assert math.isclose( - self._pricer.get_time_unit_convertion_factor(TimeUnit.DAY, TimeUnit.YEAR, dt), 1 / 365, rel_tol=1e-6 + Pricer.get_time_unit_convertion_factor(TimeUnit.DAY, TimeUnit.YEAR, dt), 1 / 365, rel_tol=1e-6 ) assert math.isclose( - self._pricer.get_time_unit_convertion_factor(TimeUnit.MONTH, TimeUnit.DAY, dt), 31, rel_tol=1e-6 + Pricer.get_time_unit_convertion_factor(TimeUnit.MONTH, TimeUnit.DAY, dt), 31, rel_tol=1e-6 ) assert math.isclose( - self._pricer.get_time_unit_convertion_factor(TimeUnit.DAY, TimeUnit.MONTH, dt), 1 / 31, rel_tol=1e-6 + Pricer.get_time_unit_convertion_factor(TimeUnit.DAY, TimeUnit.MONTH, dt), 1 / 31, rel_tol=1e-6 ) # ---------------------------------- def test_get_price_unit_convertion_factor(self): assert math.isclose( - self._pricer.get_price_unit_convertion_factor(PriceUnit.EURO, PriceUnit.CENT), 100.0, rel_tol=1e-6 + Pricer.get_price_unit_convertion_factor(PriceUnit.EURO, PriceUnit.CENT), 100.0, rel_tol=1e-6 ) assert math.isclose( - self._pricer.get_price_unit_convertion_factor(PriceUnit.CENT, PriceUnit.EURO), 0.01, rel_tol=1e-6 + Pricer.get_price_unit_convertion_factor(PriceUnit.CENT, PriceUnit.EURO), 0.01, rel_tol=1e-6 ) # ---------------------------------- def test_get_quantity_unit_convertion_factor(self): assert math.isclose( - self._pricer.get_quantity_unit_convertion_factor(QuantityUnit.KWH, QuantityUnit.MWH), 0.001, rel_tol=1e-6 + Pricer.get_quantity_unit_convertion_factor(QuantityUnit.KWH, QuantityUnit.MWH), 0.001, rel_tol=1e-6 ) assert math.isclose( - self._pricer.get_quantity_unit_convertion_factor(QuantityUnit.MWH, QuantityUnit.KWH), 1000.0, rel_tol=1e-6 + Pricer.get_quantity_unit_convertion_factor(QuantityUnit.MWH, QuantityUnit.KWH), 1000.0, rel_tol=1e-6 ) assert math.isclose( - self._pricer.get_quantity_unit_convertion_factor(QuantityUnit.WH, QuantityUnit.KWH), 0.001, rel_tol=1e-6 + Pricer.get_quantity_unit_convertion_factor(QuantityUnit.WH, QuantityUnit.KWH), 0.001, rel_tol=1e-6 ) assert math.isclose( - self._pricer.get_quantity_unit_convertion_factor(QuantityUnit.KWH, QuantityUnit.WH), 1000.0, rel_tol=1e-6 + Pricer.get_quantity_unit_convertion_factor(QuantityUnit.KWH, QuantityUnit.WH), 1000.0, rel_tol=1e-6 ) assert math.isclose( - self._pricer.get_quantity_unit_convertion_factor(QuantityUnit.WH, QuantityUnit.MWH), 0.000001, rel_tol=1e-6 + Pricer.get_quantity_unit_convertion_factor(QuantityUnit.WH, QuantityUnit.MWH), 0.000001, rel_tol=1e-6 ) assert math.isclose( - self._pricer.get_quantity_unit_convertion_factor(QuantityUnit.MWH, QuantityUnit.WH), 1000000.0, rel_tol=1e-6 + Pricer.get_quantity_unit_convertion_factor(QuantityUnit.MWH, QuantityUnit.WH), 1000000.0, rel_tol=1e-6 ) # ---------------------------------- @@ -314,33 +314,33 @@ def test_get_convertion_factor(self): euro_per_day = (PriceUnit.EURO, TimeUnit.DAY) cent_per_day = (PriceUnit.CENT, TimeUnit.DAY) - assert math.isclose(self._pricer.get_convertion_factor(euro_per_kwh, euro_per_kwh), 1.0, rel_tol=1e-6) - assert math.isclose(self._pricer.get_convertion_factor(euro_per_kwh, cent_per_kwh), 100.0, rel_tol=1e-6) - assert math.isclose(self._pricer.get_convertion_factor(cent_per_kwh, euro_per_kwh), 0.01, rel_tol=1e-6) + assert math.isclose(Pricer.get_convertion_factor(euro_per_kwh, euro_per_kwh), 1.0, rel_tol=1e-6) + assert math.isclose(Pricer.get_convertion_factor(euro_per_kwh, cent_per_kwh), 100.0, rel_tol=1e-6) + assert math.isclose(Pricer.get_convertion_factor(cent_per_kwh, euro_per_kwh), 0.01, rel_tol=1e-6) - assert math.isclose(self._pricer.get_convertion_factor(euro_per_kwh, euro_per_mwh), 1000.0, rel_tol=1e-6) - assert math.isclose(self._pricer.get_convertion_factor(euro_per_mwh, euro_per_kwh), 0.001, rel_tol=1e-6) + assert math.isclose(Pricer.get_convertion_factor(euro_per_kwh, euro_per_mwh), 1000.0, rel_tol=1e-6) + assert math.isclose(Pricer.get_convertion_factor(euro_per_mwh, euro_per_kwh), 0.001, rel_tol=1e-6) - assert math.isclose(self._pricer.get_convertion_factor(cent_per_mwh, euro_per_kwh), 0.00001, rel_tol=1e-6) + assert math.isclose(Pricer.get_convertion_factor(cent_per_mwh, euro_per_kwh), 0.00001, rel_tol=1e-6) - assert math.isclose(self._pricer.get_convertion_factor(euro_per_year, euro_per_month, dt), 1 / 12, rel_tol=1e-6) - assert math.isclose(self._pricer.get_convertion_factor(euro_per_month, euro_per_year, dt), 12, rel_tol=1e-6) - assert math.isclose(self._pricer.get_convertion_factor(euro_per_year, euro_per_day, dt), 1 / 365, rel_tol=1e-6) - assert math.isclose(self._pricer.get_convertion_factor(euro_per_day, euro_per_year, dt), 365, rel_tol=1e-6) - assert math.isclose(self._pricer.get_convertion_factor(euro_per_month, euro_per_day, dt), 1 / 31, rel_tol=1e-6) - assert math.isclose(self._pricer.get_convertion_factor(euro_per_day, euro_per_month, dt), 31, rel_tol=1e-6) + assert math.isclose(Pricer.get_convertion_factor(euro_per_year, euro_per_month, dt), 1 / 12, rel_tol=1e-6) + assert math.isclose(Pricer.get_convertion_factor(euro_per_month, euro_per_year, dt), 12, rel_tol=1e-6) + assert math.isclose(Pricer.get_convertion_factor(euro_per_year, euro_per_day, dt), 1 / 365, rel_tol=1e-6) + assert math.isclose(Pricer.get_convertion_factor(euro_per_day, euro_per_year, dt), 365, rel_tol=1e-6) + assert math.isclose(Pricer.get_convertion_factor(euro_per_month, euro_per_day, dt), 1 / 31, rel_tol=1e-6) + assert math.isclose(Pricer.get_convertion_factor(euro_per_day, euro_per_month, dt), 31, rel_tol=1e-6) - assert math.isclose(self._pricer.get_convertion_factor(cent_per_year, cent_per_month, dt), 1 / 12, rel_tol=1e-6) - assert math.isclose(self._pricer.get_convertion_factor(cent_per_month, cent_per_year, dt), 12, rel_tol=1e-6) - assert math.isclose(self._pricer.get_convertion_factor(cent_per_year, cent_per_day, dt), 1 / 365, rel_tol=1e-6) - assert math.isclose(self._pricer.get_convertion_factor(cent_per_day, cent_per_year, dt), 365, rel_tol=1e-6) + assert math.isclose(Pricer.get_convertion_factor(cent_per_year, cent_per_month, dt), 1 / 12, rel_tol=1e-6) + assert math.isclose(Pricer.get_convertion_factor(cent_per_month, cent_per_year, dt), 12, rel_tol=1e-6) + assert math.isclose(Pricer.get_convertion_factor(cent_per_year, cent_per_day, dt), 1 / 365, rel_tol=1e-6) + assert math.isclose(Pricer.get_convertion_factor(cent_per_day, cent_per_year, dt), 365, rel_tol=1e-6) # ---------------------------------- def test_convert(self): consumption_prices = self._pricer.pricing_data().consumption_prices - converted_prices = self._pricer.convert(consumption_prices, (PriceUnit.CENT, QuantityUnit.WH)) + converted_prices = Pricer.convert(consumption_prices, (PriceUnit.CENT, QuantityUnit.WH)) for i in range(len(consumption_prices) - 1): consumption_price = consumption_prices[i]