-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot.py
executable file
·125 lines (106 loc) · 4.21 KB
/
plot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env python3
import os
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import numpy
from datetime import datetime, timedelta
def url():
plt.gcf().text(0.11, 0.82, "https://wgrover.github.io/RUSD-COVID", fontsize=7)
plt.gcf().text(0.86, 0.05, "2023/24")
dates = []
elementarys = []
middles = []
highs = []
others = []
missed_dates = []
files = os.listdir("./data")
files.sort()
checked_dates = []
for filename in files:
if ".DS_Store" in filename:
continue
checked_dates.append(datetime.strptime(filename[:10], "%Y-%m-%d"))
print("\t\tElem\tMidd\tHigh\tOther\tSchools")
first_day = checked_dates[0]
print("\t\tFIRSTDAY ", first_day.strftime("%m/%d/%Y"))
last_day = checked_dates[-1]
print("\t\tLASTDAY ", last_day.strftime("%m/%d/%Y"))
num_days = (last_day - first_day).days + 1
all_dates = [first_day + timedelta(days=x) for x in range(num_days)]
for date in all_dates:
print(date.strftime("%m/%d/%Y"), end="\t")
if date in checked_dates:
dates.append(date)
infile = open("./data/" + date.strftime("%Y-%m-%d") + ".txt", "r")
elementary = 0
middle = 0
high = 0
other = 0
for line in infile:
id, cat, count, name = line.strip().split("\t")
count = int(count)
if cat == "E":
elementary += count
elif cat == "M":
middle += count
elif cat == "H":
high += count
elif cat == "O":
other += count
print(f"{elementary}\t{middle}\t{high}\t{other}\t{elementary+middle+high}")
elementarys.append(elementary)
middles.append(middle)
highs.append(high)
others.append(other)
else:
print("MISSED")
missed_dates.append(date)
schools = numpy.array(elementarys) + numpy.array(middles) + numpy.array(highs)
plt.figure(figsize=(6, 3), dpi=300)
plt.cla()
plt.bar(dates, schools, color="k")
span = plt.gca().get_ylim()[1] - plt.gca().get_ylim()[0]
plt.plot(missed_dates, [0.02*span] * len(missed_dates), "ro", markersize=2)
plt.title("Active COVID-19 cases at all RUSD schools (14-day rolling window)")
url()
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter("%b %e"))
for label in plt.gca().get_xticklabels(which='major'):
label.set(rotation=30, horizontalalignment='right')
plt.tight_layout()
plt.savefig("all_schools.png")
plt.cla()
plt.bar(dates, elementarys, color="b")
span = plt.gca().get_ylim()[1] - plt.gca().get_ylim()[0]
plt.plot(missed_dates, [0.02*span] * len(missed_dates), "ro", markersize=2)
plt.title("Active COVID-19 cases at elementary schools (14-day rolling window)")
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter("%b %e"))
for label in plt.gca().get_xticklabels(which='major'):
label.set(rotation=30, horizontalalignment='right')
plt.savefig("elementary_schools.png")
plt.cla()
plt.bar(dates, middles, color="green")
span = plt.gca().get_ylim()[1] - plt.gca().get_ylim()[0]
plt.plot(missed_dates, [0.02*span] * len(missed_dates), "ro", markersize=2)
plt.title("Active COVID-19 cases at middle schools (14-day rolling window)")
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter("%b %e"))
for label in plt.gca().get_xticklabels(which='major'):
label.set(rotation=30, horizontalalignment='right')
plt.savefig("middle_schools.png")
plt.cla()
plt.bar(dates, highs, color="orange")
span = plt.gca().get_ylim()[1] - plt.gca().get_ylim()[0]
plt.plot(missed_dates, [0.02*span] * len(missed_dates), "ro", markersize=2)
plt.title("Active COVID-19 cases at high schools (14-day rolling window)")
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter("%b %e"))
for label in plt.gca().get_xticklabels(which='major'):
label.set(rotation=30, horizontalalignment='right')
plt.savefig("high_schools.png")
plt.cla()
plt.bar(dates, others, color="0.80")
span = plt.gca().get_ylim()[1] - plt.gca().get_ylim()[0]
plt.plot(missed_dates, [0.02*span] * len(missed_dates), "ro", markersize=2)
plt.title("Active non-school COVID-19 cases (14-day rolling window)")
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter("%b %e"))
for label in plt.gca().get_xticklabels(which='major'):
label.set(rotation=30, horizontalalignment='right')
plt.savefig("others.png")