From ac8e3a09cb224dc95393e478a5122cea2b07fae7 Mon Sep 17 00:00:00 2001 From: "marvin.steinke" Date: Mon, 19 Feb 2024 15:20:09 +0100 Subject: [PATCH 1/2] Removed `monitor()` Function --- vessim/controller.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/vessim/controller.py b/vessim/controller.py index c3be748..edf541a 100644 --- a/vessim/controller.py +++ b/vessim/controller.py @@ -16,7 +16,6 @@ class Controller(ABC): - def __init__(self, step_size: Optional[int] = None): self.step_size = step_size @@ -81,9 +80,6 @@ def add_monitor_fn(self, fn: Callable[[float], dict[str, Any]]): self.custom_monitor_fns.append(fn) def step(self, time: int, p_delta: float, actor_infos: dict) -> None: - self.monitor(time, p_delta, actor_infos) - - def monitor(self, time: int, p_delta: float, actor_infos: dict) -> None: log_entry = dict( p_delta=p_delta, actor_infos=actor_infos, From d640b6209c13261945841b61656e7e604415812b Mon Sep 17 00:00:00 2001 From: "marvin.steinke" Date: Mon, 19 Feb 2024 15:36:48 +0100 Subject: [PATCH 2/2] Privatized Some Functions and Classes --- vessim/actor.py | 2 +- vessim/controller.py | 8 ++++---- vessim/cosim.py | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/vessim/actor.py b/vessim/actor.py index a18c10a..e26b3ea 100644 --- a/vessim/actor.py +++ b/vessim/actor.py @@ -97,7 +97,7 @@ def state(self, now: datetime) -> dict: } -class ActorSim(mosaik_api.Simulator): +class _ActorSim(mosaik_api.Simulator): META = { "type": "time-based", "models": { diff --git a/vessim/controller.py b/vessim/controller.py index c3be748..b142e34 100644 --- a/vessim/controller.py +++ b/vessim/controller.py @@ -94,22 +94,22 @@ def monitor(self, time: int, p_delta: float, actor_infos: dict) -> None: self.monitor_log[self.clock.to_datetime(time)] = log_entry def to_csv(self, out_path: str): - df = pd.DataFrame({k: flatten_dict(v) for k, v in self.monitor_log.items()}).T + df = pd.DataFrame({k: _flatten_dict(v) for k, v in self.monitor_log.items()}).T df.to_csv(out_path) -def flatten_dict(d: MutableMapping, parent_key: str = "") -> MutableMapping: +def _flatten_dict(d: MutableMapping, parent_key: str = "") -> MutableMapping: items: list[tuple[str, Any]] = [] for k, v in d.items(): new_key = parent_key + "." + k if parent_key else k if isinstance(v, MutableMapping): - items.extend(flatten_dict(v, str(new_key)).items()) + items.extend(_flatten_dict(v, str(new_key)).items()) else: items.append((new_key, v)) return dict(items) -class ControllerSim(mosaik_api.Simulator): +class _ControllerSim(mosaik_api.Simulator): META = { "type": "time-based", "models": { diff --git a/vessim/cosim.py b/vessim/cosim.py index 86ca9fc..958f641 100644 --- a/vessim/cosim.py +++ b/vessim/cosim.py @@ -74,12 +74,12 @@ def finalize(self): class Environment: COSIM_CONFIG = { "Actor": { - "python": "vessim.actor:ActorSim", + "python": "vessim.actor:_ActorSim", }, "Controller": { - "python": "vessim.controller:ControllerSim", + "python": "vessim.controller:_ControllerSim", }, - "Grid": {"python": "vessim.cosim:GridSim"}, + "Grid": {"python": "vessim.cosim:_GridSim"}, } def __init__(self, sim_start): @@ -128,7 +128,7 @@ def run( raise -class GridSim(mosaik_api.Simulator): +class _GridSim(mosaik_api.Simulator): META = { "type": "time-based", "models": {