Skip to content

Commit 9839573

Browse files
committed
generate full history if any signal not in metadata
1 parent 672892c commit 9839573

File tree

1 file changed

+20
-2
lines changed
  • dsew_community_profile/delphi_dsew_community_profile

1 file changed

+20
-2
lines changed

dsew_community_profile/delphi_dsew_community_profile/pull.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
import re
77
from urllib.parse import quote_plus as quote_as_url
8+
import covidcast
89

910
import pandas as pd
1011
import requests
@@ -312,12 +313,12 @@ def fetch_listing(params):
312313
el for el in listing
313314
if start_date <= el['publish_date'] <= end_date
314315
]
315-
# reference date is guaranteed to be before publish date, so we can trim
316+
# reference date is guaranteed to be on or before publish date, so we can trim
316317
# reports that are too early
317318
if 'export_start_date' in params['indicator']:
318319
listing = [
319320
el for el in listing
320-
if params['indicator']['export_start_date'] < el['publish_date']
321+
if params['indicator']['export_start_date'] <= el['publish_date']
321322
]
322323
# can't do the same for export_end_date
323324
return listing
@@ -360,6 +361,23 @@ def nation_from_state(df, sig, geomapper):
360361

361362
def fetch_new_reports(params, logger=None):
362363
"""Retrieve, compute, and collate all data we haven't seen yet."""
364+
# Fetch metadata to check how recent each signal is
365+
metadata = covidcast.metadata()
366+
sensor_names = {
367+
SIGNALS[key][name_field]
368+
for key in params["indicator"]["export_signals"]
369+
for name_field in ["api_name", "api_prop_name"]
370+
if name_field in SIGNALS[key]
371+
}
372+
373+
# Filter to only those we currently want to produce, ignore any old or deprecated signals
374+
cpr_metadata = metadata[(metadata.data_source == "dsew-cpr") &
375+
(metadata.signal.isin(sensor_names))]
376+
377+
if sensor_names.difference(set(cpr_metadata.signal)):
378+
# If any signal not in metadata yet, we need to backfill its full history.
379+
params['indicator']['reports'] = 'all'
380+
363381
listing = fetch_listing(params)
364382

365383
# download and parse individual reports

0 commit comments

Comments
 (0)