-
Notifications
You must be signed in to change notification settings - Fork 0
/
summarize.py
executable file
·79 lines (65 loc) · 2.26 KB
/
summarize.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
#!/usr/bin/env python3
import calendar
import sys
import pathogens
from pathogen_properties import Variable
MAX_ESTIMATES_FOR_PATHOGEN = 5
def pretty_date(estimate: Variable) -> str:
start_date, end_date = estimate.get_dates()
_, end_date_month_last_day = calendar.monthrange(
end_date.year, end_date.month
)
if start_date == end_date:
return str(start_date)
elif start_date.year != end_date.year:
return f"{start_date.year} to {end_date.year}"
elif (
start_date.month == 1
and start_date.day == 1
and end_date.month == 12
and end_date.day == 31
):
return str(start_date.year)
elif (
start_date.month == end_date.month
and start_date.day == 1
and end_date.day == end_date_month_last_day
):
return f"{start_date.year}-{start_date.month:02d}"
else:
return f"{start_date} to {end_date}"
def start(pathogen_names):
maximum = None if pathogen_names else MAX_ESTIMATES_FOR_PATHOGEN
for pathogen_name, pathogen in pathogens.pathogens.items():
if pathogen_names and pathogen_name not in pathogen_names:
continue
print(pathogen_name)
to_print = [] # key, line
def save(estimate: Variable, details: str):
taxid = ""
if estimate.taxid:
taxid = "; %s" % estimate.taxid
date = pretty_date(estimate)
location = estimate.summarize_location()
line = "%s (%s; %s%s)" % (
details.rjust(18),
location,
date,
taxid,
)
to_print.append(((location, date), line))
for estimate in pathogen.estimate_prevalences():
save(estimate, "%.2f per 100k" % estimate.infections_per_100k)
for estimate in pathogen.estimate_incidences():
save(
estimate,
"%.2f per 100k/y" % estimate.annual_infections_per_100k,
)
to_print.sort()
for _, line in to_print[:maximum]:
print(line)
skipped = 0 if not maximum else len(to_print[maximum:])
if skipped:
print(("+ %s more" % skipped).rjust(18))
if __name__ == "__main__":
start(sys.argv[1:])