Skip to content

Instantly share code, notes, and snippets.

@flxai
Last active May 12, 2020 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flxai/cc03bc620dd8a3eb13e454cfa0c68ebd to your computer and use it in GitHub Desktop.
Save flxai/cc03bc620dd8a3eb13e454cfa0c68ebd to your computer and use it in GitHub Desktop.

Plot COVID-19 data on the city of Kassel. Data source is the city's own dedicated website which was scraped from a bot who posted changes in IRC. These changes have then been scraped again using some regexes:

echo 'day,time,county,total,total_rel,recovered,recovered_rel,infected,infected_rel,dead,dead_rel' > covid-ks-$(date -I).csv
grep -E 'Kassel (Stadt|Land):.+tot$' ~/.weechat/logs/irc.freenode.\#flipdot.weechatlog | sed -re 's/(,|\[psa\]|insgesamt|genesen|infiziert|tot|\)|\+|Kassel)//g' -e 's/@flipbot//' -e 's/(: )/ /g' -e 's/Stadt/0/' -e 's/Land/1/g' -e 's/(\s|\t|\(| )+/,/g' -e 's/,$//' >> covid-ks-$(date -I).csv

To see interactive plots, download the necessary libraries first:

pip install --user pandas matplotlib

After successful installation run the downloaded Python script in the same folder that the csv file resides in:

