MCPcopy Create free account
hub / github.com/ahalev/python-microgrid / Container

Class Container

src/pymgrid/modules/module_container.py:11–337  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9
10
11class Container(UserDict):
12 def __init__(self, *args, **kwargs):
13 super().__init__(*args, **kwargs)
14 self.dir_additions = self.dir_additions()
15
16 @property
17 def containers(self):
18 """
19 View of this container's containers.
20
21 Returns
22 -------
23 containers : dict-like
24 View of containers.
25 """
26 return self
27
28 def to_list(self):
29 """
30 Get the modules as a list.
31
32 Returns
33 -------
34 l : list of modules
35 List of modules
36
37 """
38 l = []
39 for _, raw_container in self.containers.items():
40 l.extend(raw_container.to_list())
41 return l
42
43 def to_dict(self, orient='list'):
44 """
45 Get the modules as a dictionary.
46
47 Returns
48 -------
49 d : dict[str, list[module]]
50 Dictionary with module names as keys, modules as values.
51
52 """
53
54 def _dict_update_vals(raw_container):
55 if orient == 'list':
56 return raw_container
57 elif orient == 'records':
58 return {(name, n): module for name, mod_list in raw_container.items() for n, module in
59 enumerate(mod_list)}
60
61 def _list_update_vals(key, raw_container):
62 if orient == 'list':
63 return {key: raw_container}
64 elif orient == 'records':
65 return {(key, n): module for n, module in enumerate(raw_container)}
66
67 raise ValueError(f"Unrecognized orient '{orient}'")
68

Callers 2

_set_midlevelMethod · 0.85
get_subcontainersFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected