Passed
Push — dev ( a34975...3b058b )
by Konstantinos
01:33
created

green_magic.som.factory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 18
dl 0
loc 23
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A SelfOrganizingMapFactory.create() 0 9 2
1
import attr
2
from green_magic.utils import Subject
3
from .self_organising_map import SomTrainer, SelfOrganizingMap
4
5
6
@attr.s
7
class SelfOrganizingMapFactory:
8
    trainer = attr.ib(init=True, default=SomTrainer())
9
    subject = attr.ib(init=True, default=Subject([]))
10
11
    def create(self, dataset, nb_cols, nb_rows, **kwargs):
12
        try:
13
            map_obj = self.trainer.infer_map(nb_cols, nb_rows, dataset, **kwargs)  # backend dependent (eg somoclu kind of object)
14
            self.subject.state = map_obj
15
            self.subject.notify()
16
            return SelfOrganizingMap(map_obj, dataset.name)
17
        except NoFeatureVectorsError as e:
18
            logger.info(f"{e}. Fire up an 'encode' command.")
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable logger does not seem to be defined.
Loading history...
19
            raise e
20
21
22
class NoFeatureVectorsError(Exception): pass
23