def handler_sighting(zmq_name, jsondata): logger.info('Handling sighting') jsonsight = jsondata['Sighting'] org = jsonsight['Event']['Orgc']['name'] categ = jsonsight['Attribute']['category'] action = jsondata.get('action', None) contributor_helper.handleContribution(zmq_name, org, 'Sighting', categ, action, pntMultiplier=2) handler_attribute(zmq_name, jsonsight, hasAlreadyBeenContributed=True) timestamp = jsonsight.get('date_sighting', None) if jsonsight['type'] == "0": # sightings trendings_helper.addSightings(timestamp) elif jsonsight['type'] == "1": # false positive trendings_helper.addFalsePositive(timestamp)
def test(): flag_error = False today = datetime.datetime.now() now = time.time # Events event1 = 'test_event_1' event2 = 'test_event_2' trendings_helper.addTrendingEvent(event1, now()) trendings_helper.addTrendingEvent(event1, now() + 5) trendings_helper.addTrendingEvent(event2, now() + 10) expected_result = [[int(now()), [[event1, 2.0], [event2, 1.0]]]] rep = trendings_helper.getTrendingEvents(today, today) if rep[0][1] != expected_result[0][1]: #ignore timestamps print('getTrendingEvents result not matching') flag_error = True # Tags tag1 = {'id': 'tag1', 'colour': 'blue', 'name': 'tag1Name'} tag2 = {'id': 'tag2', 'colour': 'red', 'name': 'tag2Name'} trendings_helper.addTrendingTags([tag1], now()) trendings_helper.addTrendingTags([tag1], now() + 5) trendings_helper.addTrendingTags([tag2], now() + 10) expected_result = [[int(now()), [[tag1, 2.0], [tag2, 1.0]]]] rep = trendings_helper.getTrendingTags(today, today) if rep[0][1] != expected_result[0][1]: #ignore timestamps print('getTrendingTags result not matching') flag_error = True # Sightings trendings_helper.addSightings(now()) trendings_helper.addSightings(now()) trendings_helper.addFalsePositive(now()) expected_result = [[1512636256, {'sightings': 2, 'false_positive': 1}]] rep = trendings_helper.getTrendingSightings(today, today) if rep[0][1] != expected_result[0][1]: #ignore timestamps print('getTrendingSightings result not matching') flag_error = True return flag_error