def test_multiple_persons_by_npa(): persons = 100 timestamp = int(time.time()) npa = 3240 for id in range(0,persons): doc_id = str(uuid.uuid4())[0:10] print(doc_id) report = IndividualReportModel( document_id=doc_id, diagnostic=random.randint(0, 4), locator=npa, session_id=str(uuid.uuid4()), timestamp=timestamp, analysis_done=False ) session.add(report) session.commit() analysis_next_report(persons) _date = datetime.fromtimestamp(timestamp) print(_date) q = session.query(DailyDiagnosticChangeModel) daily_change = q.filter_by(locator=npa, year=_date.year, month=_date.month, day=_date.day).first() total = daily_change.diagnostic_0 + \ daily_change.diagnostic_1 + \ daily_change.diagnostic_2 + \ daily_change.diagnostic_3 + \ daily_change.diagnostic_4 assert persons == total
def test_one_person_update(): nb_update = 1000 timestamps = range(1584892474, 1584892474 + nb_update) session_id = str(uuid.uuid4()) npa = 1246 for timestamp in timestamps: doc_id = str(uuid.uuid4())[0:10] print(doc_id) report = IndividualReportModel( document_id=doc_id, diagnostic=random.randint(0, 4), locator=npa, session_id=session_id, timestamp=timestamp, analysis_done=False ) session.add(report) session.commit() analysis_next_report(nb_update) _date = datetime.fromtimestamp(timestamps[0]) q = session.query(DailyDiagnosticChangeModel) daily_change = q.filter_by(locator=npa, year=_date.year, month=_date.month, day=_date.day).first() total = daily_change.diagnostic_0 + \ daily_change.diagnostic_1 + \ daily_change.diagnostic_2 + \ daily_change.diagnostic_3 + \ daily_change.diagnostic_4 print(total) assert total == 1
def build(json_object): seconds = json_object["data"]["timestamp"]["_seconds"] nanoseconds = json_object["data"]["timestamp"]["_nanoseconds"] timestamp = (seconds + nanoseconds / 1000000000) * 1000 # to milliseconds return IndividualReportModel( document_id=json_object["id"], diagnostic=json_object["data"]["diagnostic"], locator=json_object["data"]["locator"], session_id=json_object["data"]["sessionId"], timestamp=timestamp, analysis_done=False, symptoms=str(json_object["data"]["symptoms"]))
def test_insert_speed(): timestamps = range(1584892474, 1584892474 + 1000) npa = 1240 start_time = time.time() for timestamp in timestamps: doc_id = str(uuid.uuid4())[0:10] report = IndividualReportModel( document_id=doc_id, diagnostic=random.randint(0, 4), locator=npa, session_id=str(uuid.uuid4()), timestamp=timestamp ) session.add(report) session.commit() print('Insertion time:',time.time() - start_time)
def build(json_object): seconds = json_object["data"]["timestamp"]["_seconds"] nanoseconds = json_object["data"]["timestamp"]["_nanoseconds"] timestamp = (seconds + nanoseconds / 1000000000) * 1000 # to milliseconds symptoms = json_object["data"]["symptoms"] return IndividualReportModel( document_id=json_object["id"], diagnostic=json_object["data"]["diagnostic"], locator=json_object["data"]["locator"], session_id=json_object["data"]["sessionId"], timestamp=timestamp, analysis_done=False, # FIXME: need to be changed if the website is updated with new # questions based on 1177 guidelines symptoms=str(symptoms), temp="mid" if "fever" in symptoms else "low", cough="sometimes" if "cough" in symptoms else "no", breathless="sometimes" if "dyspnea" in symptoms else "no", energy="tired" if "weakness" in symptoms else "normal")
def insert_fake_inidividual_reports(): from_day = '2020-03-10' to_day = '2020-03-15' sample_per_day = 1000 person_list = gen_fake_person_list(sample_per_day) from_date = datetime.strptime(from_day, DAY_FORMAT) to_date = datetime.strptime(to_day, DAY_FORMAT) _from = int(datetime.strptime(from_day, DAY_FORMAT).timestamp()) _to = int(datetime.strptime(to_day, DAY_FORMAT).timestamp()) current_day = from_date while current_day <= to_date: timestamp = current_day.timestamp() start_time = time.time() for sample in range(0, sample_per_day): person = random_list_element(person_list) doc_id = str(uuid.uuid4())[0:20] report = IndividualReportModel( document_id=doc_id, diagnostic=random.randint(0, 4), locator=person['npa'], session_id=person['session_id'], timestamp=(timestamp + sample) * 1000, # to millisecond analysis_done=False) # print(report.timestamp) session.add(report) session.commit() spend_time = time.time() - start_time print( str(current_day) + ': uploaded ' + str(sample_per_day) + ' samples in ' + str(spend_time) + 's') current_day = current_day + timedelta(days=1)
def insert_fake_inidividual_reports(): from_day = '2020-03-10' to_day = '2020-03-15' sample_per_day = 1000 person_list = gen_fake_person_list(sample_per_day) from_date = datetime.strptime(from_day, DAY_FORMAT) to_date = datetime.strptime(to_day, DAY_FORMAT) _from = int(datetime.strptime(from_day, DAY_FORMAT).timestamp()) _to = int(datetime.strptime(to_day, DAY_FORMAT).timestamp()) def random_bool(): return random.randint(0, 1) current_day = from_date while current_day <= to_date: timestamp = current_day.timestamp() start_time = time.time() for sample in range(0, sample_per_day): person = random_list_element(person_list) doc_id = str(uuid.uuid4())[0:20] has_comorbid = random_bool() comorbid = Comorbid( hypertension = random_bool(), cardiovascular = random_bool(), pulmonary = random_bool(), cancer = random_bool(), diabetes = random_bool(), renal = random_bool(), neurological = random_bool(), respiratory = random_bool(), ) report = IndividualReportModel( # Metadata document_id=doc_id, diagnostic=random.randint(0, 4), locator=person['npa'], session_id=person['session_id'], timestamp=(timestamp + sample ) * 1000, # to millisecond analysis_done=False, # Actual data temp=enum.Scale3(random.randint(1, 3)).name, cough=enum.Scale4(random.randint(0, 3)).name, breathless=enum.Scale4(random.randint(0, 3)).name, energy=enum.Energy(random.randint(0, 4)).name, exposure=enum.Exposure(random.randint(0, 2)).name, has_comorbid=has_comorbid, comorbid=comorbid, compromised_immune=random_bool(), age=enum.Scale3(random.randint(1, 3)).name, ) # print(report.timestamp) session.add(report) session.commit() spend_time = time.time() - start_time print(str(current_day) + ': uploaded ' + str(sample_per_day) + ' samples in ' + str(spend_time) + 's') current_day = current_day + timedelta(days=1)