示例#1
0
    def update_from_source(self,
                           nsw_source: NSW_SourceData.NswTestData = NSW_SourceData.NswTestData(),
                           geometry_source: TableBase = None):
        new_records = {}

        # get state capital geometries indexed by state abbreviation
        if not geometry_source:
            geometry_source = POA2016.centroids()
        features = geometry_source.values_by_id(value_field='SHAPE@')

        # load nsw source.
        for key, test_count in nsw_source.counts_by_date_and_postcode().items():
            date_code, postcode = key.split('_')
            new_record = new_records.get(key, None)
            if new_record:
                new_record[self.tests_field] = test_count
            else:
                shape_value = features.get(postcode, None)
                date_value = datetime.datetime.strptime(date_code, '%Y%m%d').date()
                new_records[key] = {self.id_field: key,
                                    self.postcode_field: postcode,
                                    self.date_field: date_value,
                                    self.tests_field: test_count,
                                    self.shape_field: shape_value}

        fields = [self.id_field, self.date_field, self.postcode_field, self.tests_field]
        return self._helper.update_records(new_data=new_records, fields=fields, add_new=True, delete_unmatched=True, shape_field=self.shape_field)
示例#2
0
    def update_from_source(self,
                           nsw_source: NSW_SourceData.NswNotificationAndSourceData = NSW_SourceData.NswNotificationAndSourceData(),
                           geometry_source: TableBase = None):
        new_records = {}

        # get state capital geometries indexed by state abbreviation
        if not geometry_source:
            geometry_source = POA2016.centroids()
        features = geometry_source.values_by_id(value_field='SHAPE@')

        # load nsw source.  NSW source values override any existing jhu values for nsw.
        for key, case_count in nsw_source.counts_by_date_postcode_source().items():
            my_key = self.__convert_key(key)
            date_code, postcode, source = my_key.split('_')
            new_record = new_records.get(my_key, None)
            if new_record:
                new_record[self.cases_field] = case_count
            else:
                shape_value = features.get(postcode, None)
                date_value = datetime.datetime.strptime(date_code, '%Y%m%d').date()
                new_records[my_key] = {self.id_field: my_key,
                                       self.postcode_field: postcode,
                                       self.date_field: date_value,
                                       self.likely_source_field: source,
                                       self.cases_field: case_count,
                                       self.shape_field: shape_value}

        fields = [self.id_field, self.date_field, self.postcode_field, self.likely_source_field, self.cases_field]
        return self._helper.update_records(new_data=new_records, fields=fields, add_new=True, delete_unmatched=True, shape_field=self.shape_field)
示例#3
0
 def __init__(self,
              target=covid.DailyCovid19TestingByPostcode(),
              nsw_source=covid_nsw.NswTestData(),
              geometry_source=POA2016.centriods()):
     self.target = target
     self.nsw_source = nsw_source
     self.geometry_source = geometry_source
 def __init__(self):
     self.target = NamedStatisticsByRegionAndDate(
         service_url=r'https://services9.arcgis.com/7eQuDPPaB6g9029K/arcgis/rest/services/COVID_19_Statistics_by_Postcode_and_Date/FeatureServer/0',
         region_id_field='Postcode',
         statistic_name='TESTS'
     )
     self.nsw_source = NswNotificationData()
     self.geometry_source = POA2016.centroids()
示例#5
0
def update_daily_testing_by_postcode():
    daily_postcode_stats = DailyRegionStatistics()

    source = covid_nsw.NswTestData()
    source.add_postcode_tests(data_model=daily_postcode_stats, name='tests')

    daily_postcode_stats.calculate_cumulative_daily_totals(['tests'])
    postcode_centroid_xys = POA2016.centriods().load_xy_tuples()

    target = covid.DailyCovid19TestingByPostcode()
    update_rows = daily_postcode_stats.get_rows(['tests', 'total_tests'])
    pprint.pprint(update_rows)
    cleaned_data = target.pre_process_data(
        raw_data=update_rows,
        geometry_source=postcode_centroid_xys,
        postcode_key='region_id',
        date_str_key='date',
        date_format=source.csv_date_format,
        tests_key='tests',
        total_tests_key='total_tests')
    pprint.pprint(cleaned_data)
示例#6
0
 def __init__(self, service_url=default_service_url):
     self.target = DailyCovid19TestingByPostcode(service_url)
     self.nsw_source = NswTestData()
     self.geometry_source = POA2016.centroids()
示例#7
0
 def __init__(self):
     self.feature_service = Covid19NotificationsByDateAndPostcode()
     self.nsw_notifications_source = NswNotificationData()
     self.postcode_feature_source = POA2016.centroids()
示例#8
0
 def __init__(self, service_url=default_service_url):
     self.target = DailyCovid19CasesByPostcode(service_url)
     self.nsw_source = NswNotificationData()
     self.geometry_source = POA2016.centroids()