4
4
from freezegun import freeze_time
5
5
from conftest import TEST_DIR , NEW_DATE
6
6
7
+ import covidcast
8
+
7
9
from delphi_utils .validator .utils import lag_converter
8
10
from delphi_google_symptoms .constants import FULL_BKFILL_START_DATE
9
11
from delphi_google_symptoms .date_utils import generate_query_dates , generate_num_export_days , generate_patch_dates
12
+
13
+
10
14
class TestDateUtils :
11
15
12
16
@freeze_time ("2021-01-05" )
@@ -36,57 +40,77 @@ def test_generate_query_dates_custom(self):
36
40
assert set (output ) == set (expected )
37
41
38
42
def test_generate_export_dates (self , params , logger , monkeypatch ):
39
- import covidcast
40
43
metadata_df = pd .read_csv (f"{ TEST_DIR } /test_data/covid_metadata.csv" )
41
44
monkeypatch .setattr (covidcast , "metadata" , lambda : metadata_df )
42
- num_export_days = generate_num_export_days (params , logger )
43
45
46
+ num_export_days = generate_num_export_days (params , logger )
44
47
expected_num_export_days = params ["indicator" ]["num_export_days" ]
45
-
46
48
assert num_export_days == expected_num_export_days
47
49
48
50
def test_generate_export_dates_normal (self , params_w_no_date , logger , monkeypatch ):
49
- import covidcast
50
51
metadata_df = pd .read_csv (f"{ TEST_DIR } /test_data/covid_metadata.csv" )
51
52
monkeypatch .setattr (covidcast , "metadata" , lambda : metadata_df )
53
+
52
54
num_export_days = generate_num_export_days (params_w_no_date , logger )
53
55
54
- max_expected_lag = lag_converter (params_w_no_date ["validation" ]["common" ]. get ( "max_expected_lag" , { "all" : 4 }) )
56
+ max_expected_lag = lag_converter (params_w_no_date ["validation" ]["common" ][ "max_expected_lag" ] )
55
57
global_max_expected_lag = max (list (max_expected_lag .values ()))
56
- expected_num_export_days = params_w_no_date ["validation" ]["common" ]. get ( "span_length" , 14 ) + global_max_expected_lag
58
+ expected_num_export_days = params_w_no_date ["validation" ]["common" ][ "span_length" ] + global_max_expected_lag
57
59
58
60
assert num_export_days == expected_num_export_days
59
61
60
62
def test_generate_export_date_missing (self , params_w_no_date , logger , monkeypatch ):
61
- import covidcast
62
63
metadata_df = pd .read_csv (f"{ TEST_DIR } /test_data/covid_metadata_missing.csv" )
63
64
monkeypatch .setattr (covidcast , "metadata" , lambda : metadata_df )
65
+
64
66
num_export_days = generate_num_export_days (params_w_no_date , logger )
65
67
expected_num_export_days = (date .today () - FULL_BKFILL_START_DATE .date ()).days + 1
66
68
assert num_export_days == expected_num_export_days
67
69
68
- def test_generate_patch_dates (self , params_w_patch , logger , monkeypatch ):
69
- import covidcast
70
- metadata_df = pd .read_csv (f"{ TEST_DIR } /test_data/covid_metadata_missing.csv" )
71
- monkeypatch .setattr (covidcast , "metadata" , lambda : metadata_df )
72
- max_expected_lag = lag_converter (params_w_patch ["validation" ]["common" ].get ("max_expected_lag" , {"all" : 4 }))
70
+ def generate_expected_start_end_dates (self , params_ , issue_date ):
71
+ # Actual dates reported on issue dates June 27-29, 2024, by the old
72
+ # version of the google-symptoms indicator
73
+ # (https://github.com/cmu-delphi/covidcast-indicators/tree/b338a0962bf3a63f70a83f0b719516f914b098e2).
74
+ # The patch module should be able to recreate these dates.
75
+ dates_dict = {
76
+ "2024-06-27" : [ '2024-06-02' , '2024-06-03' , '2024-06-04' , '2024-06-05' , '2024-06-06' , '2024-06-07' , '2024-06-08' , '2024-06-09' , '2024-06-10' , '2024-06-11' , '2024-06-12' , '2024-06-13' , '2024-06-14' , '2024-06-15' , '2024-06-16' , '2024-06-17' , '2024-06-18' , '2024-06-19' , '2024-06-20' , '2024-06-21' , '2024-06-22' ],
77
+ "2024-06-28" : ['2024-06-03' , '2024-06-04' , '2024-06-05' , '2024-06-06' , '2024-06-07' , '2024-06-08' , '2024-06-09' , '2024-06-10' , '2024-06-11' , '2024-06-12' , '2024-06-13' , '2024-06-14' , '2024-06-15' , '2024-06-16' , '2024-06-17' , '2024-06-18' , '2024-06-19' , '2024-06-20' , '2024-06-21' , '2024-06-22' , '2024-06-23' ],
78
+ "2024-06-29" : ['2024-06-04' , '2024-06-05' , '2024-06-06' ,'2024-06-07' , '2024-06-08' , '2024-06-09' , '2024-06-10' , '2024-06-11' , '2024-06-12' , '2024-06-13' , '2024-06-14' , '2024-06-15' , '2024-06-16' , '2024-06-17' , '2024-06-18' , '2024-06-19' , '2024-06-20' , '2024-06-21' , '2024-06-22' , '2024-06-23' , '2024-06-24' ],
79
+ }
80
+
81
+ dates_dict = {
82
+ datetime .strptime (key , "%Y-%m-%d" ): [
83
+ datetime .strptime (listvalue , "%Y-%m-%d" ) for listvalue in value
84
+ ] for key , value in dates_dict .items ()
85
+ }
86
+
87
+ dates = dates_dict [issue_date ]
88
+
89
+ # Raw signals add 6 extra dates of padding for later calculating
90
+ # smoothed signals. Since this test is checking an early step in the
91
+ # process, before padding has happened, we can drop the first 6
92
+ # dates.
93
+ return {
94
+ "export_start_date" : min (dates [6 :21 ]),
95
+ "export_end_date" : max (dates [6 :21 ])
96
+ }
97
+
98
+ def test_generate_patch_dates (self , params_w_patch , logger ):
99
+ max_expected_lag = lag_converter (params_w_patch ["validation" ]["common" ]["max_expected_lag" ])
73
100
global_max_expected_lag = max (list (max_expected_lag .values ()))
74
- expected_num_export_days = params_w_patch ["validation" ]["common" ]. get ( "span_length" , 14 ) + global_max_expected_lag
101
+ num_export_days = params_w_patch ["validation" ]["common" ][ "span_length" ]
75
102
76
103
issue_date = datetime .strptime (params_w_patch ["patch" ]["start_issue" ], "%Y-%m-%d" )
77
104
end_issue = datetime .strptime (params_w_patch ["patch" ]["end_issue" ], "%Y-%m-%d" )
78
105
79
106
patch_date_dict = generate_patch_dates (params_w_patch )
80
107
81
108
while issue_date <= end_issue :
82
- expected_daterange = generate_query_dates (
83
- FULL_BKFILL_START_DATE ,
84
- issue_date ,
85
- expected_num_export_days ,
86
- False
87
- )
88
109
# in the patch script the date generated by generate_patch_dates becomes the export_start_date and export_end_date
89
- export_start_date , export_end_date = patch_date_dict [issue_date ]
90
- actual_daterange = generate_query_dates (export_start_date , export_end_date , expected_num_export_days , True )
91
- assert set (actual_daterange ) == set (expected_daterange )
92
- issue_date += timedelta (days = 1 )
110
+ patch_settings = patch_date_dict [issue_date ]
111
+ expected_dict = self .generate_expected_start_end_dates (params_w_patch , issue_date )
112
+ expected_dict ["num_export_days" ] = num_export_days # unmodified
113
+
114
+ assert patch_settings == expected_dict
115
+
116
+ issue_date += timedelta (days = 1 )
0 commit comments