Skip to content

Commit

Permalink
fix writing actual disptach in time
Browse files Browse the repository at this point in the history
  • Loading branch information
maurerle committed Sep 29, 2023
1 parent b6e1e9c commit 3a32766
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 15 deletions.
4 changes: 1 addition & 3 deletions assume/common/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,7 @@ def execute_current_dispatch(
:return: the volume of the unit within the given time range
:rtype: pd.Series
"""
end_excl = end - self.index.freq
energy = self.outputs["energy"][start:end_excl]
return energy
return self.outputs["energy"][start:end]

def get_output_before(self, dt: datetime, product_type: str = "energy") -> float:
"""
Expand Down
4 changes: 2 additions & 2 deletions assume/common/units_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def write_actual_dispatch(self):
unit_dispatch_dfs = []
for unit_id, unit in self.units.items():
current_dispatch = unit.execute_current_dispatch(start, now)
end = now - unit.index.freq
end = now
current_dispatch.name = "power"
data = pd.DataFrame(current_dispatch)
data["soc"] = unit.outputs["soc"][start:end]
Expand All @@ -237,7 +237,7 @@ def write_actual_dispatch(self):
unit_dispatch_dfs.append(data)

self.valid_orders = list(
filter(lambda x: x["end_time"] >= now, self.valid_orders)
filter(lambda x: x["end_time"] > now, self.valid_orders)
)

db_aid = self.context.data_dict.get("output_agent_id")
Expand Down
3 changes: 1 addition & 2 deletions assume/units/demand.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ def execute_current_dispatch(
:return: the volume of the unit within the given time range
:rtype: pd.Series
"""
end_excl = end - self.index.freq
return self.volume[start:end_excl]
return self.volume[start:end]

def calculate_min_max_power(
self, start: pd.Timestamp, end: pd.Timestamp, product_type="energy"
Expand Down
8 changes: 3 additions & 5 deletions assume/units/powerplant.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,11 @@ def execute_current_dispatch(
:rtype: float
"""

end_excl = end - self.index.freq

max_power = (
self.forecaster.get_availability(self.id)[start:end_excl] * self.max_power
self.forecaster.get_availability(self.id)[start:end] * self.max_power
)

for t in self.outputs["energy"][start:end_excl].index:
for t in self.outputs["energy"][start:end].index:
current_power = self.outputs["energy"][t]
previous_power = self.get_output_before(t)

Expand All @@ -179,7 +177,7 @@ def execute_current_dispatch(
elif current_power < min_power_t and current_power > 0:
self.outputs["energy"][t] = 0

return self.outputs["energy"].loc[start:end_excl]
return self.outputs["energy"].loc[start:end]

def calc_simple_marginal_cost(
self,
Expand Down
5 changes: 2 additions & 3 deletions assume/units/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,9 @@ def execute_current_dispatch(self, start: pd.Timestamp, end: pd.Timestamp):
:return: The dispatched energy in MWh.
:rtype: pd.Series
"""
end_excl = end - self.index.freq
time_delta = self.index.freq / timedelta(hours=1)

for t in self.outputs["energy"][start:end_excl].index:
for t in self.outputs["energy"][start:end].index:
delta_soc = 0
soc = self.outputs["soc"][t]
if self.outputs["energy"][t] > self.max_power_discharge:
Expand Down Expand Up @@ -247,7 +246,7 @@ def execute_current_dispatch(self, start: pd.Timestamp, end: pd.Timestamp):

self.outputs["soc"][t + self.index.freq :] = soc + delta_soc

return self.outputs["energy"].loc[start:end_excl]
return self.outputs["energy"].loc[start:end]

@lru_cache(maxsize=256)
def calculate_marginal_cost(
Expand Down

0 comments on commit 3a32766

Please sign in to comment.