def test_score_bad_match_same_day_run(self): """ Tests messages with mutually exclusive uids on the same day are scored lowly """ # uid, risk, day, time_received, true sender id current_day = 0 message1 = Message(0, 0, current_day, "human:0") message2 = Message(1, 0, current_day, "human:1") clusters = Clusters() clusters.add_messages([encode_message(message1)], current_day) best_cluster, best_message, best_score = clusters.score_matches( message2, current_day) self.assertEqual(best_score, -1) self.assertEqual(message1, best_message)
def test_score_bad_match_one_day_run(self): """ Tests messages with mutually exclusive uids seperated by a day are scored lowly """ # uid, risk, day, true sender id message1 = Message(0, 0, 0, "human:1") message2 = Message(6, 0, 1, "human:1") clusters = Clusters() clusters.add_messages([encode_message(message1)], 0) best_cluster, best_message, best_score = clusters.score_matches( message2, 1) self.assertEqual(best_cluster, 0) self.assertEqual(best_message, message1) self.assertEqual(best_score, -1)
def test_purge(self): """ Tests the purge functionality""" message1 = Message(0, 0, 0, "human:0") message2 = Message(15, 0, 1, "human:0") clusters = Clusters() clusters.add_messages([encode_message(message1)], 0) clusters.add_messages([encode_message(message2)], 0) clusters.purge(13) self.assertEqual(len(clusters), 2) clusters.purge(14) self.assertEqual(len(clusters), 1) clusters.purge(15) self.assertEqual(len(clusters), 0)
def test_score_good_match_same_day_run(self): """ Tests messages with the same uids on the same day are scored highly """ # uid, risk, day, true sender id current_day = 0 message1 = Message(0, 0, current_day, "human:1") message2 = Message(0, 0, current_day, "human:1") clusters = Clusters() clusters.add_messages([encode_message(message1)], current_day) best_cluster, best_message, best_score = clusters.score_matches( message2, current_day) self.assertEqual(best_cluster, 0) self.assertEqual(best_message, message1) self.assertEqual(best_score, 3)
def __init__(self, name=None): self.name = name self.M = {} self.sent_messages = {} self.messages = [] self.update_messages = [] self.risk = np.log(0.01) self.clusters = Clusters() self.all_reported_symptoms = [[]] self.all_symptoms = [] self.start_risk = np.log(0.01) self.uid = None self.time_of_recovery = datetime.datetime.max self.infectiousness_start_time = datetime.datetime.max self.time_of_death = datetime.datetime.max self.test_time = datetime.datetime.max self.time_of_exposure = datetime.datetime.max self.symptoms_start = datetime.datetime.max self.exposure_source = None self.exposure_message = None self.infectiousness_start = datetime.datetime.max self.tested_positive_contact_count = 0 self.rolling_infectiousness_array = [] self.infectiousness = {} self.locations_visited = {} self.obs_preexisting_conditions = set() self.obs_age = None self.obs_sex = None self.preexisting_conditions = set() self.age = None self.sex = None
def test_score_good_match_one_day_run(self): """ Tests messages with similar uids on the different day are scored mediumly """ # uid, risk, day, true sender id current_day = 0 clusters = Clusters() message1 = Message(0, 0, 0, "human:1") clusters.add_messages([encode_message(message1)], current_day) message2 = Message(1, 0, 1, "human:1") best_cluster, best_message, best_score = clusters.score_matches( message2, 1) self.assertEqual(best_cluster, 0) self.assertEqual(best_message, message1) self.assertEqual(best_score, 2)
def test_add_message_to_cluster_same_cluster_run(self): """ Tests that the add_message_to_cluster function adds messages with the same uid on the same day to the same cluster. """ # make new old message clusters message = Message(0, 0, 0, "human:1") clusters = Clusters() clusters.add_messages([encode_message(message)], 0) # make new message new_message = Message(0, 0, 0, "human:1") # add message to clusters clusters.add_messages([encode_message(new_message)], 0) self.assertEqual(len(clusters), 1)
def test_add_message_to_cluster_new_cluster_run(self): """ Tests messages with mutually exclusive uids on the same day are scored lowly """ # make new old message clusters message = Message(0, 0, 0, "human:1") clusters = Clusters() clusters.add_messages([encode_message(message)], 0) # make new message new_message = Message(1, 0, 0, "human:1") # add message to clusters clusters.add_messages([encode_message(new_message)], 0) num_clusters = len(clusters) self.assertEqual(num_clusters, 2)