Browse Source

KeyError 45058 #389 (#397)

* fix general

* test

* minor fix

* fix test

* minor fix
pull/1/head
Alexandr Velikiy 6 years ago committed by Alexey Velikiy
parent
commit
775c663de5
  1. 1
      analytics/analytics/models/general_model.py
  2. 13
      analytics/tests/test_dataset.py

1
analytics/analytics/models/general_model.py

@ -66,6 +66,7 @@ class GeneralModel(Model):
if pat_data.count(0) == len(pat_data): if pat_data.count(0) == len(pat_data):
raise ValueError('Labeled patterns must not be empty') raise ValueError('Labeled patterns must not be empty')
self.all_conv = []
for i in range(self.state['WINDOW_SIZE'] * 2, len(data)): for i in range(self.state['WINDOW_SIZE'] * 2, len(data)):
watch_data = data[i - self.state['WINDOW_SIZE'] * 2: i] watch_data = data[i - self.state['WINDOW_SIZE'] * 2: i]
watch_data = utils.subtract_min_without_nan(watch_data) watch_data = utils.subtract_min_without_nan(watch_data)

13
analytics/tests/test_dataset.py

@ -168,6 +168,19 @@ class TestDataset(unittest.TestCase):
except ValueError: except ValueError:
self.fail('Model {} raised unexpectedly'.format(model_name)) self.fail('Model {} raised unexpectedly'.format(model_name))
def test_general_for_two_labeling(self):
data_val = [1.0, 2.0, 5.0, 2.0, 1.0, 1.0, 3.0, 6.0, 4.0, 2.0, 1.0, 0, 0]
dataframe = create_dataframe(data_val)
segments = [{'_id': 'Esl7uetLhx4lCqHa', 'analyticUnitId': 'opnICRJwOmwBELK8', 'from': 1523889000001, 'to': 1523889000003, 'labeled': True, 'deleted': False}]
model = models.GeneralModel()
model.fit(dataframe, segments, dict())
result = len(data_val) + 1
for _ in range(2):
model.do_detect(dataframe)
max_pattern_index = max(model.do_detect(dataframe))
self.assertLessEqual(max_pattern_index, result)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

Loading…
Cancel
Save