Skip to content

Commit

Permalink
[#31] Cost integration.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stéphane Senart committed Feb 3, 2025
1 parent 650c4d0 commit 42d2857
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions gazpar2haws/gazpar.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ async def publish(self):
last_date_and_value_by_sensor[cost_sensor_name] = await self.find_last_date_and_value(cost_sensor_name)

# Compute the start date as the minimum of the last dates plus one day
start_date = min(v[0] for v in last_date_and_value_by_sensor.values()) + timedelta(days=1)
start_date = min(
min(v[0] for v in last_date_and_value_by_sensor.values()) + timedelta(days=1), self._as_of_date
)

# The end date is the as of date
end_date = self._as_of_date
Expand Down Expand Up @@ -150,18 +152,17 @@ async def publish(self):
return

# Compute the cost from the energy
quantities = ConsumptionQuantityArray(
start_date=last_date_and_value_by_sensor[energy_sensor_name][0],
end_date=end_date,
value_unit=QuantityUnit.KWH,
base_unit=TimeUnit.DAY,
value_array=energy_array,
)

# Compute the cost
if energy_array is not None:
pricer = Pricer(self._pricing_config)

quantities = ConsumptionQuantityArray(
start_date=last_date_and_value_by_sensor[energy_sensor_name][0],
end_date=end_date,
value_unit=QuantityUnit.KWH,
base_unit=TimeUnit.DAY,
value_array=energy_array,
)

cost_array = pricer.compute(quantities, PriceUnit.EURO)
else:
cost_array = None
Expand Down

0 comments on commit 42d2857

Please sign in to comment.