|
13 | 13 | from delphi_utils import (
|
14 | 14 | read_params,
|
15 | 15 | S3ArchiveDiffer,
|
16 |
| - add_prefix |
| 16 | + add_prefix, |
| 17 | + create_export_csv |
17 | 18 | )
|
18 | 19 |
|
| 20 | +from .data_tools import format_for_export |
19 | 21 | from .pull_api import GoogleHealthTrends, get_counts_states, get_counts_dma
|
20 | 22 | from .map_values import derived_counts_from_dma
|
21 |
| -from .export import export_csv |
22 | 23 | from .constants import (SIGNALS, RAW, SMOOTHED,
|
23 | 24 | MSA, HRR, STATE, DMA,
|
24 | 25 | PULL_START_DATE)
|
@@ -68,45 +69,37 @@ def run_module():
|
68 | 69 | logging.basicConfig(format="%(levelname)s:%(message)s", level=logging.INFO)
|
69 | 70 | logging.info("Creating data from %s through %s.", start_date, end_date)
|
70 | 71 |
|
| 72 | + # Dictionary mapping geo resolution to the data corresponding to that resolution. |
| 73 | + df_by_geo_res = {} |
| 74 | + |
71 | 75 | if not params["test"]:
|
72 | 76 | # setup class to handle API calls
|
73 | 77 | ght = GoogleHealthTrends(ght_key=ght_key)
|
74 | 78 |
|
75 | 79 | # read data frame version of the data
|
76 |
| - df_state = get_counts_states( |
| 80 | + df_by_geo_res[STATE] = get_counts_states( |
77 | 81 | ght, PULL_START_DATE, end_date, static_dir=static_dir, data_dir=data_dir
|
78 | 82 | )
|
79 |
| - df_dma = get_counts_dma( |
| 83 | + df_by_geo_res[DMA] = get_counts_dma( |
80 | 84 | ght, PULL_START_DATE, end_date, static_dir=static_dir, data_dir=data_dir
|
81 | 85 | )
|
82 | 86 | else:
|
83 |
| - df_state = pd.read_csv(params["test_data_dir"].format(geo_res="state")) |
84 |
| - df_dma = pd.read_csv(params["test_data_dir"].format(geo_res="dma")) |
| 87 | + df_by_geo_res[STATE] = pd.read_csv(params["test_data_dir"].format(geo_res="state")) |
| 88 | + df_by_geo_res[DMA] = pd.read_csv(params["test_data_dir"].format(geo_res="dma")) |
85 | 89 |
|
86 |
| - df_hrr, df_msa = derived_counts_from_dma(df_dma, static_dir=static_dir) |
| 90 | + df_by_geo_res[HRR], df_by_geo_res[MSA] = derived_counts_from_dma(df_by_geo_res[DMA], |
| 91 | + static_dir=static_dir) |
87 | 92 |
|
88 | 93 | signal_names = add_prefix(SIGNALS, wip_signal, prefix="wip_")
|
89 | 94 |
|
90 | 95 | for signal in signal_names:
|
91 |
| - if signal.endswith(SMOOTHED): |
92 |
| - # export each geographic region, with both smoothed and unsmoothed data |
93 |
| - export_csv(df_state, STATE, signal, smooth=True, |
94 |
| - start_date=start_date, receiving_dir=export_dir) |
95 |
| - export_csv(df_dma, DMA, signal, smooth=True, |
96 |
| - start_date=start_date, receiving_dir=export_dir) |
97 |
| - export_csv(df_hrr, HRR, signal, smooth=True, |
98 |
| - start_date=start_date, receiving_dir=export_dir) |
99 |
| - export_csv(df_msa, MSA, signal, smooth=True, |
100 |
| - start_date = start_date, receiving_dir=export_dir) |
101 |
| - elif signal.endswith(RAW): |
102 |
| - export_csv(df_state, STATE, signal, smooth=False, |
103 |
| - start_date=start_date, receiving_dir=export_dir) |
104 |
| - export_csv(df_dma, DMA, signal, smooth=False, |
105 |
| - start_date=start_date, receiving_dir=export_dir) |
106 |
| - export_csv(df_hrr, HRR, signal, smooth=False, |
107 |
| - start_date=start_date, receiving_dir=export_dir) |
108 |
| - export_csv(df_msa, MSA, signal, smooth=False, |
109 |
| - start_date=start_date, receiving_dir=export_dir) |
| 96 | + is_smoothed = signal.endswith(SMOOTHED) |
| 97 | + for geo_res, df in df_by_geo_res.items(): |
| 98 | + create_export_csv(format_for_export(df, is_smoothed), |
| 99 | + geo_res=geo_res, |
| 100 | + sensor=signal, |
| 101 | + start_date=start_date, |
| 102 | + export_dir=export_dir) |
110 | 103 |
|
111 | 104 | if not params["test"]:
|
112 | 105 | # Diff exports, and make incremental versions
|
|
0 commit comments