@@ -500,7 +500,7 @@ def handle_coverage():
500
500
similar to /signal_dashboard_coverage for a specific signal returns the coverage (number of locations for a given geo_type)
501
501
"""
502
502
503
- signal_pair = parse_single_source_signal_arg ("signal" )
503
+ signal = parse_source_signal_arg ("signal" )
504
504
geo_type = request .args .get ("geo_type" , "county" )
505
505
if "window" in request .values :
506
506
time_window = parse_day_range_arg ("window" )
@@ -513,16 +513,24 @@ def handle_coverage():
513
513
time_window = (date_to_time_value (now - timedelta (days = last )), date_to_time_value (now ))
514
514
515
515
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
+
517
525
if geo_type == "only-county" :
518
526
q .where (geo_type = "county" )
519
527
q .conditions .append ('geo_value not like "%000"' )
520
528
else :
521
529
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 )
523
531
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"
525
533
526
534
_handle_lag_issues_as_of (q , None , None , None )
527
535
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