def compare_cases_by_date_postcode_and_source(): l0 = AuthorityData2.CasesByDatePostcodeSource().records() l1 = DataEngine.CasesByDatePostcodeAndSource().records() d0 = {} for item in l0: key = '{}_{}_{}'.format(item['Postcode'], item['Date'].strftime('%Y%m%d'), item['LikelySource']) d0[key] = item['Cases'] d1 = {} for item in l1: key = '{}_{}_{}'.format(item['Postcode'], item['Date'].strftime('%Y%m%d'), item['LikelySource']) d1[key] = item['Cases'] print('d0 length: {}'.format(len(d0))) print('d1 length: {}'.format(len(d1))) keys = list(d0.keys()) for key in keys: if key in d1: if d0[key] == d1[key]: d0.pop(key) d1.pop(key) print('d0 length: {}'.format(len(d0))) print('d1 length: {}'.format(len(d1))) if d0 or d1: if d0: keys = list(d0.keys()) else: keys = [] if d1: keys.extend(d1.keys()) ids = set(keys) results = {} for key in ids: results[key] = {'d0': d0.get(key, None), 'd1': d1.get(key, None)} print('unmatched items') pprint.pprint(results) with open(r'E:\Documents2\tmp\cases_by_date_postcode_and_source.json', 'w') as file: file.write(json.dumps(results, indent=4))
def compare_tests_by_date_and_state(): l0 = AuthorityData2.TestsByDateAndState2().records() l1 = DataEngine.TestsByDateAndState().records() d0 = {} for item in l0: key = '{}_{}'.format(item['State'], item['Date'].strftime('%Y%m%d')) d0[key] = item['Tests'] d1 = {} for item in l1: key = '{}_{}'.format(item['State'], item['Date'].strftime('%Y%m%d')) d1[key] = item['Tests'] print('d0 length: {}'.format(len(d0))) print('d1 length: {}'.format(len(d1))) keys = list(d0.keys()) for key in keys: if key in d1: if d0[key] == d1[key]: d0.pop(key) d1.pop(key) print('d0 length: {}'.format(len(d0))) print('d1 length: {}'.format(len(d1))) if d0 or d1: if d0: keys = list(d0.keys()) else: keys = [] if d1: keys.extend(d1.keys()) ids = set(keys) results = {} for key in ids: results[key] = { 'd0': d0.get(key, 'No Match'), 'd1': d1.get(key, 'No Match') } print('unmatched items') pprint.pprint(results) with open(r'E:\Documents2\tmp\tests_by_date_and_state.json', 'w') as file: file.write(json.dumps(results, indent=4))
def update(): cases = AuthorityData2.CasesByDateAndState2() cases.update_from_source() deaths = AuthorityData2.DeathsByDateAndState2() deaths.update_from_source() tests = AuthorityData2.TestsByDateAndState2() tests.update_from_source() time_stamper = Covid19FeatureLayers2.DataExtractDates() updater = Covid19FeatureLayers2.CrisperStatisticsByState() updater.update_from_source(cases=cases, deaths=deaths, tests=tests) time_stamper.set_update_time(updater.source) updater = Covid19FeatureLayers2.Covid19StatisticsByDateAndState() updater.update_from_source(cases=cases, deaths=deaths, tests=tests) time_stamper.set_update_time(updater.source) updater = Covid19FeatureLayers2.CrisperMovingDailyAverageCasesByDateAndState( ) updater.update_from_source(cases=cases) time_stamper.set_update_time(updater.source) updater = Covid19FeatureLayers2.CrisperMovingDailyAverageDeathsByDateAndState( ) updater.update_from_source(deaths=deaths) time_stamper.set_update_time(updater.source) updater = Covid19FeatureLayers2.CrisperMovingDailyAverageTestsByDateAndState( ) updater.update_from_source(tests=tests) time_stamper.set_update_time(updater.source) cases = AuthorityData2.CasesByDateAndPostcode() cases.update_from_source() tests = AuthorityData2.TestsByDateAndPostcode() tests.update_from_source() updater = Covid19FeatureLayers2.Covid19StatisticsByDateAndPostcode() updater.update_from_source(cases=cases, tests=tests) time_stamper.set_update_time(updater.source) updater = Covid19FeatureLayers2.Covid19TotalNotificationsByPostcode() updater.update_from_source(cases=cases) time_stamper.set_update_time(updater.source) updater = Covid19FeatureLayers2.Covid19PostcodeStatisticPolygons() updater.update_from_source(cases=cases) time_stamper.set_update_time(updater.source) # update authority data-sets notifications_by_date_and_postcode = AuthorityData2.CasesByDatePostcodeSource( ) notifications_by_date_and_postcode.update_from_source() updater = Covid19FeatureLayers.Covid19CaseLocationsByPostcode() updater.synch_with_authority(notifications_by_date_and_postcode) time_stamper.set_update_time(updater.service_url) updater = Covid19FeatureLayers2.CrisperTotalCasesByDatePostcodeSource() updater.update_from_source(notifications_by_date_and_postcode) time_stamper.set_update_time(updater.source)