diff --git a/tests/dummy_data_store.h5 b/tests/dummy_data_store.h5 new file mode 100644 index 0000000..9cc696f Binary files /dev/null and b/tests/dummy_data_store.h5 differ diff --git a/tests/tariff_block_demand.json b/tests/tariff_block_demand.json new file mode 100644 index 0000000..17eac56 --- /dev/null +++ b/tests/tariff_block_demand.json @@ -0,0 +1,33 @@ +{ + "charges": [ + + + { + "type":"consumption", + "rate":0.117545, + "meter": "imported energy (kwh)" + }, + { + "rate": 0, + "meter": "exported energy (kwh)" + }, + { + "type": "demand", + "meter": "imported power (kw)", + "rate_bands": [ + { + "rate": 0, + "limit": 120 + }, + { + "rate": 28.45 + } + ] + } + ], + "service": "electricity", + "consumption_unit": "kWh", + "demand_unit": "kW", + "demand_window": "30min", + "billing_period": "monthly" + } \ No newline at end of file diff --git a/tests/tariff_cons_demand.json b/tests/tariff_cons_demand.json new file mode 100644 index 0000000..17eac56 --- /dev/null +++ b/tests/tariff_cons_demand.json @@ -0,0 +1,33 @@ +{ + "charges": [ + + + { + "type":"consumption", + "rate":0.117545, + "meter": "imported energy (kwh)" + }, + { + "rate": 0, + "meter": "exported energy (kwh)" + }, + { + "type": "demand", + "meter": "imported power (kw)", + "rate_bands": [ + { + "rate": 0, + "limit": 120 + }, + { + "rate": 28.45 + } + ] + } + ], + "service": "electricity", + "consumption_unit": "kWh", + "demand_unit": "kW", + "demand_window": "30min", + "billing_period": "monthly" + } \ No newline at end of file diff --git a/tests/tariff_multi_tou.json b/tests/tariff_multi_tou.json new file mode 100644 index 0000000..a58ce1c --- /dev/null +++ b/tests/tariff_multi_tou.json @@ -0,0 +1,167 @@ + + { + "charges": [ + { + "rate": 0.018066091, + "meter": "imported energy (kwh)" + }, + { + "rate": 0.0399909090909091, + "meter": "imported energy (kwh)" + "time": { + "name": "peak", + "periods": [ + { + "weekdays": 1111100, + "from_hour": 14, + "from_minute": 0, + "to_hour": 19, + "to_minute": 59 + } + ] + } + }, + { + "rate": 0.0191381818181818, + "meter": "imported energy (kwh)" + "time": { + "name": "shoulder", + "periods": [ + { + "weekdays": 1111100, + "from_hour": 7, + "from_minute": 0, + "to_hour": 13, + "to_minute": 59 + }, + { + "weekdays": 1111100, + "from_hour": 20, + "from_minute": 0, + "to_hour": 21, + "to_minute": 59 + } + ] + } + }, + { + "rate":0.01261 + "meter": "imported energy (kwh)" + "time": { + "name": "off-peak" + "periods":[ + { + "weekdays": 1111100, + "from_hour": 0, + "from_minute": 0, + "to_hour": 6, + "to_minute": 59 + }, + { + "weekdays": 1111100, + "from_hour": 22, + "from_minute": 0, + "to_hour": 23, + "to_minute": 59 + }, + { + "weekdays": 0000011, + "from_hour": 0, + "from_minute": 0, + "to_hour": 23, + "to_minute": 59 + } + ] + } + }, + { + "rate": 0.0865693, + "meter": "imported energy (kwh)" + "time": { + "name": "peak", + "periods": [ + { + "weekdays": 1111100, + "from_hour": 7, + "from_minute": 0, + "to_hour": 8, + "to_minute": 59 + }, + { + "weekdays": 1111100, + "from_hour": 17, + "from_minute": 0, + "to_hour": 19, + "to_minute": 59 + } + ] + } + }, + { + "rate": 0.0865693, + "meter": "imported energy (kwh)" + "time": { + "name": "shoulder", + "periods": [ + { + "weekdays": 1111100, + "from_hour": 9, + "from_minute": 0, + "to_hour": 16, + "to_minute": 59 + }, + { + "weekdays": 1111100, + "from_hour": 20, + "from_minute": 0, + "to_hour": 21, + "to_minute": 59 + } + ] + } + }, + { + "rate":0.0491122654545455 + "meter": "imported energy (kwh)" + "time": { + "name": "off-peak" + "periods":[ + { + "weekdays": 1111100, + "from_hour": 0, + "from_minute": 0, + "to_hour": 6, + "to_minute": 59 + }, + { + "weekdays": 1111100, + "from_hour": 22, + "from_minute": 0, + "to_hour": 23, + "to_minute": 59 + }, + { + "weekdays": 0000011, + "from_hour": 0, + "from_minute": 0, + "to_hour": 23, + "to_minute": 59 + } + ] + } + }, + { + "type": "demand", + "meter": "imported power (kw)", + "rate": 9.883121591 + } + ], + "service": "electricity", + "consumption_unit": "kWh", + "demand_unit": "kVA", + "billing_period": "monthly" + } + + + + diff --git a/tests/tariff_multi_tou_weekday.json b/tests/tariff_multi_tou_weekday.json new file mode 100644 index 0000000..c25bb5b --- /dev/null +++ b/tests/tariff_multi_tou_weekday.json @@ -0,0 +1,163 @@ + + { + "charges": [ + { + "rate": 0.0399909090909091, + "meter": "imported energy (kwh)" + "time": { + "name": "peak", + "periods": [ + { + "weekdays": 1111100, + "from_hour": 14, + "from_minute": 0, + "to_hour": 19, + "to_minute": 59 + } + ] + } + }, + { + "rate": 0.0191381818181818, + "meter": "imported energy (kwh)" + "time": { + "name": "shoulder", + "periods": [ + { + "weekdays": 1111100, + "from_hour": 7, + "from_minute": 0, + "to_hour": 13, + "to_minute": 59 + }, + { + "weekdays": 1111100, + "from_hour": 20, + "from_minute": 0, + "to_hour": 21, + "to_minute": 59 + } + ] + } + }, + { + "rate":0.01261 + "meter": "imported energy (kwh)" + "time": { + "name": "off-peak" + "periods":[ + { + "weekdays": 1111100, + "from_hour": 0, + "from_minute": 0, + "to_hour": 6, + "to_minute": 59 + }, + { + "weekdays": 1111100, + "from_hour": 22, + "from_minute": 0, + "to_hour": 23, + "to_minute": 59 + }, + { + "weekdays": 0000011, + "from_hour": 0, + "from_minute": 0, + "to_hour": 23, + "to_minute": 59 + } + ] + } + }, + { + "rate": 0.0865693, + "meter": "imported energy (kwh)" + "time": { + "name": "peak", + "periods": [ + { + "weekdays": 1111100, + "from_hour": 7, + "from_minute": 0, + "to_hour": 8, + "to_minute": 59 + }, + { + "weekdays": 1111100, + "from_hour": 17, + "from_minute": 0, + "to_hour": 19, + "to_minute": 59 + } + ] + } + }, + { + "rate": 0.0865693, + "meter": "imported energy (kwh)" + "time": { + "name": "shoulder", + "periods": [ + { + "weekdays": 1111100, + "from_hour": 9, + "from_minute": 0, + "to_hour": 16, + "to_minute": 59 + }, + { + "weekdays": 1111100, + "from_hour": 20, + "from_minute": 0, + "to_hour": 21, + "to_minute": 59 + } + ] + } + }, + { + "rate":0.0491122654545455 + "meter": "imported energy (kwh)" + "time": { + "name": "off-peak" + "periods":[ + { + "weekdays": 1111100, + "from_hour": 0, + "from_minute": 0, + "to_hour": 6, + "to_minute": 59 + }, + { + "weekdays": 1111100, + "from_hour": 22, + "from_minute": 0, + "to_hour": 23, + "to_minute": 59 + }, + { + "weekdays": 0000011, + "from_hour": 0, + "from_minute": 0, + "to_hour": 23, + "to_minute": 59 + } + ] + } + }, + { + "type": "demand", + "meter": "imported power (kw)", + "rate": 9.883121591 + } + ], + "service": "electricity", + "consumption_unit": "kWh", + "demand_unit": "kVA", + "billing_period": "monthly" + } + + + + diff --git a/tests/tariff_test_day_tou.json b/tests/tariff_test_day_tou.json new file mode 100644 index 0000000..c25bb5b --- /dev/null +++ b/tests/tariff_test_day_tou.json @@ -0,0 +1,163 @@ + + { + "charges": [ + { + "rate": 0.0399909090909091, + "meter": "imported energy (kwh)" + "time": { + "name": "peak", + "periods": [ + { + "weekdays": 1111100, + "from_hour": 14, + "from_minute": 0, + "to_hour": 19, + "to_minute": 59 + } + ] + } + }, + { + "rate": 0.0191381818181818, + "meter": "imported energy (kwh)" + "time": { + "name": "shoulder", + "periods": [ + { + "weekdays": 1111100, + "from_hour": 7, + "from_minute": 0, + "to_hour": 13, + "to_minute": 59 + }, + { + "weekdays": 1111100, + "from_hour": 20, + "from_minute": 0, + "to_hour": 21, + "to_minute": 59 + } + ] + } + }, + { + "rate":0.01261 + "meter": "imported energy (kwh)" + "time": { + "name": "off-peak" + "periods":[ + { + "weekdays": 1111100, + "from_hour": 0, + "from_minute": 0, + "to_hour": 6, + "to_minute": 59 + }, + { + "weekdays": 1111100, + "from_hour": 22, + "from_minute": 0, + "to_hour": 23, + "to_minute": 59 + }, + { + "weekdays": 0000011, + "from_hour": 0, + "from_minute": 0, + "to_hour": 23, + "to_minute": 59 + } + ] + } + }, + { + "rate": 0.0865693, + "meter": "imported energy (kwh)" + "time": { + "name": "peak", + "periods": [ + { + "weekdays": 1111100, + "from_hour": 7, + "from_minute": 0, + "to_hour": 8, + "to_minute": 59 + }, + { + "weekdays": 1111100, + "from_hour": 17, + "from_minute": 0, + "to_hour": 19, + "to_minute": 59 + } + ] + } + }, + { + "rate": 0.0865693, + "meter": "imported energy (kwh)" + "time": { + "name": "shoulder", + "periods": [ + { + "weekdays": 1111100, + "from_hour": 9, + "from_minute": 0, + "to_hour": 16, + "to_minute": 59 + }, + { + "weekdays": 1111100, + "from_hour": 20, + "from_minute": 0, + "to_hour": 21, + "to_minute": 59 + } + ] + } + }, + { + "rate":0.0491122654545455 + "meter": "imported energy (kwh)" + "time": { + "name": "off-peak" + "periods":[ + { + "weekdays": 1111100, + "from_hour": 0, + "from_minute": 0, + "to_hour": 6, + "to_minute": 59 + }, + { + "weekdays": 1111100, + "from_hour": 22, + "from_minute": 0, + "to_hour": 23, + "to_minute": 59 + }, + { + "weekdays": 0000011, + "from_hour": 0, + "from_minute": 0, + "to_hour": 23, + "to_minute": 59 + } + ] + } + }, + { + "type": "demand", + "meter": "imported power (kw)", + "rate": 9.883121591 + } + ], + "service": "electricity", + "consumption_unit": "kWh", + "demand_unit": "kVA", + "billing_period": "monthly" + } + + + + diff --git a/tests/tariff_test_flat.json b/tests/tariff_test_flat.json new file mode 100644 index 0000000..5e53788 --- /dev/null +++ b/tests/tariff_test_flat.json @@ -0,0 +1,13 @@ +{ + "charges": [ + { + "type":"consumption", + "rate": 0.15, + "meter": "imported energy (kwh)" + } + ], + "service": "electricity", + "consumption_unit": "kWh", + "demand_unit": "kVA", + "billing_period": "monthly" + } \ No newline at end of file diff --git a/tests/tariff_test_tou.json b/tests/tariff_test_tou.json new file mode 100644 index 0000000..538e4c9 --- /dev/null +++ b/tests/tariff_test_tou.json @@ -0,0 +1,65 @@ +{ + "charges": [ + { + "rate": 1, + "meter": "imported energy (kwh)", + "time": { + "name": "peak", + "periods": [ + { + "from_hour": 14, + "from_minute": 0, + "to_hour": 19, + "to_minute": 59 + } + ] + } + }, + { + "rate": 1, + "meter": "imported energy (kwh)", + "time": { + "name": "shoulder", + "periods": [ + { + "from_hour": 10, + "from_minute": 0, + "to_hour": 13, + "to_minute": 59 + }, + { + "from_hour": 20, + "from_minute": 0, + "to_hour": 21, + "to_minute": 59 + } + ] + } + }, + { + "rate": 1, + "meter": "imported energy (kwh)", + "time": { + "name": "off-peak", + "periods": [ + { + "from_hour": 0, + "from_minute": 0, + "to_hour": 9, + "to_minute": 59 + }, + { + "from_hour": 22, + "from_minute": 0, + "to_hour": 23, + "to_minute": 59 + } + ] + } + } + ], + "service": "electricity", + "consumption_unit": "kWh", + "demand_unit": "kVA", + "billing_period": "monthly" + } \ No newline at end of file diff --git a/tests/tariff_test_tou_single_period.json b/tests/tariff_test_tou_single_period.json new file mode 100644 index 0000000..4f94500 --- /dev/null +++ b/tests/tariff_test_tou_single_period.json @@ -0,0 +1,22 @@ +{ + "charges": [ + { + "rate": 1, + "time": { + "name": "peak", + "periods": [ + { + "from_hour": 0, + "from_minute": 0, + "to_hour": 23, + "to_minute": 59 + } + ] + } + } + ], + "service": "electricity", + "consumption_unit": "kWh", + "demand_unit": "kVA", + "billing_period": "monthly" + } \ No newline at end of file diff --git a/tests/test_calculations.py b/tests/test_calculations.py index 39cf0e5..8f0b451 100644 --- a/tests/test_calculations.py +++ b/tests/test_calculations.py @@ -1,13 +1,17 @@ from tariffs.tariff import Tariff import pytest + from odin.codecs import dict_codec +from odin.codecs import json_codec import pandas import datetime + parser = lambda t: datetime.datetime.strptime(t, '%d/%m/%Y %H:%M') + class TestTariff(object): @pytest.fixture @@ -17,19 +21,33 @@ def meter_data(self): date_parser=parser) return meter_data + @pytest.fixture + def series_data_df(self): + working_data_store = pandas.HDFStore('dummy_data_store.h5') + series_data_df = working_data_store.select('time_series_data') + working_data_store.close() + return series_data_df + + @pytest.fixture def block_tariff(self): block_tariff = dict_codec.load( { "charges": [ { + "type": "consumption", + "meter": "imported energy (kwh)", "rate_bands": [ { "limit": 10, - "rate": 1.0 + "rate": 0.10 }, { - "rate": 1.0 + "limit": 400, + "rate": 0.15 + }, + { + "rate": 0.30 } ] } @@ -146,6 +164,7 @@ def scheduled_tariff(self): { "charges": [ { + "meter": "imported energy (kwh)", "rate_schedule": [ { "datetime":"2018-01-01T00:00:00Z", @@ -186,7 +205,8 @@ def demand_tariff(self): { "charges": [ { - "rate": 1.0, + "rate": 0.1, + "meter": "imported power (kw)", "type": "demand" } ] @@ -194,6 +214,78 @@ def demand_tariff(self): ) return demand_tariff + + def test_flat_tariff(self,series_data_df): + expected_bill = 1339.20 + meter_data_df = pandas.DataFrame([]) + meter_data_df['imported energy (kwh)'] = series_data_df['load_series_flat'] + with open('tariff_test_flat.json') as f: + test_tariff = json_codec.load(f, Tariff) + actual_bill = test_tariff.apply(meter_data_df) + assert actual_bill == pytest.approx(expected_bill) + + def test_block_tariff(self,series_data_df, block_tariff): + expected_bill = 162.549 + meter_data_df = pandas.DataFrame([]) + meter_data_df['imported energy (kwh)'] = series_data_df['load_series_real'] + actual_bill = block_tariff.apply(meter_data_df) + assert actual_bill == pytest.approx(expected_bill) + + def test_tou_tariff(self, series_data_df): + expected_bill = 8928 + meter_data_df = pandas.DataFrame([]) + meter_data_df['imported energy (kwh)'] = series_data_df['load_series_flat'] + with open('tariff_test_tou.json') as f: + test_tariff = json_codec.load(f, Tariff) + actual_bill = test_tariff.apply(meter_data_df) + assert actual_bill == pytest.approx(expected_bill) + + def test_demand_tariff(self, demand_tariff, series_data_df): + expected_bill = 300*0.1 + meter_data_df = pandas.DataFrame([]) + meter_data_df['imported energy (kwh)'] = series_data_df['load_series_bimodal'] + meter_data_df['imported power (kw)'] = series_data_df['load_series_bimodal']*60 + actual_bill = demand_tariff.apply(meter_data_df) + assert actual_bill == expected_bill + + def test_multi_tou_weekday_tariff(self, series_data_df): + expected_bill = 17486.60175860 + meter_data_df = pandas.DataFrame([]) + meter_data_df['imported energy (kwh)'] = series_data_df['load_series_bimodal'] + with open('tariff_multi_tou_weekday.json') as f: + test_tariff = json_codec.load(f, Tariff) + actual_bill = test_tariff.apply(meter_data_df) + assert actual_bill == pytest.approx(expected_bill) + + + # def test_demand__block_tariff(self, demand_tariff, meter_data): + # expected_bill = 1.0 + # actual_bill = demand_tariff.apply(meter_data) + # assert actual_bill == expected_bill + + + # def test_scheduled_tariff(self, scheduled_tariff, series_data_df): + # expected_bill = 57106330.2 + # meter_data_df = pandas.DataFrame([]) + # meter_data_df['imported energy (kwh)'] = series_data_df['load_series_flat'] + # actual_bill = scheduled_tariff.apply(meter_data_df) + # assert actual_bill == expected_bill + # + # def test_seasonal_tariff(self, seasonal_tariff, meter_data): + # expected_bill = 1.0 + # actual_bill = seasonal_tariff.apply(meter_data) + # assert actual_bill == expected_bill + # + + # + # + # + # def test_supply_payment(self, supply_payment_tariff, meter_data): + # expected_bill = 1.0 + # actual_bill = supply_payment_tariff.apply(meter_data) + # assert actual_bill == expected_bill + # + def test_block_tariff(self, block_tariff, meter_data): expected_bill = 35040.0 actual_bill = block_tariff.apply(meter_data) @@ -223,3 +315,4 @@ def test_demand_tariff(self, demand_tariff, meter_data): expected_bill = 12.0 actual_bill = demand_tariff.apply(meter_data) assert actual_bill.cost == expected_bill +