Skip to content

Commit 8435dc1

Browse files
committed
Adds support for fixed fees charged per billing period
1 parent d5897ba commit 8435dc1

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

tariffs/tariff.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ def charge_types(self):
221221
charge_types.add('consumption')
222222
if charge.type == 'generation':
223223
charge_types.add('generation')
224+
if charge.type == 'fixed':
225+
charge_types.add('fixed')
224226

225227
return list(charge_types)
226228

@@ -350,6 +352,12 @@ def apply(self, meter_data, start=None, end=None):
350352
peak_monthly = demand_data.resample(PERIOD_TO_TIMESTEP[self.billing_period]).max()
351353
cost_items.update(self.apply_by_charge_type(peak_monthly, cost_items, 'demand'))
352354

355+
if 'fixed' in self.charge_types:
356+
billing_periods = len(meter_data.resample(PERIOD_TO_TIMESTEP[self.billing_period]).mean())
357+
for charge in self.charges:
358+
if charge.type == 'fixed':
359+
cost_items[charge.name]['cost'] = billing_periods * charge.rate
360+
353361
# Transform the output data into the specified output format
354362
cost_dict = {
355363
'name': self.name,

tests/test_calculations.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ def tariff_file(self):
2323
tariff = json_codec.load(f, Tariff)
2424
return tariff
2525

26+
@pytest.fixture
27+
def fixed_tariff(self):
28+
with open('./fixtures/fixed_tariff.json') as f:
29+
tariff = json_codec.load(f, Tariff)
30+
return tariff
31+
2632
@pytest.fixture
2733
def block_tariff(self):
2834
with open('./fixtures/block_tariff.json') as f:
@@ -59,6 +65,11 @@ def demand_tariff(self):
5965
tariff = json_codec.load(f, Tariff)
6066
return tariff
6167

68+
def test_fixed_tariff(self, fixed_tariff, meter_data):
69+
expected_bill = 12.0
70+
actual_bill = fixed_tariff.apply(meter_data)
71+
assert actual_bill.cost == expected_bill
72+
6273
def test_block_tariff(self, block_tariff, meter_data):
6374
expected_bill = 35040.0
6475
actual_bill = block_tariff.apply(meter_data)

0 commit comments

Comments
 (0)