Passed
Push — dev ( 6a1e3c...3c73d5 )
by Konstantinos
01:31
created

green_magic.data.features.feature_factory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 21
dl 0
loc 30
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A AbstractFeatureFactory.get_feature() 0 3 1
A FeatureFactory.register_as_subclass() 0 7 1
A FeatureFactory.create() 0 5 2
A FeatureFactory.get_feature() 0 2 1
1
from abc import ABC, abstractmethod
2
3
from data.features.features import TrackingFeature
4
5
6
class AbstractFeatureFactory(ABC):
7
    @abstractmethod
8
    def get_feature(self, *args, **kwargs) -> TrackingFeature:
9
        raise NotImplementedError
10
11
12
class FeatureFactory(AbstractFeatureFactory):
13
14
    @classmethod
15
    def register_as_subclass(cls, backend_type):
16
        def wrapper(subclass):
17
            cls.subclasses[backend_type] = subclass
18
            return subclass
19
20
        return wrapper
21
22
    @classmethod
23
    def create(cls, backend_type, *args, **kwargs):
24
        if backend_type not in cls.subclasses:
25
            raise ValueError('Bad "BinnerFactory Backend type" type \'{}\''.format(backend_type))
26
        return cls.subclasses[backend_type](*args, **kwargs)
27
28
    def get_feature(self, *args, **kwargs) -> TrackingFeature:
29
        raise NotImplementedError
30