Passed
Push — release-staging ( f66c6e...bcf37a )
by Konstantinos
01:35
created

so_magic.data.data_manager.DataMediator.notify()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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