Skip to content

Commit

Permalink
Merge branch 'main' of github.com:dos-group/vessim
Browse files Browse the repository at this point in the history
  • Loading branch information
birnbaum committed Feb 20, 2024
2 parents 6519942 + a423ddd commit b9c4690
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion vessim/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def state(self, now: datetime) -> dict:
}


class ActorSim(mosaik_api.Simulator):
class _ActorSim(mosaik_api.Simulator):
META = {
"type": "time-based",
"models": {
Expand Down
12 changes: 4 additions & 8 deletions vessim/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@


class Controller(ABC):

def __init__(self, step_size: Optional[int] = None):
self.step_size = step_size

Expand Down Expand Up @@ -77,9 +76,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,
Expand All @@ -90,22 +86,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": {
Expand Down
8 changes: 4 additions & 4 deletions vessim/cosim.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -128,7 +128,7 @@ def run(
raise


class GridSim(mosaik_api.Simulator):
class _GridSim(mosaik_api.Simulator):
META = {
"type": "time-based",
"models": {
Expand Down

0 comments on commit b9c4690

Please sign in to comment.