Skip to content

Commit 4b3f439

Browse files
committed
feat: support multiple source/signals at once
1 parent b223b4b commit 4b3f439

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/server/endpoints/covidcast.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ def handle_coverage():
500500
similar to /signal_dashboard_coverage for a specific signal returns the coverage (number of locations for a given geo_type)
501501
"""
502502

503-
signal_pair = parse_single_source_signal_arg("signal")
503+
signal = parse_source_signal_arg("signal")
504504
geo_type = request.args.get("geo_type", "county")
505505
if "window" in request.values:
506506
time_window = parse_day_range_arg("window")
@@ -513,16 +513,24 @@ def handle_coverage():
513513
time_window = (date_to_time_value(now - timedelta(days=last)), date_to_time_value(now))
514514

515515
q = QueryBuilder("covidcast", "c")
516-
q.fields = ["c.time_value", "count(c.geo_value) as count"]
516+
fields_string = ["source", "signal"]
517+
fields_int = ["time_value"]
518+
519+
q.set_fields(fields_string, fields_int)
520+
521+
# manually append the count column because of grouping
522+
fields_int.append("count")
523+
q.fields.append(f"count({q.alias}.geo_value) as count")
524+
517525
if geo_type == "only-county":
518526
q.where(geo_type="county")
519527
q.conditions.append('geo_value not like "%000"')
520528
else:
521529
q.where(geo_type=geo_type)
522-
q.where_source_signal_pairs("source", "signal", [signal_pair])
530+
q.where_source_signal_pairs("source", "signal", signal)
523531
q.where_time_pairs("time_type", "time_value", [TimePair("day", [time_window])])
524-
q.group_by = "c.time_value"
532+
q.group_by = "c.source, c.signal, c.time_value"
525533

526534
_handle_lag_issues_as_of(q, None, None, None)
527535

528-
return execute_query(q.query, q.params, [], ["time_value", "count"], [])
536+
return execute_query(q.query, q.params, fields_string, fields_int, [])

0 commit comments

Comments
 (0)