covid19-etl/etl/idph_vaccine_to_s3.py
def format_result(self, county_to_fips_dict, existing_data, new_data):
        """
        Parse new data from Peregrine and add it to the existing data.

        Args:
        - `county_to_fips_dict`
        - `existing_data` format: see data file format at the top of this file
        - `new_data`: data from Peregrine, in format:
            {
                summary_location: [
                    {
                        county: <county name>,
                        summary_clinicals: [
                            {
                                date: <str>,
                                vaccine_persons_fully_vaccinated: <int>
                            },
                            ...
                        ]
                    },
                    ...
                ]
            }
        """
        # the date at which this data was last updated
        existing_data["last_updated"] = self.get_last_updated_date(
            new_data["summary_location"][0]["summary_clinicals"]
        )

        chicago_data_by_date = None
        for location in new_data["summary_location"]:
            county = location["county"]

            # get the total count
            if county == "Illinois":
                for record in location["summary_clinicals"]:
                    date = record["date"].split("T")[0]
                    if date == existing_data["last_updated"]:
                        existing_data["total"] = record[
                            "vaccine_persons_fully_vaccinated"
                        ]
                continue

            fips = county_to_fips_dict.get(county)
            if not fips:
                if county in ["Unknown", "Out Of State", "Chicago"]:
                    # we expect no FIPS for these, use the name as identifier
                    fips = county
                else:
                    raise Exception(
                        f"Uh-oh, did not find FIPS code for county '{county}'"
                    )

            data_by_date = {}
            for record in location["summary_clinicals"]:
                # remove time from some early dates in the dataset
                date = record["date"].split("T")[0]
                data_by_date[date] = record["vaccine_persons_fully_vaccinated"]

            if county == "Chicago":
                # the Chicago data are processed later
                chicago_data_by_date = data_by_date
            else:
                if fips in existing_data["il_county_list"]:
                    # merge existing data and new data
                    data_by_date = dict(
                        data_by_date, **existing_data["il_county_list"][fips]["by_date"]
                    )
                existing_data["il_county_list"][fips] = {
                    "county": county,
                    "by_date": data_by_date,
                }

        # we don't separate Chicago from Cook county on the frontend,
        # so add the Chicago counts to the Cook county counts.
        for data in existing_data["il_county_list"].values():
            if data["county"] == "Cook":
                for date in data["by_date"]:
                    # ignore dates that are in Chicago data but not Cook data;
                    # counts without the rest of Cook county would look weird
                    if date in chicago_data_by_date:
                        data["by_date"][date] += chicago_data_by_date[date]
                break

        return existing_data

        Parse new data from Peregrine and add it to the existing data.

        Args:
        - `county_to_fips_dict`
        - `existing_data` format: see data file format at the top of this file
        - `new_data`: data from Peregrine, in format:
            {
                summary_location: [
                    {
                        county: <county name>,
                        summary_clinicals: [
                            {
                                date: <str>,
                                vaccine_persons_fully_vaccinated: <int>
                            },
                            ...
                        ]
                    },
                    ...
                ]
            }
        
Parse new data from Peregrine and add it to the existing data.
Parse new data from Peregrine and add it to the existing data .
def format_result(self, county_to_fips_dict, existing_data, new_data):
        existing_data["last_updated"] = self.get_last_updated_date(
            new_data["summary_location"][0]["summary_clinicals"]
        )
        chicago_data_by_date = None
        for location in new_data["summary_location"]:
            county = location["county"]
            if county == "Illinois":
                for record in location["summary_clinicals"]:
                    date = record["date"].split("T")[0]
                    if date == existing_data["last_updated"]:
                        existing_data["total"] = record[
                            "vaccine_persons_fully_vaccinated"
                        ]
                continue
            fips = county_to_fips_dict.get(county)
            if not fips:
                if county in ["Unknown", "Out Of State", "Chicago"]:
                    fips = county
                else:
                    raise Exception(
                        f"Uh-oh, did not find FIPS code for county '{county}'"
                    )
            data_by_date = {}
            for record in location["summary_clinicals"]:
                date = record["date"].split("T")[0]
                data_by_date[date] = record["vaccine_persons_fully_vaccinated"]
            if county == "Chicago":
                chicago_data_by_date = data_by_date
            else:
                if fips in existing_data["il_county_list"]:
                    data_by_date = dict(
                        data_by_date, **existing_data["il_county_list"][fips]["by_date"]
                    )
                existing_data["il_county_list"][fips] = {
                    "county": county,
                    "by_date": data_by_date,
                }
        for data in existing_data["il_county_list"].values():
            if data["county"] == "Cook":
                for date in data["by_date"]:
                    if date in chicago_data_by_date:
                        data["by_date"][date] += chicago_data_by_date[date]
                break
        return existing_data
def format_result ( self , county_to_fips_dict , existing_data , new_data ) : existing_data [ "last_updated" ] = self . get_last_updated_date ( new_data [ "summary_location" ] [ 0 ] [ "summary_clinicals" ] ) chicago_data_by_date = None for location in new_data [ "summary_location" ] : county = location [ "county" ] if county == "Illinois" : for record in location [ "summary_clinicals" ] : date = record [ "date" ] . split ( "T" ) [ 0 ] if date == existing_data [ "last_updated" ] : existing_data [ "total" ] = record [ "vaccine_persons_fully_vaccinated" ] continue fips = county_to_fips_dict . get ( county ) if not fips : if county in [ "Unknown" , "Out Of State" , "Chicago" ] : fips = county else : raise Exception ( f"Uh-oh, did not find FIPS code for county '{county}'" ) data_by_date = { } for record in location [ "summary_clinicals" ] : date = record [ "date" ] . split ( "T" ) [ 0 ] data_by_date [ date ] = record [ "vaccine_persons_fully_vaccinated" ] if county == "Chicago" : chicago_data_by_date = data_by_date else : if fips in existing_data [ "il_county_list" ] : data_by_date = dict ( data_by_date , ** existing_data [ "il_county_list" ] [ fips ] [ "by_date" ] ) existing_data [ "il_county_list" ] [ fips ] = { "county" : county , "by_date" : data_by_date , } for data in existing_data [ "il_county_list" ] . values ( ) : if data [ "county" ] == "Cook" : for date in data [ "by_date" ] : if date in chicago_data_by_date : data [ "by_date" ] [ date ] += chicago_data_by_date [ date ] break return existing_data
Parse new data from Peregrine and add it to the existing data.
Parse new data from Peregrine and add it to the existing data .
"""
        Parse new data from Peregrine and add it to the existing data.

        Args:
        - `county_to_fips_dict`
        - `existing_data` format: see data file format at the top of this file
        - `new_data`: data from Peregrine, in format:
            {
                summary_location: [
                    {
                        county: <county name>,
                        summary_clinicals: [
                            {
                                date: <str>,
                                vaccine_persons_fully_vaccinated: <int>
                            },
                            ...
                        ]
                    },
                    ...
                ]
            }
        """ # the date at which this data was last updated # get the total count # we expect no FIPS for these, use the name as identifier # remove time from some early dates in the dataset # the Chicago data are processed later # merge existing data and new data # we don't separate Chicago from Cook county on the frontend, # so add the Chicago counts to the Cook county counts. # ignore dates that are in Chicago data but not Cook data; # counts without the rest of Cook county would look weird
self
county_to_fips_dict
existing_data
new_data