8
8
import pandas as pd
9
9
from delphi_epidata import Epidata
10
10
11
- covidcast .covidcast ._ASYNC_CALL = True # pylint: disable=protected-access
11
+ from .date_utils import _date_to_api_string , _parse_datetimes
12
+
12
13
13
14
@dataclass
14
15
class Complaint :
@@ -34,6 +35,7 @@ def to_md(self):
34
35
message = self .message , updated = self .last_updated .strftime ("%Y-%m-%d" ))
35
36
36
37
38
+
37
39
def check_source (data_source , meta , params , grace , logger ): # pylint: disable=too-many-locals
38
40
"""Iterate over all signals from a source and check for problems.
39
41
@@ -74,30 +76,28 @@ def check_source(data_source, meta, params, grace, logger): # pylint: disable=t
74
76
signal = row ["signal" ],
75
77
start_day = start_date .strftime ("%Y-%m-%d" ),
76
78
end_day = end_date .strftime ("%Y-%m-%d" ),
77
- geo_type = row ["geo_type" ])
79
+ geo_type = row ["geo_type" ],
80
+ time_type = row ["time_type" ])
78
81
79
82
response = Epidata .covidcast (
80
83
data_source ,
81
84
row ["signal" ],
82
85
time_type = row ["time_type" ],
83
86
geo_type = row ["geo_type" ],
84
- time_values = Epidata .range (start_date . strftime ( "%Y%m%d" ), end_date . strftime ( "%Y%m%d" )),
87
+ time_values = Epidata .range (_date_to_api_string ( start_date ), _date_to_api_string ( end_date )),
85
88
geo_value = "*" ,
86
89
)
87
90
88
- if response ["result" ] != 1 :
89
- # Something failed in the API and we did not get real metadata
90
- raise RuntimeError ("Error when fetching signal data from the API" , response ["message" ])
91
-
92
- latest_data = pd .DataFrame .from_dict (response ["epidata" ])
93
- latest_data ["issue" ] = pd .to_datetime (latest_data ["issue" ], format = "%Y%m%d" )
94
- latest_data ["time_value" ] = pd .to_datetime (latest_data ["time_value" ], format = "%Y%m%d" )
95
- latest_data .drop ("direction" , axis = 1 , inplace = True )
96
-
97
- current_lag_in_days = (now - datetime .strptime (str (row ["max_time" ]), "%Y%m%d" )).days
91
+ current_lag_in_days = (now - row ["max_time" ]).days
98
92
lag_calculated_from_api = False
93
+ latest_data = None
94
+
95
+ if response ["result" ] == 1 :
96
+ latest_data = pd .DataFrame .from_dict (response ["epidata" ])
97
+ latest_data ["issue" ] = latest_data .apply (lambda x : _parse_datetimes (x .issue , x .time_type ), axis = 1 )
98
+ latest_data ["time_value" ] = latest_data .apply (lambda x : _parse_datetimes (x .time_value , x .time_type ), axis = 1 )
99
+ latest_data .drop ("direction" , axis = 1 , inplace = True )
99
100
100
- if latest_data is not None :
101
101
unique_dates = [pd .to_datetime (val ).date ()
102
102
for val in latest_data ["time_value" ].unique ()]
103
103
current_lag_in_days = (datetime .now ().date () - max (unique_dates )).days
0 commit comments