Esempio n. 1
0
 def _get_points(self,
                 data: typing.List[typing.Dict],
                 min_timestamp=None) -> typing.List[CovidPoint]:
     res = []
     for entry in data:
         updated_at = datetime.datetime.strptime(entry['dateChecked'],
                                                 '%Y-%m-%dT%H:%M:%SZ')
         if min_timestamp and updated_at < datetime.datetime.fromtimestamp(
                 min_timestamp):
             continue
         point = CovidPoint(
             source="covidtracking_usa",
             timestamp=updated_at,
             last_update=int(updated_at.strftime('%s')),
             country="USA",
             region=normalize_data(entry['state'].replace("'", ".")),
             city="",
             confirmed_cumulative=int(entry['total'] or 0),
             death_cumulative=int(entry.get('death') or 0),
             recovered_cumulative=entry.get('negative') or 0,
             hospitalized_cumulative=int(entry.get('hospitalized') or 0),
             severe_cumulative=0,
             tests_cumulative=int(entry.get('totalTestResults') or 0))
         res.append(point)
     return res
Esempio n. 2
0
 def _get_points(self, data: str, timestamp=None) -> typing.List[CovidPoint]:
     res = []
     csv_data = self._parse_csv(data)
     index = csv_data[0]
     years = self._get_years(index)
     pre_res = {}
     for row in csv_data[1:]:
         for year, yeardata in years.items():
             timestamp = self._weekref_to_datetime(row, year)
             key = self._get_range_key(row[7])
             self._ensure_data_populated(pre_res, row[3], row[4], timestamp)
             pre_res[row[3]][row[4]][timestamp]['females_deaths'] += int(row[yeardata['femmine']])
             pre_res[row[3]][row[4]][timestamp]['males_deaths'] += int(row[yeardata['maschi']])
             pre_res[row[3]][row[4]][timestamp]['total_deaths'] += int(row[yeardata['totale']])
             pre_res[row[3]][row[4]][timestamp]['females_{}_deaths'.format(key)] += int(row[yeardata['femmine']])
             pre_res[row[3]][row[4]][timestamp]['males_{}_deaths'.format(key)] += int(row[yeardata['maschi']])
             pre_res[row[3]][row[4]][timestamp]['total_{}_deaths'.format(key)] += int(row[yeardata['totale']])
     for region in pre_res.keys():
         for province in pre_res[region].keys():
             for timestamp, _data in pre_res[region][province].items():
                 res.append(
                     IstatDeathRatePoint(
                         timestamp=timestamp,
                         country='Italy',
                         province=normalize_data(province),
                         region=normalize_data(region),
                         city='',
                         females_deaths=_data['females_deaths'],
                         males_deaths=_data['males_deaths'],
                         total_deaths=_data['total_deaths'],
                         females_0_14_deaths=_data['females_0_14_deaths'],
                         males_0_14_deaths=_data['males_0_14_deaths'],
                         total_0_14_deaths=_data['total_0_14_deaths'],
                         females_15_64_deaths=_data['females_15_64_deaths'],
                         males_15_64_deaths=_data['males_15_64_deaths'],
                         total_15_64_deaths=_data['total_15_64_deaths'],
                         females_65_74_deaths=_data['females_65_74_deaths'],
                         males_65_74_deaths=_data['males_65_74_deaths'],
                         total_65_74_deaths=_data['total_65_74_deaths'],
                         females_over75_deaths=_data['females_over75_deaths'],
                         males_over75_deaths=_data['males_over75_deaths'],
                         total_over75_deaths=_data['total_over75_deaths'],
                         source='istat_weekly_death_rate'
                     )
                 )
     return res
Esempio n. 3
0
 def _get_points(self, timestamp=None) -> typing.List[CovidPoint]:
     res = []
     for country, function in self._country_fns.items():
         data = function()
         for d in data:
             if timestamp <= int(d['timestamp'].strftime('%s')):
                 res.append(
                     InhabitantsPoint(
                         timestamp=d['timestamp'],
                         country=d['country'],
                         province=normalize_data(d['province']),
                         region=normalize_data(d['region']),
                         residents=int(d['residents']),
                         size_sqm=float(d['size_sqm']),
                         density=int(d['density']),
                         municipalities=int(d['municipalities'])))
     return res
 def _get_points(self, data: typing.List[typing.List]) -> typing.List[CovidPoint]:
     res = []
     for entry in data:
         rows = self._parse_csv(entry[1])
         for row in rows:
             last_update = self._get_last_update_timestamp(row[0])
             point = CovidPoint(
                 source="csse",
                 timestamp=datetime.datetime.fromtimestamp(last_update),
                 last_update=last_update,
                 country=normalize_data(row[1]),
                 region=normalize_data(row[2]),
                 city="",
                 confirmed_cumulative=int(row[3] or 0),
                 death_cumulative=int(row[4] or 0),
                 recovered_cumulative=int(row[5] or 0),
                 hospitalized_cumulative=0,
                 severe_cumulative=0,
                 tests_cumulative=0
             )
             res.append(point)
     return res
Esempio n. 5
0
 def _get_points(self, data: typing.List[typing.Dict], min_timestamp=None) -> typing.List[CovidPoint]:
     res = []
     for row in data:
         dt_format = '%Y-%m-%dT%H:%M:%S' if 'T' in row['data'] else '%Y-%m-%d %H:%M:%S'
         updated_at = datetime.datetime.strptime(row['data'], dt_format)
         if min_timestamp and updated_at < datetime.datetime.fromtimestamp(min_timestamp):
             continue
         point = CovidPoint(
             source="dpc_ita",
             timestamp=updated_at,
             last_update=int(updated_at.strftime('%s')),
             country="Italy",
             region=normalize_data(row['denominazione_regione'].replace("'", ".")),
             city="",
             confirmed_cumulative=int(row['totale_positivi']),
             death_cumulative=int(row['deceduti']),
             recovered_cumulative=int(row['dimessi_guariti']),
             hospitalized_cumulative=int(row['totale_ospedalizzati']),
             severe_cumulative=int(row['terapia_intensiva']),
             tests_cumulative=int(row['tamponi'])
         )
         res.append(point)
     return res