Skip to content

Commit

Permalink
Resolution steps
Browse files Browse the repository at this point in the history
  • Loading branch information
Juliette-Gerbaux committed Jul 4, 2024
1 parent 585fc50 commit ec850d8
Show file tree
Hide file tree
Showing 8 changed files with 574 additions and 446 deletions.
33 changes: 19 additions & 14 deletions src/andromede/study/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class AbstractDataStructure(ABC):
def get_value(self, timestep: int, scenario: int) -> float:
return NotImplemented

def get_max_value(self) -> float:
return NotImplemented

@abstractmethod
def check_requirement(self, time: bool, scenario: bool) -> bool:
"""
Expand All @@ -57,6 +60,9 @@ class ConstantData(AbstractDataStructure):
def get_value(self, timestep: int, scenario: int) -> float:
return self.value

def get_max_value(self) -> float:
return self.value

# ConstantData can be used for time varying or constant models
def check_requirement(self, time: bool, scenario: bool) -> bool:
if not isinstance(self, ConstantData):
Expand All @@ -77,6 +83,9 @@ class TimeSeriesData(AbstractDataStructure):
def get_value(self, timestep: int, scenario: int) -> float:
return self.time_series[TimeIndex(timestep)]

def get_max_value(self) -> float:
return max(self.time_series.values())

def check_requirement(self, time: bool, scenario: bool) -> bool:
if not isinstance(self, TimeSeriesData):
raise ValueError("Invalid data type for TimeSeriesData")
Expand All @@ -97,6 +106,9 @@ class ScenarioSeriesData(AbstractDataStructure):
def get_value(self, timestep: int, scenario: int) -> float:
return self.scenario_series[ScenarioIndex(scenario)]

def get_max_value(self) -> float:
return max(self.scenario_series.values())

def check_requirement(self, time: bool, scenario: bool) -> bool:
if not isinstance(self, ScenarioSeriesData):
raise ValueError("Invalid data type for TimeSeriesData")
Expand All @@ -116,19 +128,6 @@ def load_ts_from_txt(
raise Exception(f"An error has arrived when processing '{ts_path}'")


def filter_ts_on_scenarios_and_timesteps(
raw_ts: pd.DataFrame,
scenarios: Optional[List[int]],
timesteps: Optional[List[int]],
) -> pd.DataFrame:
filtered_ts = raw_ts
if scenarios is not None:
filtered_ts = filtered_ts.filter(items=scenarios, axis=1)
if timesteps is not None:
filtered_ts = filtered_ts.filter(items=timesteps, axis=0)
return filtered_ts.reset_index(drop=True)


@dataclass(frozen=True)
class TimeScenarioSeriesData(AbstractDataStructure):
"""
Expand All @@ -144,7 +143,13 @@ def get_value(self, timestep: int, scenario: int) -> float:
value = str(self.time_scenario_series.loc[[timestep]].iloc[0, 0])
return float(value)
value = str(self.time_scenario_series.loc[timestep, scenario])
return float(value)
try:
return float(value)
except ValueError:
return float(list(self.time_scenario_series.loc[timestep, scenario])[0])

def get_max_value(self) -> float:
return self.time_scenario_series.values.max()

def check_requirement(self, time: bool, scenario: bool) -> bool:
if not isinstance(self, TimeScenarioSeriesData):
Expand Down
1 change: 0 additions & 1 deletion src/andromede/study/resolve_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
AbstractDataStructure,
TimeScenarioIndex,
TimeScenarioSeriesData,
filter_ts_on_scenarios_and_timesteps,
load_ts_from_txt,
)
from andromede.study.parsing import (
Expand Down
4 changes: 1 addition & 3 deletions src/andromede/thermal_heuristic/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ def __init__(
scenario, dir_path, week
)

def check_output_values(self, problem: OptimizationProblem) -> None:
output = OutputValues(problem)

def check_output_values(self, output: OutputValues) -> None:
for i, cluster in enumerate(self.list_cluster):
self.check_output_cluster(
output,
Expand Down
Loading

0 comments on commit ec850d8

Please sign in to comment.