def update(self):

        # get the source data
        source_data = self.source.

        # get postcode xys
        xys = da_arcpy.load_xy_geometries(source=self.geometry_source._source,
                                          id_field=self.geometry_source.poa_code_field)

        # convert to input rows
        data = {}
        for row in source_data:
            date_str = self.target.format_date_string(date_string=row[self.nsw_source.most_recent_date_field], in_format=self.nsw_source.csv_date_format)
            postcode = row[self.nsw_source.postcode_field]
            if not postcode:
                postcode = 'UNK'

            key = '{}_{}'.format(date_str, postcode)
            data_item = data.get(key, None)
            if data_item:
                data_item['value'] += 1
            else:
                xy = xys.get(postcode, None)
                data[key] = {'value': 1, 'geometry': xy}

        return self.target.update_statistic(update_values=data, allow_deletes=True)
Esempio n. 2
0
    def full_update(self):
        """
        Performs a full update from the source data, inculding adds, deletes and updates.
        A combination of the date_code and postcode are used as the full identifier.
        :return:
        :rtype:
        """
        # get the source data
        source_data = self.nsw_source.source_data()

        # sort rows by date and postcode.
        sorted_data = sorted(
            source_data,
            key=lambda x:
            (x[self.nsw_source.postcode_field], x[self.nsw_source.date_field]))

        # get postcode xys
        xys = da_arcpy.load_xy_geometries(
            source=self.geometry_source._source,
            id_field=self.geometry_source.poa_code_field)

        # convert to input rows
        totals = {}
        wkg = {}
        for row in sorted_data:
            date_str = self.target.format_date_string(
                date_string=row[self.nsw_source.date_field],
                in_format=self.nsw_source.out_date_format)
            postcode = row[self.nsw_source.postcode_field]
            if not postcode:
                postcode = 'UNK'

            total = totals.get(postcode, 0) + 1
            totals[postcode] = total

            key = '{}_{}'.format(postcode, date_str)
            wkg_item = wkg.get(key, None)
            if wkg_item:
                wkg_item['tests'] += 1
                wkg_item['total_tests'] = total
            else:
                xy = xys.get(postcode, None)
                wkg_item = {
                    'postcode': postcode,
                    'date_code': date_str,
                    'tests': 1,
                    'total_tests': total,
                    'xy': xy
                }
                wkg[key] = wkg_item

        return self.target.update(rows=wkg.values(), allow_deletes=True)
    def _get_vic_source(self):
        source_data = self.vic_source.daily_cases_by_lga()

        xys = da_arcpy.load_xy_geometries(source=self.lga2020._source,
                                          id_field=self.lga2020.lga_code_field,
                                          where_clause="{} = '2'".format(
                                              self.lga2020.ste_code_field))

        for source_item in source_data:
            source_id = source_item['lga_code']
            source_item['xy'] = xys.get(source_id, None)
            source_item['lga_version'] = '2020'

        return source_data
    def _get_nsw_source(self):
        # get the source data
        source_data = self.nsw_source.source_data()

        # sort rows by date and lga_code.
        sorted_data = sorted(
            source_data,
            key=lambda x:
            (x[self.nsw_source.lga_code_field], x[self.nsw_source.date_field]))

        # convert to input rows
        xys = da_arcpy.load_xy_geometries(source=self.lga2019._source,
                                          id_field=self.lga2019.lga_code_field,
                                          where_clause="{} = '1'".format(
                                              self.lga2019.ste_code_field))

        totals = {}
        wkg = {}
        for row in sorted_data:
            date_str = self.target.format_date_string(
                date_string=row[self.nsw_source.date_field],
                in_format=self.nsw_source.csv_date_format)
            lga_code = row[self.nsw_source.lga_code_field]
            if not lga_code:
                lga_code = '00000'

            total = totals.get(lga_code, 0) + 1
            totals[lga_code] = total

            key = '{}_{}'.format(lga_code, date_str)
            wkg_item = wkg.get(key, None)
            if wkg_item:
                wkg_item['cases'] += 1
                wkg_item['total_cases'] = total
            else:
                lga_name = row[self.nsw_source.lga_name_field]
                wkg_item = {
                    'lga_code': lga_code,
                    'lga_name': lga_name,
                    'date_code': date_str,
                    'cases': 1,
                    'total_cases': total,
                    'lga_version': '2019',
                    'xy': xys.get(lga_code, None)
                }
                wkg[key] = wkg_item
        return wkg.values()
    def apply_xys(self, postcode_items):
        """
        Applys the xy geometries to each postcode using the geometry_source.  If no geometry for the postcode is found, the output
        'xy' value will be None for that item.

        :param postcode_items: {postcode: {}}
        :type postcode_items: dict
        :return: {postcode: {'xy': {'x': float, 'y': float}}
        :rtype: dict
        """

        # get postcode xys
        xys = da_arcpy.load_xy_geometries(
            source=self.geometry_source._source,
            id_field=self.geometry_source.poa_code_field)

        for postcode, postcode_item in postcode_items.items():
            postcode_item['xy'] = xys.get(postcode, None)

        return postcode_items
Esempio n. 6
0
    def full_update(self):
        """
        Performs a full update from the source data, including adds, deletes and updates.
        :return:
        :rtype:
        """
        # get the source data
        source_data = self.nsw_notifications_source.source_data()

        # sort rows by date and postcode.
        sorted_data = sorted(source_data,
                             key=lambda x:
                             (x[self.nsw_notifications_source.postcode_field],
                              x[self.nsw_notifications_source.date_field]))

        # get postcode xys
        xys = da_arcpy.load_xy_geometries(
            source=self.postcode_feature_source.source,
            id_field=self.postcode_feature_source.poa_code_field)

        # convert to input rows
        wkg = {}
        for row in sorted_data:
            date_str = self.feature_service.format_date_string(
                date_string=row[self.nsw_notifications_source.date_field],
                in_format='%Y%m%d')
            postcode = row[self.nsw_notifications_source.postcode_field]
            if not postcode:
                postcode = 'UNK'

            key = '{}_{}'.format(date_str, postcode)
            wkg_item = wkg.get(key, None)
            if wkg_item:
                wkg_item['notifications'] += 1
            else:
                xy = xys.get(postcode, None)
                wkg[key] = {'notifications': 1, 'xy': xy}

        return self.feature_service.update(update_values=wkg,
                                           allow_deletes=True)