| Total Complexity | 15 |
| Total Lines | 58 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import attr |
||
| 2 | |||
| 3 | from green_magic.data.variables.types import NominalVariableType |
||
| 4 | from green_magic.data.features.features import TrackingFeature |
||
| 5 | |||
| 6 | |||
| 7 | @attr.s |
||
| 8 | class BaseFeatureSet: |
||
| 9 | features = attr.ib(init=True, default=[]) |
||
| 10 | |||
| 11 | def __len__(self): |
||
| 12 | return len(self.features) |
||
| 13 | |||
| 14 | def __getitem__(self, item): |
||
| 15 | return self.features[item] |
||
| 16 | |||
| 17 | def __iter__(self): |
||
| 18 | return iter(self.features) |
||
| 19 | |||
| 20 | @classmethod |
||
| 21 | def from_raw_extractors(cls, data): |
||
| 22 | """Create a Feature for each of the lists in the input data (list). Inner lists must satisfy 0 < len(l)""" |
||
| 23 | return [TrackingFeature.from_callable(*args) for args in data] |
||
| 24 | |||
| 25 | |||
| 26 | class FeatureSet(BaseFeatureSet): |
||
| 27 | |||
| 28 | @property |
||
| 29 | def encoded(self): |
||
| 30 | for feature in self.features: |
||
| 31 | if str(feature.state) == 'encoded': |
||
| 32 | yield feature |
||
| 33 | |||
| 34 | @property |
||
| 35 | def not_encoded(self): |
||
| 36 | for feature in self.features: |
||
| 37 | if str(feature.state) != 'encoded': |
||
| 38 | yield feature |
||
| 39 | |||
| 40 | @property |
||
| 41 | def binnable(self): |
||
| 42 | for feature in self.features: |
||
| 43 | if not isinstance(feature.var_type, NominalVariableType): |
||
| 44 | yield feature |
||
| 45 | |||
| 46 | |||
| 47 | @attr.s |
||
| 48 | class FeatureManager: |
||
| 49 | _feature_configuration = attr.ib(init=True) |
||
| 50 | |||
| 51 | @property |
||
| 52 | def feature_configuration(self): |
||
| 53 | return self._feature_configuration |
||
| 54 | |||
| 55 | @feature_configuration.setter |
||
| 56 | def feature_configuration(self, feature_configuration): |
||
| 57 | self._feature_configuration = feature_configuration |
||
| 58 |