6
6
# standard packages
7
7
import logging
8
8
from multiprocessing import Pool , cpu_count
9
- from delphi_utils import GeoMapper , S3ArchiveDiffer , read_params , add_prefix
10
9
11
10
# third party
12
11
import numpy as np
13
12
import pandas as pd
13
+ from delphi_utils import GeoMapper , read_params , add_prefix
14
+
14
15
# first party
15
16
from .config import Config , Constants
17
+ from .constants import SIGNALS , SMOOTHED , SMOOTHED_ADJ , NA
16
18
from .load_data import load_combined_data
17
19
from .sensor import CHCSensor
18
20
from .weekday import Weekday
19
- from .constants import SIGNALS , SMOOTHED , SMOOTHED_ADJ , NA
20
21
21
22
22
23
def write_to_csv (output_dict , write_se , out_name , output_path = "." ):
@@ -28,7 +29,7 @@ def write_to_csv(output_dict, write_se, out_name, output_path="."):
28
29
output_path: outfile path to write the csv (default is current directory)
29
30
"""
30
31
if write_se :
31
- logging .info (f "========= WARNING: WRITING SEs TO { out_name } =========" )
32
+ logging .info ("========= WARNING: WRITING SEs TO {0 } =========" . format ( out_name ) )
32
33
geo_level = output_dict ["geo_level" ]
33
34
dates = output_dict ["dates" ]
34
35
geo_ids = output_dict ["geo_ids" ]
@@ -52,7 +53,9 @@ def write_to_csv(output_dict, write_se, out_name, output_path="."):
52
53
assert not np .isnan (sensor ), "value for included sensor is nan"
53
54
assert not np .isnan (se ), "se for included sensor is nan"
54
55
if sensor > 90 :
55
- logging .warning (f"value suspiciously high, { geo_id } : { sensor } " )
56
+ logging .warning ("value suspiciously high, {0}: {1}" .format (
57
+ geo_id , sensor
58
+ ))
56
59
assert se < 5 , f"se suspiciously high, { geo_id } : { se } "
57
60
if write_se :
58
61
assert sensor > 0 and se > 0 , "p=0, std_err=0 invalid"
@@ -64,10 +67,12 @@ def write_to_csv(output_dict, write_se, out_name, output_path="."):
64
67
"%s,%f,%s,%s,%s\n " % (geo_id , sensor , NA , NA , NA )
65
68
)
66
69
out_n += 1
67
- logging .debug (f"wrote { out_n } rows for { len (geo_ids )} { geo_level } " )
70
+ logging .debug ("wrote {0} rows for {1} {2}" .format (
71
+ out_n , len (geo_ids ), geo_level
72
+ ))
68
73
69
74
70
- class CHCSensorUpdator :
75
+ class CHCSensorUpdator : # pylint: disable=too-many-instance-attributes
71
76
"""Contains methods to update sensor and write results to csv
72
77
"""
73
78
@@ -136,7 +141,9 @@ def geo_reindex(self, data):
136
141
geo = self .geo
137
142
gmpr = GeoMapper ()
138
143
if geo not in {"county" , "state" , "msa" , "hrr" }:
139
- logging .error (f"{ geo } is invalid, pick one of 'county', 'state', 'msa', 'hrr'" )
144
+ logging .error ("{0} is invalid, pick one of 'county', 'state', 'msa', 'hrr'" .format (
145
+ geo
146
+ ))
140
147
return False
141
148
if geo == "county" :
142
149
data_frame = gmpr .fips_to_megacounty (data ,
@@ -203,7 +210,7 @@ def update_sensor(self,
203
210
sensor_include [geo_id ] = np .array (res .loc [final_sensor_idxs ,"incl" ])
204
211
else :
205
212
n_cpu = min (10 , cpu_count ())
206
- logging .debug (f "starting pool with { n_cpu } workers" )
213
+ logging .debug ("starting pool with {0 } workers" . format ( n_cpu ) )
207
214
with Pool (n_cpu ) as pool :
208
215
pool_results = []
209
216
for geo_id , sub_data in data_frame .groupby (level = 0 ,as_index = False ):
@@ -235,30 +242,4 @@ def update_sensor(self,
235
242
# write out results
236
243
for signal in self .updated_signal_names :
237
244
write_to_csv (output_dict , self .se , signal , outpath )
238
- logging .debug (f"wrote files to { outpath } " )
239
- '''
240
- params = read_params()
241
-
242
- arch_diff = S3ArchiveDiffer(
243
- params["cache_dir"],
244
- params["export_dir"],
245
- params["bucket_name"], "chc",
246
- params["aws_credentials"])
247
- arch_diff.update_cache()
248
-
249
- _, common_diffs, new_files = arch_diff.diff_exports()
250
-
251
- # Archive changed and new files only
252
- to_archive = [f for f, diff in common_diffs.items() if diff is not None]
253
- to_archive += new_files
254
- _, fails = arch_diff.archive_exports(to_archive)
255
- print(fails)
256
-
257
- # Filter existing exports to exclude those that failed to archive
258
- succ_common_diffs = {f: diff for f, diff in common_diffs.items() if f not in fails}
259
- arch_diff.filter_exports(succ_common_diffs)
260
-
261
- # Report failures: someone should probably look at them
262
- for exported_file in fails:
263
- print(f"Failed to archive '{exported_file}'")
264
- '''
245
+ logging .debug ("wrote files to {0}" .format (outpath ))
0 commit comments