Completed
Push — appveyor ( 280314...2c0e2c )
by Konstantinos
02:09
created

so_magic.data.data_manager.DataManager.phis()   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
from enum import Enum
2
import attr
3
from so_magic.utils import GenericMediator, BaseComponent, ObjectRegistry, Observer
4
from .commands_manager import CommandsManager
5
6
7
class MediatorEvent(Enum):
8
    A = 'A'
9
    B = 'B'
10
    C = 'C'
11
12
13
class DataMediator(GenericMediator):
14
    def __init__(self, *args, **kwargs):
15
        self.events = kwargs.get('events', {})
16
17
    def notify(self, sender: object, event: str) -> None:
18
        pass
19
20
21
class Phis(ObjectRegistry, Observer):
22
    def __getattr__(self, item):
23
        return self.objects[item]
24
    def update(self, subject):
25
        self.add(subject.name, subject.state)
26
27
28
@attr.s
29
class DataManager:
30
    backend = attr.ib(init=True)
31
    _phi_function_class = attr.ib(init=True)
32
    feature_manager = attr.ib(init=True)
33
34
    commands_manager = attr.ib(init=True, default=CommandsManager())
35
    mediator = attr.ib(init=False, default=attr.Factory(lambda self: DataMediator(self.commands_manager, self.backend), takes_self=True))
36
    built_phis = attr.ib(init=False, default=Phis())
37
38
    def __attrs_post_init__(self):
39
        self.backend.datapoints_factory.subject.attach(self.backend.datapoints_manager)
40
        self.backend.engine.command_factory.attach(self.commands_manager.command.accumulator)
41
        self._phi_function_class.subject.attach(self.built_phis)
42
43
    @property
44
    def phis(self):
45
        return self.built_phis
46
47
    @property
48
    def phi_class(self):
49
        return self._phi_function_class
50
51
    @property
52
    def commands(self):
53
        return self.commands_manager.commands_dict
54
55
    @property
56
    def command(self):
57
        return self.commands_manager.command
58
59
    @property
60
    def datapoints(self):
61
        return self.backend.datapoints_manager.datapoints
62