1
|
|
|
import attr |
2
|
|
|
from so_magic.utils import ObjectRegistry, Observer |
3
|
|
|
from .commands_manager import CommandsManager |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
@attr.s |
7
|
|
|
class Phis(Observer): |
8
|
|
|
registry: ObjectRegistry = attr.ib(default=attr.Factory(ObjectRegistry)) |
9
|
|
|
|
10
|
|
|
def __getattr__(self, item): |
11
|
|
|
return getattr(self.registry, item) |
12
|
|
|
|
13
|
|
|
def __contains__(self, item): |
14
|
|
|
return item in self.registry |
15
|
|
|
|
16
|
|
|
def update(self, subject, *args, **kwargs): |
17
|
|
|
self.registry.add(subject.name, subject.state) |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
@attr.s |
21
|
|
|
class DataManager: |
22
|
|
|
engine = attr.ib(init=True) |
23
|
|
|
_phi_function_class = attr.ib(init=True) |
24
|
|
|
feature_manager = attr.ib(init=True) |
25
|
|
|
|
26
|
|
|
commands_manager = attr.ib(init=True, default=CommandsManager()) |
27
|
|
|
# mediator = attr.ib(init=False, default=attr.Factory( |
28
|
|
|
# lambda self: DataMediator(self.commands_manager, self.backend), takes_self=True)) |
29
|
|
|
built_phis = attr.ib(init=False, default=Phis()) |
30
|
|
|
|
31
|
|
|
def __attrs_post_init__(self): |
32
|
|
|
self.engine.backend.datapoints_factory.subject.attach(self.engine.datapoints_manager) |
33
|
|
|
self.engine.backend.command_factory.subject.attach(self.commands_manager.command.accumulator) |
34
|
|
|
self._phi_function_class.subject.attach(self.built_phis) |
35
|
|
|
|
36
|
|
|
@property |
37
|
|
|
def phis(self): |
38
|
|
|
return self.built_phis |
39
|
|
|
|
40
|
|
|
@property |
41
|
|
|
def phi_class(self): |
42
|
|
|
return self._phi_function_class |
43
|
|
|
|
44
|
|
|
@property |
45
|
|
|
def commands(self): |
46
|
|
|
return self.commands_manager.commands_dict |
47
|
|
|
|
48
|
|
|
@property |
49
|
|
|
def command(self): |
50
|
|
|
return self.commands_manager.command |
51
|
|
|
|
52
|
|
|
@property |
53
|
|
|
def datapoints(self): |
54
|
|
|
return self.engine.datapoints_manager.datapoints |
55
|
|
|
|