Skip to content

Adding congestion result. #302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
## Unreleased

### Added
- Congestion result [#198](https://github.com/ie3-institute/pypsdm/issues/198)

### Changed
- Adapt Coordinate type to use WKBElement Geography [#287](https://github.com/ie3-institute/pypsdm/issues/287)
Expand Down
7 changes: 7 additions & 0 deletions pypsdm/models/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def get_plot_name(self):
def get_result_type(self) -> type[TimeSeries]:
# locally to avoid circular imports
from pypsdm import FlexOption
from pypsdm.models.result.grid.congestions import CongestionResult
from pypsdm.models.result.grid.connector import ConnectorCurrent
from pypsdm.models.result.grid.switch import SwitchResult
from pypsdm.models.result.grid.transformer import Transformer2WResult
Expand All @@ -66,6 +67,8 @@ def get_result_type(self) -> type[TimeSeries]:
return ConnectorCurrent
case RawGridElementsEnum.SWITCH:
return SwitchResult
case RawGridElementsEnum.CONGESTION:
return CongestionResult
case _:
raise NotImplementedError(
f"Result type {self} not implemented yet!"
Expand All @@ -74,6 +77,7 @@ def get_result_type(self) -> type[TimeSeries]:
raise ValueError(f"Entity type {self} not supported!")

def get_result_dict_type(self) -> Type["EntitiesResultDictMixin"]:
from pypsdm.models.result.grid.congestions import CongestionsResult
from pypsdm.models.result.grid.line import LinesResult
from pypsdm.models.result.grid.node import NodesResult
from pypsdm.models.result.grid.switch import SwitchesResult
Expand All @@ -100,6 +104,8 @@ def get_result_dict_type(self) -> Type["EntitiesResultDictMixin"]:
return Transformers2WResult
case RawGridElementsEnum.SWITCH:
return SwitchesResult
case RawGridElementsEnum.CONGESTION:
return CongestionsResult
case SystemParticipantsEnum.ELECTRIC_VEHICLE:
return EvsResult
case SystemParticipantsEnum.EV_CHARGING_STATION:
Expand Down Expand Up @@ -161,6 +167,7 @@ class RawGridElementsEnum(EntitiesEnum):
TRANSFROMER_3_W = "transformer_3_w"
SWITCH = "switch"
MEASUREMENT_UNIT = "measurement_unit"
CONGESTION = "congestion"


class ThermalGridElementsEnum(EntitiesEnum):
Expand Down
4 changes: 4 additions & 0 deletions pypsdm/models/gwr.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ def transformers_2_w_res(self):
def switches_res(self):
return self.raw_grid_res.switches

@property
def congestions_res(self):
return self.results.raw_grid.congestions

@property
def participants_res(self):
return self.results.participants
Expand Down
4 changes: 4 additions & 0 deletions pypsdm/models/result/container/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ def transformers_2w(self):
def switches(self):
return self.raw_grid.switches

@property
def congestions(self):
return self.raw_grid.congestions

@property
def ems(self):
return self.participants.ems
Expand Down
6 changes: 6 additions & 0 deletions pypsdm/models/result/container/raw_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from pypsdm.models.result.grid.node import NodesResult
from pypsdm.models.result.grid.switch import SwitchesResult
from pypsdm.models.result.grid.transformer import Transformers2WResult
from pypsdm.models.result.grid.congestions import CongestionsResult
from pypsdm.models.ts.base import EntityKey


Expand All @@ -19,6 +20,7 @@ class RawGridResultContainer(ResultContainerMixin):
lines: LinesResult
transformers_2w: Transformers2WResult
switches: SwitchesResult
congestions: CongestionsResult

def __init__(self, dct):
def get_or_empty(key: RawGridElementsEnum, dict_type):
Expand All @@ -37,6 +39,9 @@ def get_or_empty(key: RawGridElementsEnum, dict_type):
RawGridElementsEnum.TRANSFORMER_2_W, Transformers2WResult
)
self.switches = get_or_empty(RawGridElementsEnum.SWITCH, SwitchesResult)
self.congestions = get_or_empty(
RawGridElementsEnum.CONGESTION, CongestionsResult
)

def __len__(self):
return sum(len(v) for v in self.to_dict().values())
Expand All @@ -55,6 +60,7 @@ def to_dict(self, include_empty: bool = False) -> dict:
RawGridElementsEnum.LINE: self.lines,
RawGridElementsEnum.TRANSFORMER_2_W: self.transformers_2w,
RawGridElementsEnum.SWITCH: self.switches,
RawGridElementsEnum.CONGESTION: self.congestions,
}
if not include_empty:
res = {k: v for k, v in res.items() if v}
Expand Down
2 changes: 2 additions & 0 deletions pypsdm/models/result/grid/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from .congestions import CongestionResult
from .connector import ConnectorCurrent, ConnectorCurrentDict
from .line import LinesResult
from .node import NodesResult
from .switch import SwitchesResult, SwitchResult
from .transformer import Transformer2WResult, Transformers2WResult

__all__ = [
"CongestionResult",
"ConnectorCurrent",
"ConnectorCurrentDict",
"NodesResult",
Expand Down
98 changes: 98 additions & 0 deletions pypsdm/models/result/grid/congestions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
from dataclasses import dataclass
from datetime import datetime
from enum import Enum

from pandas import DataFrame

from pypsdm.models.result.participant.dict import EntitiesResultDictMixin
from pypsdm.models.enums import RawGridElementsEnum
from pypsdm.models.ts.base import (
EntityKey,
TimeSeries,
TimeSeriesDict,
TimeSeriesDictMixin,
)


class InputModelType(Enum):
NODE = "node"
LINE = "line"
TRANSFORMER_2_W = "transformer_2w"
TRANSFORMER_3_W = "transformer_3w"


@dataclass
class CongestionResult(TimeSeries):
def __init__(self, data: DataFrame, end: datetime | None = None):
super().__init__(data, end)

def __eq__(self, other: object) -> bool:
return super().__eq__(other)

def __add__(self, _):
return NotImplemented

@property
def subgrid(self) -> int:
return self.data["subgrid"].drop_duplicates()[0]

@property
def input_model_type(self) -> InputModelType:
match self.data["type"].drop_duplicates()[0]:
case "node":
return InputModelType.NODE
case "line":
return InputModelType.LINE
case "transformer_2w":
return InputModelType.TRANSFORMER_2_W
case "transformer_3w":
return InputModelType.TRANSFORMER_3_W

@property
def value(self) -> float:
return self.data["value"].drop_duplicates()[0]

@property
def min(self) -> float:
return self.data["min"].drop_duplicates()[0]

@property
def max(self) -> float:
return self.data["max"].drop_duplicates()[0]

@staticmethod
def attributes() -> list[str]:
return ["subgrid", "type", "value", "min", "max"]


class CongestionsResult(
TimeSeriesDict[EntityKey, CongestionResult],
TimeSeriesDictMixin,
EntitiesResultDictMixin,
):
def __eq__(self, other: object) -> bool:
return super().__eq__(other)

@property
def subgrid(self) -> DataFrame:
return self.attr_df("subgrid")

@property
def type(self) -> DataFrame:
return self.attr_df("type")

@property
def value(self) -> DataFrame:
return self.attr_df("value")

@property
def min(self) -> DataFrame:
return self.attr_df("min")

@property
def max(self) -> DataFrame:
return self.attr_df("max")

@classmethod
def entity_type(cls) -> RawGridElementsEnum:
return RawGridElementsEnum.CONGESTION
Loading