Skip to content

Commit

Permalink
Simplify get_value out of database
Browse files Browse the repository at this point in the history
  • Loading branch information
Juliette-Gerbaux committed Jul 4, 2024
1 parent ec850d8 commit a3325e7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
10 changes: 2 additions & 8 deletions src/andromede/study/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,8 @@ class TimeScenarioSeriesData(AbstractDataStructure):
time_scenario_series: pd.DataFrame

def get_value(self, timestep: int, scenario: int) -> float:
if self.time_scenario_series.shape[1] == 1:
value = str(self.time_scenario_series.loc[[timestep]].iloc[0, 0])
return float(value)
value = str(self.time_scenario_series.loc[timestep, scenario])
try:
return float(value)
except ValueError:
return float(list(self.time_scenario_series.loc[timestep, scenario])[0])
value = str(self.time_scenario_series.iloc[timestep, scenario])
return float(value)

def get_max_value(self) -> float:
return self.time_scenario_series.values.max()
Expand Down
14 changes: 12 additions & 2 deletions src/andromede/thermal_heuristic/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,18 @@ def update_database_fast_before_heuristic(
"n_guide",
TimeSeriesData(
{
TimeIndex(i + week * self.number_hours): nb_on_1[i]
for i in range(self.number_hours)
TimeIndex(i): (
nb_on_1[i % self.number_hours]
if i
in list(
range(
week * self.number_hours,
(week + 1) * self.number_hours,
)
)
else 0
)
for i in range(self.number_hours * self.number_week)
}
),
)
Expand Down

0 comments on commit a3325e7

Please sign in to comment.