|
5 | 5 | import os
|
6 | 6 | import re
|
7 | 7 | from urllib.parse import quote_plus as quote_as_url
|
| 8 | +import covidcast |
8 | 9 |
|
9 | 10 | import pandas as pd
|
10 | 11 | import requests
|
@@ -312,12 +313,12 @@ def fetch_listing(params):
|
312 | 313 | el for el in listing
|
313 | 314 | if start_date <= el['publish_date'] <= end_date
|
314 | 315 | ]
|
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 |
316 | 317 | # reports that are too early
|
317 | 318 | if 'export_start_date' in params['indicator']:
|
318 | 319 | listing = [
|
319 | 320 | 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'] |
321 | 322 | ]
|
322 | 323 | # can't do the same for export_end_date
|
323 | 324 | return listing
|
@@ -360,6 +361,23 @@ def nation_from_state(df, sig, geomapper):
|
360 | 361 |
|
361 | 362 | def fetch_new_reports(params, logger=None):
|
362 | 363 | """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 | + |
363 | 381 | listing = fetch_listing(params)
|
364 | 382 |
|
365 | 383 | # download and parse individual reports
|
|
0 commit comments