X-Git-Url: https://plomlompom.com/repos/feed.xml?a=blobdiff_plain;ds=inline;f=enhance_table.py;h=7fe22b3cf04195dff574a14084b6f71b165c7ce6;hb=2b686eda23627862965e73c1abfd097a2ef0411a;hp=c670739eb69c53f2ef9ce2b7e26a9300e9138424;hpb=b2afbdcf5351cf2aa7898241baa7ab081814d522;p=berlin-corona-table diff --git a/enhance_table.py b/enhance_table.py index c670739..7fe22b3 100755 --- a/enhance_table.py +++ b/enhance_table.py @@ -32,9 +32,10 @@ translate = { 'TS': 'Tempelhof-Schöneberg', 'TK': 'Treptow-Köpenick', 'sum': 'all of Berlin', - 'wsum': 'sum for last 7 days', - 'wavg': 'per-day average of new infections for last 7 days', - 'winc': 'incidence (x per 100k inhabitants) of new infections for last 7 days', + '+': 'new infections counted that day', + 'Σ': 'sum of new infections for last 7 days', + 'Ã': 'per-day average of new infections for last 7 days', + 'i': 'incidence (x per 100k inhabitants) of new infections for last 7 days', } # Read infections table path and output type. @@ -95,17 +96,20 @@ for line in lines[1:]: sorted_dates.sort() # In LaGeSo's data, the last "district" is actually the sum of all districts / -# the whole of Berlin. -# +# the whole of Berlin. For our district order, move it in front of the other +# districts, as its numbers are the most interesting, so in the table views +# we want to see it first. +sum_district = sorted_districts.pop() +sorted_districts.insert(0, sum_district) + # Fail on any day where the "sum" district's new infections are not the proper # sum of the individual districts new infections. Yes, sometimes Lageso sends # data that is troubled in this way. It will then have to be fixed manually in # the table file, since we should have a human look at what mistake was # probably made. for date in sorted_dates: - sum_district = sorted_districts[-1] day_sum = 0 - for district in sorted_districts[:-1]: + for district in [d for d in sorted_districts if not d==sum_district]: day_sum += db[district][date]['new_infections'] if day_sum != db[sum_district][date]['new_infections']: raise Exception('Questionable district infection sum in %s' % date) @@ -130,54 +134,53 @@ for i in range(len(sorted_dates)): db[district][date]['week_incidence'] = (week_sum / district_pop) * 100000 # Optimized for web browser viewing. +import calendar if output_type == 'html': print("""
Updated daily at 9pm based on data from the "Senatsverwaltung für Gesundheit, Pflege und Gleichstellung". Source code. Text view optimized for terminal curl.
+Updated daily at 9pm based on data from the "Senatsverwaltung für Gesundheit, Pflege und Gleichstellung". Source code. Plain text view (optimized for terminal curl).
""") sorted_dates.reverse() - long_wsum = translate['wsum'] - long_wavg = translate['wavg'] - long_winc = translate['winc'] - sum_district = sorted_districts[-1] for district in sorted_districts: - long_form = translate[district] # Wrap in div because the vertical orientation otherwise fails # in Chromium. - print(' | %s | ' % long_form)
- print('||||||
---|---|---|---|---|---|---|---|
date | ') - print('') - for district in sorted_districts: - print(' | %s | ' % district) + print('%s | ' %
+ translate[district])
print('||||
date | ') + print('? | ') + for district in sorted_districts: + print('%s | ' % + (translate[district], district)) + print('|||||
%s | ' % date) + weekday = calendar.day_name[datetime.date.fromisoformat(date).weekday()] + print('%s %s | ' % (date, weekday))
print('
| ')
for district in sorted_districts:
district_data = db[district][date]
- week_sum = week_avg = week_inc = '(not enough data)'
+ week_sum = week_avg = week_inc = '?'
new_infections = district_data['new_infections']
if 'week_sum' in district_data:
week_sum = '%s' % district_data['week_sum']
@@ -194,7 +197,16 @@ if output_type == 'html':
print('