home · contact · privacy
Extend abbreviation mapping, use collapsible for HTML table cells.
authorChristian Heller <c.heller@plomlompom.de>
Fri, 3 Jul 2020 19:06:56 +0000 (21:06 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Fri, 3 Jul 2020 19:06:56 +0000 (21:06 +0200)
enhance_table.py

index acbebc6b950905cab22a247a42010b69a15c166a..bdf91e1654a28be8d6c33445362f2cd0aadf7a3f 100755 (executable)
@@ -32,6 +32,9 @@ 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',
 }
 
 # Read infections table path and output type.
@@ -144,6 +147,9 @@ if output_type == 'html':
     for date in sorted_dates:
         print('<tr>')
         print('<td>%s</td>' % date)
+        long_wsum = translate['wsum']
+        long_wavg = translate['wavg']
+        long_winc = translate['winc']
         for district in sorted_districts:
             district_data = db[district][date]
             week_sum = week_avg = week_inc = ''
@@ -155,12 +161,12 @@ if output_type == 'html':
             if 'week_incidence' in district_data:
                 week_inc = '%.1f' % district_data['week_incidence']
             print('<td>')
-            print('<table>')
-            print('<tr><th>new</th><td>%s</td></tr>' % new_infections)
-            print('<tr><th>wsum</th><td>%s</td></tr>' % week_sum)
-            print('<tr><th>wavg</th><td>%s</td></tr>' % week_avg)
-            print('<tr><th>winc</th><td>%s</td></tr>' % week_inc)
-            print('</table>')
+            print(new_infections)
+            print('<details><summary>(more)</summary><table>')
+            print('<tr><th>%s</th><td>%s</td></tr>' % (long_wsum, week_sum))
+            print('<tr><th>%s</th><td>%s</td></tr>' % (long_wavg, week_avg))
+            print('<tr><th>%s</th><td>%s</td></tr>' % (long_winc, week_inc))
+            print('</table></details>')
             print('</td>')
         print('</tr>')
     print('</table>')
@@ -178,10 +184,7 @@ Abbrevations/explanations:
 """
     for k in translate:
         intro += "%s: %s\n" % (k, translate[k])
-    intro += """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
-
+    intro += """
 Source code: https://plomlompom.com/repos/?p=berlin-corona-table
 """
     print(intro)