|
| 1 | +"""Module for evaluating energy simulation data.""" |
| 2 | + |
| 3 | +import pandas as pd |
| 4 | + |
| 5 | +from .. import const |
| 6 | + |
| 7 | + |
| 8 | +def evaluate( |
| 9 | + data: pd.DataFrame, return_frequencies: list[str] | None = None |
| 10 | +) -> dict[str, pd.DataFrame]: |
| 11 | + """Evaluate the data and return resampled results. |
| 12 | +
|
| 13 | + Args: |
| 14 | + data: A pandas DataFrame containing time series data with columns: |
| 15 | + - electricity_delivered |
| 16 | + - electricity_exported |
| 17 | + - electricity_produced |
| 18 | + return_frequencies: List of pandas offset aliases for resampling frequencies. |
| 19 | + Defaults to ['MS'] (Month Start) if None. |
| 20 | +
|
| 21 | + Returns: |
| 22 | + A dictionary with keys as frequencies and values as resampled DataFrames. |
| 23 | + """ |
| 24 | + evaluator = Evaluator(data=data, return_frequencies=return_frequencies) |
| 25 | + return evaluator.evaluate() |
| 26 | + |
| 27 | + |
| 28 | +class Evaluator: |
| 29 | + """Evaluator for basic energy system evaluation.""" |
| 30 | + |
| 31 | + def __init__(self, data: pd.DataFrame, return_frequencies: list[str] | None = None): |
| 32 | + """Initialize the evaluator with data and return frequencies.""" |
| 33 | + self.data = data |
| 34 | + if return_frequencies is None: |
| 35 | + self.return_frequencies = ["MS"] # Month Start |
| 36 | + else: |
| 37 | + self.return_frequencies = return_frequencies |
| 38 | + |
| 39 | + def evaluate(self) -> dict[str, pd.DataFrame]: |
| 40 | + """Evaluate the data and return resampled results.""" |
| 41 | + # Add electricy_consumed |
| 42 | + self.data[const.ELECTRICITY_CONSUMED] = ( |
| 43 | + self.data[const.ELECTRICITY_DELIVERED] |
| 44 | + - self.data[const.ELECTRICITY_EXPORTED] |
| 45 | + + self.data[const.ELECTRICITY_PRODUCED] |
| 46 | + ) |
| 47 | + |
| 48 | + results = {} |
| 49 | + for freq in self.return_frequencies: |
| 50 | + resampled = ( |
| 51 | + self.data[ |
| 52 | + [ |
| 53 | + const.ELECTRICITY_DELIVERED, |
| 54 | + const.ELECTRICITY_EXPORTED, |
| 55 | + const.ELECTRICITY_PRODUCED, |
| 56 | + const.ELECTRICITY_CONSUMED, |
| 57 | + ] |
| 58 | + ] |
| 59 | + .resample(freq) |
| 60 | + .sum() |
| 61 | + ) |
| 62 | + results[freq] = resampled |
| 63 | + return results |
0 commit comments