Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dragging key assignation to review #87

Closed
XaviTorello opened this issue Jan 31, 2018 · 0 comments
Closed

Dragging key assignation to review #87

XaviTorello opened this issue Jan 31, 2018 · 0 comments

Comments

@XaviTorello
Copy link
Contributor

XaviTorello commented Jan 31, 2018

There is something to review here, probably I've a misunderstanding about the dragging process but can it be a bug.

It seems like the drag_key is defined based on the period of the previous gap iteration (the last gap period for the first iteration).

Could it be that the correct period key to define is the one of the current iteration?

The affected method [suspect line 375]:

def estimate(self, tariff, balance):
assert isinstance(tariff, Tariff)
logger.debug('Estimating for tariff: {0}'.format(
tariff.code
))
measures = [x for x in self.measures if x.valid]
start = self.start_date
end = self.end_date
cofs = self.profile_class.get_range(start, end)
cofs = Coefficients(cofs)
cofs_per_period = Counter()
for gap in self.gaps:
period = tariff.get_period_by_date(gap)
gap_cof = cofs.get(gap)
cofs_per_period[period.code] += gap_cof.cof[tariff.cof]
logger.debug('Coefficients per period calculated: {0}'.format(
cofs_per_period
))
energy_per_period = self.get_estimable_consumption(tariff, balance)
energy_per_period_rem = energy_per_period.copy()
dragger = Dragger()
for idx, gap in enumerate(self.gaps):
logger.debug('Gap {0}/{1}'.format(
idx + 1, len(self.gaps)
))
drag_key = period.code
period = tariff.get_period_by_date(gap)
gap_cof = cofs.get(gap).cof[tariff.cof]
energy = energy_per_period[period.code]
# If the balance[period] < energy_profile[period] fill with 0
# the gaps
if energy < 0:
energy = 0
gap_energy = (energy * gap_cof) / cofs_per_period[period.code]
aprox = dragger.drag(gap_energy, key=drag_key)
energy_per_period_rem[period.code] -= gap_energy
logger.debug(
'Energy for hour {0} is {1}. {2} Energy {3}/{4}'.format(
gap, aprox, period.code,
energy_per_period_rem[period.code], energy
))
pos = bisect.bisect_left(measures, ProfileHour(gap, 0, True))
profile_hour = ProfileHour(TIMEZONE.normalize(gap), aprox, True)
measures.insert(pos, profile_hour)
profile = Profile(self.start_date, self.end_date, measures)
return profile

Proposal solution:
Assign drag_key before period assignation (to exchange lines 375 and 376)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

3 participants