def test_sum_avg_with_filtering(self): """test summing multiple events together via combine on the back end.""" # combine them all events = [ self._create_event(self.aware_ts, { 'a': 5, 'b': 6, 'c': 7 }), self._create_event(self.aware_ts, { 'a': None, 'b': None, 'c': 4 }), self._create_event(self.aware_ts, { 'a': 1, 'b': 2, 'c': 3 }), ] result = Event.sum(events, filter_func=Filters.zero_missing) self.assertEqual(result[0].get('a'), 6) result = Event.sum(events, filter_func=Filters.propagate_missing) self.assertIsNone(result[0].get('a')) result = Event.avg(events, filter_func=Filters.ignore_missing) self.assertEqual(result[0].get('b'), 4) result = Event.avg(events, filter_func=Filters.propagate_missing) self.assertIsNone(result[0].get('b'))
def test_sum_events_with_combine(self): """test summing multiple events together via combine on the back end.""" # combine them all events = [ self._create_event(self.aware_ts, {'a': 5, 'b': 6, 'c': 7}), self._create_event(self.aware_ts, {'a': 2, 'b': 3, 'c': 4}), self._create_event(self.aware_ts, {'a': 1, 'b': 2, 'c': 3}), ] result = Event.sum(events) self.assertEqual(result[0].get('a'), 8) self.assertEqual(result[0].get('b'), 11) self.assertEqual(result[0].get('c'), 14) # combine single field result = Event.sum(events, 'a') self.assertEqual(result[0].get('a'), 8) self.assertIsNone(result[0].get('b')) self.assertIsNone(result[0].get('c')) # grab multiple fields result = Event.sum(events, ['a', 'c']) self.assertEqual(result[0].get('a'), 8) self.assertIsNone(result[0].get('b')) self.assertEqual(result[0].get('c'), 14) # average result = Event.avg( events + [self._create_event(self.aware_ts, {'a': 1, 'b': 1, 'c': 2})], 'c') self.assertEqual(result[0].get('c'), 4) # bad arg self.assertEqual(Event.sum([]), []) self.assertEqual(Event.avg([]), []) # work the extra reducer functions in Functions module result = Event.combine(events, 'c', Functions.max()) self.assertEqual(result[0].get('c'), 7) result = Event.combine(events, 'c', Functions.min()) self.assertEqual(result[0].get('c'), 3) result = Event.combine(events, 'c', Functions.count()) self.assertEqual(result[0].get('c'), 3) result = Event.combine(events, 'c', Functions.first()) self.assertEqual(result[0].get('c'), 7) result = Event.combine(events, 'c', Functions.last()) self.assertEqual(result[0].get('c'), 3) result = Event.combine(events, 'c', Functions.difference()) self.assertEqual(result[0].get('c'), 4) self.assertIsNone(Functions.first()([])) self.assertIsNone(Functions.last()([]))
def test_sum_avg_with_filtering(self): """test summing multiple events together via combine on the back end.""" # combine them all events = [ self._create_event(self.aware_ts, {'a': 5, 'b': 6, 'c': 7}), self._create_event(self.aware_ts, {'a': None, 'b': None, 'c': 4}), self._create_event(self.aware_ts, {'a': 1, 'b': 2, 'c': 3}), ] result = Event.sum(events, filter_func=Filters.zero_missing) self.assertEqual(result[0].get('a'), 6) result = Event.sum(events, filter_func=Filters.propagate_missing) self.assertIsNone(result[0].get('a')) result = Event.avg(events, filter_func=Filters.ignore_missing) self.assertEqual(result[0].get('b'), 4) result = Event.avg(events, filter_func=Filters.propagate_missing) self.assertIsNone(result[0].get('b'))
def test_sum_events_with_combine(self): """test summing multiple events together via combine on the back end.""" # combine them all events = [ self._create_event(self.aware_ts, { 'a': 5, 'b': 6, 'c': 7 }), self._create_event(self.aware_ts, { 'a': 2, 'b': 3, 'c': 4 }), self._create_event(self.aware_ts, { 'a': 1, 'b': 2, 'c': 3 }), ] result = Event.sum(events) self.assertEqual(result[0].get('a'), 8) self.assertEqual(result[0].get('b'), 11) self.assertEqual(result[0].get('c'), 14) # combine single field result = Event.sum(events, 'a') self.assertEqual(result[0].get('a'), 8) self.assertIsNone(result[0].get('b')) self.assertIsNone(result[0].get('c')) # grab multiple fields result = Event.sum(events, ['a', 'c']) self.assertEqual(result[0].get('a'), 8) self.assertIsNone(result[0].get('b')) self.assertEqual(result[0].get('c'), 14) # average result = Event.avg( events + [self._create_event(self.aware_ts, { 'a': 1, 'b': 1, 'c': 2 })], 'c') self.assertEqual(result[0].get('c'), 4) # bad arg self.assertEqual(Event.sum([]), []) self.assertEqual(Event.avg([]), []) # work the extra reducer functions in Functions module result = Event.combine(events, 'c', Functions.max()) self.assertEqual(result[0].get('c'), 7) result = Event.combine(events, 'c', Functions.min()) self.assertEqual(result[0].get('c'), 3) result = Event.combine(events, 'c', Functions.count()) self.assertEqual(result[0].get('c'), 3) result = Event.combine(events, 'c', Functions.first()) self.assertEqual(result[0].get('c'), 7) result = Event.combine(events, 'c', Functions.last()) self.assertEqual(result[0].get('c'), 3) result = Event.combine(events, 'c', Functions.difference()) self.assertEqual(result[0].get('c'), 4) self.assertIsNone(Functions.first()([])) self.assertIsNone(Functions.last()([]))