fix: Refactored parts of the script into functions
This commit is contained in:
parent
e13e8f1df6
commit
0e0ad8bc0f
1 changed files with 118 additions and 109 deletions
63
plot.py
63
plot.py
|
@ -52,28 +52,33 @@ plt.rcParams["figure.figsize"] = [11.69, 8.27]
|
||||||
|
|
||||||
# Download
|
# Download
|
||||||
|
|
||||||
data_filename = '{}/{}_Impfquotenmonitoring.xlsx'.format(data_folder, filename_now)
|
def download_rki(filename_prefix):
|
||||||
|
data_filename = '{}/{}_Impfquotenmonitoring.xlsx'.format(data_folder, filename_prefix)
|
||||||
|
|
||||||
r = req.get('https://www.rki.de/DE/Content/InfAZ/N/Neuartiges_Coronavirus/Daten/Impfquotenmonitoring.xlsx?__blob=publicationFile')
|
r = req.get('https://www.rki.de/DE/Content/InfAZ/N/Neuartiges_Coronavirus/Daten/Impfquotenmonitoring.xlsx?__blob=publicationFile')
|
||||||
|
|
||||||
with open(data_filename, 'wb') as outfile:
|
with open(data_filename, 'wb') as outfile:
|
||||||
outfile.write(r.content)
|
outfile.write(r.content)
|
||||||
|
|
||||||
#data_filename = 'data/20210118151908_Impfquotenmonitoring.xlsx'
|
return data_filename
|
||||||
|
|
||||||
rki_file = pd.read_excel(data_filename, sheet_name=None, engine='openpyxl')
|
data_filename = download_rki(filename_now)
|
||||||
|
|
||||||
raw_data = rki_file['Impfungen_proTag']
|
def parse_rki(filename):
|
||||||
|
|
||||||
impfungen = raw_data[:-1].dropna(subset=['Datum']).fillna(0)
|
rki_file = pd.read_excel(filename, sheet_name=None, engine='openpyxl')
|
||||||
|
|
||||||
impfungen.drop(impfungen.tail(1).index,inplace=True) # remove Gesamt row
|
raw_data = rki_file['Impfungen_proTag']
|
||||||
|
|
||||||
dates = impfungen['Datum']
|
impfungen = raw_data[:-1].dropna(subset=['Datum']).fillna(0)
|
||||||
|
|
||||||
start_of_reporting_date = dates.iloc[0].date()
|
impfungen.drop(impfungen.tail(1).index,inplace=True) # remove Gesamt row
|
||||||
|
|
||||||
def calculate_vaccination_data(data):
|
dates = impfungen['Datum']
|
||||||
|
|
||||||
|
start_of_reporting_date = dates.iloc[0].date()
|
||||||
|
|
||||||
|
def calculate_vaccination_data(data):
|
||||||
|
|
||||||
total = int(np.sum(data))
|
total = int(np.sum(data))
|
||||||
total_percentage = float(total) / einwohner_deutschland * 100
|
total_percentage = float(total) / einwohner_deutschland * 100
|
||||||
|
@ -169,32 +174,36 @@ def calculate_vaccination_data(data):
|
||||||
'vaccinations_last_week_vaccination_percentage': vaccinations_by_week[Week.thisweek() - 1] / total * 100
|
'vaccinations_last_week_vaccination_percentage': vaccinations_by_week[Week.thisweek() - 1] / total * 100
|
||||||
}
|
}
|
||||||
|
|
||||||
if 'Erstimpfung' in impfungen:
|
if 'Erstimpfung' in impfungen:
|
||||||
raw_first_vaccinations = impfungen['Erstimpfung']
|
raw_first_vaccinations = impfungen['Erstimpfung']
|
||||||
elif 'Einmal geimpft' in impfungen:
|
elif 'Einmal geimpft' in impfungen:
|
||||||
raw_first_vaccinations = impfungen['Einmal geimpft']
|
raw_first_vaccinations = impfungen['Einmal geimpft']
|
||||||
elif 'Begonnene Impfserie' in impfungen:
|
elif 'Begonnene Impfserie' in impfungen:
|
||||||
raw_first_vaccinations = impfungen['Begonnene Impfserie']
|
raw_first_vaccinations = impfungen['Begonnene Impfserie']
|
||||||
|
|
||||||
if 'Zweitimpfung' in impfungen:
|
if 'Zweitimpfung' in impfungen:
|
||||||
raw_second_vaccinations = impfungen['Zweitimpfung']
|
raw_second_vaccinations = impfungen['Zweitimpfung']
|
||||||
elif 'Vollständig geimpft' in impfungen:
|
elif 'Vollständig geimpft' in impfungen:
|
||||||
raw_second_vaccinations = impfungen['Vollständig geimpft']
|
raw_second_vaccinations = impfungen['Vollständig geimpft']
|
||||||
|
|
||||||
data_first_vaccination = calculate_vaccination_data(raw_first_vaccinations)
|
data_first_vaccination = calculate_vaccination_data(raw_first_vaccinations)
|
||||||
data_second_vaccination = calculate_vaccination_data(raw_second_vaccinations)
|
data_second_vaccination = calculate_vaccination_data(raw_second_vaccinations)
|
||||||
|
|
||||||
# Stand aus Daten auslesen
|
# Stand aus Daten auslesen
|
||||||
#stand = dates.iloc[-1]
|
#stand = dates.iloc[-1]
|
||||||
#print_stand = stand.isoformat()
|
#print_stand = stand.isoformat()
|
||||||
|
|
||||||
# Stand aus offiziellen Angaben auslesen
|
# Stand aus offiziellen Angaben auslesen
|
||||||
stand = rki_file['Erläuterung'].iloc[1][0]
|
stand = rki_file['Erläuterung'].iloc[1][0]
|
||||||
|
|
||||||
stand_regex = re.compile('^Datenstand: (\d\d.\d\d.\d\d\d\d, \d?\d:\d\d) Uhr$')
|
stand_regex = re.compile('^Datenstand: (\d\d.\d\d.\d\d\d\d, \d?\d:\d\d) Uhr$')
|
||||||
m = stand_regex.match(stand)
|
m = stand_regex.match(stand)
|
||||||
stand_date = datetime.datetime.strptime(m.groups()[0], '%d.%m.%Y, %H:%M')
|
stand_date = datetime.datetime.strptime(m.groups()[0], '%d.%m.%Y, %H:%M')
|
||||||
print_stand = stand_date.isoformat()
|
print_stand = stand_date.isoformat()
|
||||||
|
|
||||||
|
return dates, start_of_reporting_date, data_first_vaccination, data_second_vaccination, stand_date, print_stand
|
||||||
|
|
||||||
|
dates, start_of_reporting_date, data_first_vaccination, data_second_vaccination, stand_date, print_stand = parse_rki(filename=data_filename)
|
||||||
|
|
||||||
filename_stand = stand_date.strftime("%Y%m%d%H%M%S")
|
filename_stand = stand_date.strftime("%Y%m%d%H%M%S")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue