Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions enerdata/profiles/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
class Dragger(Counter):

def drag(self, number, key='default'):
if key == 'disabled':
return number
if number == 0 and abs(self[key]) == Decimal('0.5'):
# Avoid oscillation between -1 and 1 and dragging 0.5 and -0.5
return number
Expand Down
6 changes: 3 additions & 3 deletions enerdata/profiles/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ def profile(self, tariff, measures, drag_method='hour'):
dragger = Dragger()
for hour, cof in self.coefficient.get_range(start, end):
period = tariff.get_period_by_date(hour)
if drag_method == 'hour':
dp = 'hour'
else:
if drag_method == 'period':
dp = period.code
else:
dp = drag_method
d = hour.date()
if hour.hour == 0:
d -= timedelta(days=1)
Expand Down
5 changes: 5 additions & 0 deletions spec/profiles/dragger_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
expect(aprox).to(be(6))
expect(d['key2']).to(equal(Decimal('-0.5')))

with it('has a special key "disabled" which returns the number'):
d = Dragger()
aprox = d.drag(1.123456789, key='disabled')
expect(aprox).to(equal(1.123456789))


with context('Has to use the drag of antecesor drag'):

Expand Down
38 changes: 38 additions & 0 deletions spec/profiles/profile_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,44 @@ def get_range_error():
consum = sum([i[1]['aprox'] for i in prof])
expect(consum).to(equal(103 + 22 + 130 + 20))

with it('the total energy must be the sum of the profiled energy disabling drag'):
c = Coefficients(REEProfile.get(2014, 10))
profiler = Profiler(c)
measures = [
EnergyMeasure(
date(2014, 9, 30),
TariffPeriod('P1', 'te'), 307, consumption=145
),
EnergyMeasure(
date(2014, 9, 30),
TariffPeriod('P2', 'te'), 108, consumption=10
),
EnergyMeasure(
date(2014, 10, 15),
TariffPeriod('P1', 'te'), 410, consumption=103
),
EnergyMeasure(
date(2014, 10, 15),
TariffPeriod('P2', 'te'), 130, consumption=22
),
EnergyMeasure(
date(2014, 10, 31),
TariffPeriod('P1', 'te'), 540, consumption=130
),
EnergyMeasure(
date(2014, 10, 31),
TariffPeriod('P2', 'te'), 150, consumption=20
)
]
t = T20DHA()
t.cof = 'A'
prof = list(profiler.profile(t, measures, drag_method='disabled'))
expect(len(prof)).to(equal((31 * 24) + 1))
for i in prof:
expect(i[1]['aprox']).to(be_a(float))
consum = sum([i[1]['aprox'] for i in prof])
expect(round(consum, 12)).to(equal(103 + 22 + 130 + 20))


with it('should be the same per period if drag per period is used'):
c = Coefficients()
Expand Down