-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
192 lines (155 loc) · 5.54 KB
/
main.py
File metadata and controls
192 lines (155 loc) · 5.54 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# -*- coding: utf-8 -*-
from lib.l0_importBiominers import L0ImportBiominers
from lib.l1_importOthers import L1ImportOthers
from lib.l2_mergeTogether import L2MergeTogether
from lib.l3_generateArcData import L3GenerateArcData
from lib.l4_plots import L4Plots, PostprocessingDashboard, SlopesChisquaredDashboardDetailed, SlopesChisquaredDashboardSimple
from lib.l4_plots.p5_global_scatter import GlobalScatterplots
from lib.l5_generateTable import L5GenerateTable
# Enable debug level messages
# I used this section to see debug messages during the l0 run
# Used as: NOTIONPY_LOG_LEVEL=debug LOG_LEVEL=debug python3 main.py ...
# But definitely can be simplified. Anyway, in the end, it was an internet problem
# https://stackoverflow.com/a/16043023/4126114
#import os
#import logging
#logging.basicConfig() # you need to initialize logging, otherwise you will not see anything from requests
#logging.getLogger().setLevel(logging.DEBUG)
#requests_log = logging.getLogger("requests.packages.urllib3")
#requests_log.propagate = True
#print(os.environ.get("NOTIONPY_LOG_LEVEL"))
#print(os.environ.get("LOG_LEVEL"))
#from notion.logger import enable_debugging
#enable_debugging()
#
#logging.getLogger("requests").setLevel(logging.DEBUG)
#logging.getLogger("notion").setLevel(logging.DEBUG)
#logging.getLogger("requests.packages.urllib3").setLevel(logging.DEBUG)
#logging.getLogger("urllib3").setLevel(logging.DEBUG)
#logging.getLogger("urllib").setLevel(logging.DEBUG)
#
#
#for key in logging.Logger.manager.loggerDict:
# print(key)
# logging.getLogger(key).setLevel(logging.DEBUG)
import click
@click.group()
def cli():
pass
@cli.command()
@click.argument('notion_fn')
@click.argument('fn_biominers')
def l0_importBiominers(notion_fn, fn_biominers):
"""
Read all the data from the notion.so tables and dump into a csv
Requires the notion.so unofficial API key
Original notebook is:
t11-shadi-collect notion tables of total tests.ipynb
https://colab.research.google.com/drive/1y0DWBLeLoKfLCw0G0E5QeXa4OdRv228Z
"""
# notion_fn="notion-shadiakiki1986-token_v2.txt"
# fn_biominers = "multiple-biominers-gitrepo.csv"
factory = L0ImportBiominers()
factory.get_notion_token(notion_fn)
factory.fetch_tables()
factory.to_csv(fn_biominers)
@cli.command()
@click.argument('dir_gitrepo')
@click.option("--skip-download", is_flag=True, default=False)
def l1_importOthers(dir_gitrepo, skip_download):
"""
Read data from other non-biominer sources
Original notebook at
t11b-shadi-collect biominers and non-biominers sources.ipynb
https://colab.research.google.com/drive/1yN-HGiOJzMDXnaimHZ96yUBT7bU38A94
"""
factory = L1ImportOthers(dir_gitrepo, do_download = not skip_download)
factory.get_jhu_conf_deaths()
factory.get_owid_roser()
factory.get_owid_ortiz()
factory.get_covidtracking_usa()
factory.get_wikipedia()
factory.get_worldometers()
factory.get_biominers()
factory.merge_all()
factory.aggregate_and_to_csv()
factory.one_field()
factory.drop_outlaws()
factory.to_csv_subcols()
factory.to_csv_all()
@cli.command()
@click.argument('dir_gitrepo')
def l2_mergeTogether(dir_gitrepo):
"""
Merge tests data with confirmed cases data and population
From notebook: t11c2-shadi-merge with confirmed cases and population.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1XeMityBlecPV8kyatsoIy82Zml8qyr8Y
"""
factory = L2MergeTogether(dir_gitrepo)
factory.read_confirmed_cases()
factory.replace_wrong_conf()
factory.check_no_conf_dips()
factory.read_totaltests()
factory.merge_conf_total()
factory.drop_outlaws()
factory.merge_country_meta()
factory.export_count_per_source()
factory.add_supplementary_stats()
factory.to_csv_interpolated()
factory.to_csv_historical()
factory.to_csv_latestOnly()
@cli.command()
@click.argument('dir_gitrepo')
def l3_generateArcData(dir_gitrepo):
"""
Convert data from l2 csv files into format suitable for our dashboard on arcgis.com
"""
factory = L3GenerateArcData(dir_gitrepo)
factory.read_l2_historical()
factory.calculate_stats()
factory.write_latest()
factory.write_dailyStacked()
factory.write_chisquared()
@cli.command()
@click.argument('dir_gitrepo')
@click.argument('dir_plot_destination')
def l4_plots(dir_gitrepo, dir_plot_destination):
"""
Generate plots, eg figure of stacked number of countries/states per day per source
"""
# Deprecated as of 2020-06-16
#f5 = GlobalScatterplots()
#f5.read_csv(dir_gitrepo)
#f5.create_layout()
#f5.to_html(dir_plot_destination)
#----------
f3d = SlopesChisquaredDashboardDetailed()
f3d.read_csv(dir_gitrepo)
from os.path import join
print("Saving l4/chisquared-postprocessed.csv")
f3d.df_chisq.to_csv(join(dir_gitrepo, "l4-analysis", "chisquared-postprocessed.csv"), index=False)
f3d.to_html(dir_plot_destination)
#----------
f3s = SlopesChisquaredDashboardSimple()
f3s.read_csv(dir_gitrepo)
f3s.to_html(dir_plot_destination)
f2 = PostprocessingDashboard()
f2.read_csv(dir_gitrepo)
f2.to_html(dir_plot_destination)
factory = L4Plots()
factory.read_csv(dir_gitrepo)
factory.prep_plots()
#factory.plot_line(dir_plot_destination)
factory.plot_stacked(dir_plot_destination)
@cli.command()
@click.argument('dir_gitrepo')
@click.argument('dir_plot_destination')
def l5_generateTable(dir_gitrepo, dir_plot_destination):
factory = L5GenerateTable()
factory.read_csv(dir_gitrepo)
factory.to_html(dir_plot_destination)
print("Saved html")
if __name__ == '__main__':
cli()