|
1 | 1 | """Module for evaluating energy simulation data.""" |
2 | 2 |
|
| 3 | +import typing |
| 4 | + |
3 | 5 | import numpy as np |
4 | 6 | import pandas as pd |
5 | 7 |
|
@@ -39,6 +41,8 @@ def __init__(self, data: pd.DataFrame, return_frequencies: list[str] | None = No |
39 | 41 |
|
40 | 42 | def evaluate(self) -> dict[str, pd.DataFrame | pd.Series]: |
41 | 43 | """Evaluate the data and return resampled results.""" |
| 44 | + if const.ELECTRICITY_DELIVERED not in self.data.columns: |
| 45 | + self.data[const.ELECTRICITY_DELIVERED] = float("NaN") |
42 | 46 | if const.ELECTRICITY_EXPORTED not in self.data.columns: |
43 | 47 | self.data[const.ELECTRICITY_EXPORTED] = float("NaN") |
44 | 48 | if const.ELECTRICITY_PRODUCED not in self.data.columns: |
@@ -122,3 +126,23 @@ def evaluate(self) -> dict[str, pd.DataFrame | pd.Series]: |
122 | 126 | frame[const.ELECTRICITY_CONSUMED], |
123 | 127 | ) |
124 | 128 | return results |
| 129 | + |
| 130 | + |
| 131 | +def compare_results( |
| 132 | + res_1: dict[str, pd.DataFrame | pd.Series], res_2: dict[str, pd.DataFrame | pd.Series] |
| 133 | +) -> dict[str, dict[str, pd.Series | pd.DataFrame]]: |
| 134 | + """Compare two evaluation results and return the differences.""" |
| 135 | + results = {} |
| 136 | + for key in res_1.keys(): |
| 137 | + if key in res_2: |
| 138 | + df_1 = res_1[key] |
| 139 | + df_2 = res_2[key] |
| 140 | + if isinstance(df_1, pd.Series) and isinstance(df_2, pd.Series): |
| 141 | + df_1 = df_1.to_frame().T |
| 142 | + df_2 = df_2.to_frame().T |
| 143 | + df_1, df_2 = typing.cast(pd.DataFrame, df_1), typing.cast(pd.DataFrame, df_2) |
| 144 | + diff = df_2 - df_1 |
| 145 | + results[key] = {} |
| 146 | + results[key]["diff"] = diff.dropna(how="all", axis=1).squeeze(axis=0) |
| 147 | + results[key]["ratio_diff"] = (diff / df_1).dropna(how="all", axis=1).squeeze(axis=0) |
| 148 | + return results |
0 commit comments