python3 covid-ks.py
day time county total total_rel recovered recovered_rel infected infected_rel dead dead_rel
2020-04-01 16:12:49 0 95 8 26 6 68 2 1 0
2020-04-01 16:16:21 0 95 8 26 6 68 2 1 0
2020-04-01 16:17:04 1 95 8 26 6 68 2 1 0
2020-04-02 10:26:40 1 100 5 31 5 68 0 1 0
2020-04-03 11:31:40 1 106 6 42 11 63 -5 1 0
2020-04-04 16:21:39 0 101 3 44 11 55 -10 2 2
2020-04-04 16:21:40 1 112 6 47 5 63 0 2 1
2020-04-05 12:36:40 0 103 2 48 4 53 -2 2 0
2020-04-05 12:36:40 1 114 2 54 7 57 -6 3 1
2020-04-06 10:18:34 0 103 0 49 1 52 -1 2 0
2020-04-06 10:18:34 1 118 4 54 0 61 4 3 0
2020-04-07 12:08:34 0 109 6 55 6 52 0 2 0
2020-04-07 12:08:34 1 120 2 59 5 58 -3 3 0
2020-04-08 11:03:34 0 117 8 59 4 56 4 2 0
2020-04-08 11:03:34 1 140 20 60 1 76 18 4 1
2020-04-09 12:53:33 0 128 11 62 3 64 8 2 0
2020-04-09 12:53:33 1 153 13 62 2 87 11 4 0
2020-04-10 12:38:35 0 137 9 71 9 64 0 2 0
2020-04-10 12:38:35 1 170 17 68 6 97 10 5 1
2020-04-11 12:38:34 0 144 7 72 1 69 5 3 1
2020-04-11 12:38:34 1 186 16 70 2 110 13 6 1
2020-04-12 13:23:34 0 147 3 77 5 67 -2 3 0
2020-04-12 13:23:34 1 197 11 73 3 116 6 8 2
2020-04-13 15:33:34 0 150 3 79 2 68 1 3 0
2020-04-13 15:33:34 1 215 18 73 0 132 16 10 2
2020-04-14 10:53:34 0 153 3 80 1 70 2 3 0
2020-04-14 10:53:34 1 219 4 73 0 136 4 10 0
2020-04-15 10:38:34 0 158 5 82 2 70 2 4 1
2020-04-15 10:38:34 1 223 4 75 2 138 2 10 0
2020-04-16 11:03:34 0 166 8 91 9 71 -2 4 0
2020-04-16 11:03:34 1 228 5 80 5 135 -3 13 3
2020-04-17 10:08:36 0 180 14 93 2 82 11 5 1
2020-04-17 10:08:37 1 235 7 81 1 141 6 13 0
2020-04-18 12:53:34 0 187 7 95 2 87 5 5 0
2020-04-18 12:53:35 1 242 7 85 4 144 3 13 0
2020-04-19 12:43:33 0 194 7 100 5 89 2 5 0
2020-04-19 12:43:34 1 257 15 89 4 155 11 13 0
2020-04-20 11:33:33 0 194 0 100 0 89 0 5 0
2020-04-20 11:33:34 1 260 3 97 8 147 -8 16 3
2020-04-21 13:50:30 0 196 2 102 2 89 0 5 0
2020-04-21 13:50:31 1 263 3 107 10 139 -8 17 1
2020-04-22 10:00:27 0 203 7 105 3 93 4 5 0
2020-04-22 10:00:28 1 270 7 116 9 137 -2 17 0
2020-04-23 11:31:51 0 207 4 107 2 94 1 6 1
2020-04-23 11:31:52 1 284 14 123 7 143 6 18 1
2020-04-24 12:09:26 0 209 2 109 2 94 0 6 0
2020-04-24 12:09:26 1 291 7 126 3 147 4 18 0
2020-04-25 11:34:25 0 220 11 112 3 102 8 6 0
2020-04-25 11:34:25 1 304 13 131 5 155 8 18 0
2020-04-26 11:44:24 0 226 6 116 4 104 2 6 0
2020-04-26 11:44:24 1 310 6 136 5 156 1 18 0
2020-04-27 09:54:24 0 226 0 117 1 103 -1 6 0
2020-04-27 09:54:25 1 311 1 136 0 157 1 18 0
2020-04-28 09:54:25 0 229 3 121 4 102 -1 6 0
2020-04-28 09:54:25 1 313 2 138 2 157 0 18 0
2020-04-29 11:04:25 0 248 19 123 2 119 17 6 0
2020-04-29 11:04:25 1 318 5 145 7 153 -4 20 0
2020-04-30 10:34:24 0 258 10 127 4 125 6 6 0
2020-04-30 10:34:24 1 324 6 171 26 131 -22 22 2
2020-05-01 12:09:25 0 266 8 144 17 116 -9 6 0
2020-05-01 12:09:25 1 329 5 181 10 125 -6 23 1
2020-05-02 12:01:20 0 272 6 148 4 118 2 6 0
2020-05-02 12:01:20 1 333 4 188 7 121 -4 24 1
2020-05-03 11:30:44 0 275 3 156 8 113 -5 6 0
2020-05-03 11:30:44 1 338 5 193 5 121 0 24 0
2020-05-04 10:15:07 0 278 3 157 1 115 2 6 0
2020-05-04 10:15:07 1 339 1 193 0 122 1 24 0
2020-05-05 10:45:07 0 279 1 161 4 112 -3 6 0
2020-05-05 10:45:07 1 339 0 195 2 120 -2 24 0
2020-05-06 10:28:31 0 283 4 166 5 111 -1 6 0
2020-05-06 10:28:31 1 350 11 200 5 126 6 24 0
2020-05-07 12:18:56 0 286 3 178 12 102 -9 6 0
2020-05-07 12:18:56 1 350 0 217 17 108 -18 25 1
2020-05-08 11:13:56 0 287 1 180 2 101 -1 6 0
2020-05-08 11:13:56 1 351 1 218 1 106 -2 27 2
2020-05-09 11:08:56 0 290 3 192 12 92 -9 6 0
2020-05-09 11:08:56 1 356 5 233 15 95 -11 28 1
#!/usr/bin/env python3
import pylab as plt
import pandas as pd
import matplotlib.dates as mdates
interest = {
'infected': 'Infiziert',
'recovered': 'Genesen',
'dead': 'Gestorben',
}
areas = {
0: 'Kassel Stadt',
1: 'Kassel Land',
}
formatter = mdates.DateFormatter('%Y-%b-%d')
df = pd.read_csv('covid-ks-2020-05-09.csv', parse_dates={'date': [0, 1]})
fig, ax = plt.subplots(len(interest), sharex=True)
for i, (k_i, l_i) in enumerate(interest.items()):
for k_a, l_a in areas.items():
ax[i].plot(df[df.county == k_a].date, df[df.county == k_a][k_i], label=l_a)
ax[i].set_title(l_i)
ax[i].xaxis_date()
ax[i].xaxis.set_major_formatter(formatter)
ax[i].legend()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment