|
1 | 1 | from typing import List, Optional, Union, Tuple, Dict, Any, Set
|
2 | 2 | from itertools import groupby
|
3 |
| -from datetime import date, datetime |
| 3 | +from datetime import date, datetime, timedelta |
4 | 4 | from flask import Blueprint, request
|
5 | 5 | from flask.json import loads, jsonify
|
6 | 6 | from bisect import bisect_right
|
@@ -150,7 +150,6 @@ def handle():
|
150 | 150 | q.set_order("source", "signal", "time_type", "time_value", "geo_type", "geo_value", "issue")
|
151 | 151 | q.set_fields(fields_string, fields_int, fields_float)
|
152 | 152 |
|
153 |
| - |
154 | 153 | # basic query info
|
155 | 154 | # data type of each field
|
156 | 155 | # build the source, signal, time, and location (type and id) filters
|
@@ -493,3 +492,33 @@ def handle_meta():
|
493 | 492 | entry.intergrate(row)
|
494 | 493 |
|
495 | 494 | return jsonify([r.asdict() for r in out.values()])
|
| 495 | + |
| 496 | + |
| 497 | +@bp.route("/coverage", methods=("GET", "POST")) |
| 498 | +def handle_coverage(): |
| 499 | + """ |
| 500 | + similar to /signal_dashboard_coverage for a specific signal returns the coverage (number of locations for a given geo_type) |
| 501 | + """ |
| 502 | + |
| 503 | + signal_pair = parse_single_source_signal_arg("signal") |
| 504 | + geo_type = request.args.get("geo_type", "county") |
| 505 | + if "window" in request.values: |
| 506 | + time_window = parse_day_range_arg("window") |
| 507 | + else: |
| 508 | + now = date.today() |
| 509 | + time_window = (date_to_time_value(now - timedelta(days=30)), date_to_time_value(now)) |
| 510 | + |
| 511 | + q = QueryBuilder("covidcast", "c") |
| 512 | + q.fields = ["c.time_value", "count(c.geo_value) as count"] |
| 513 | + if geo_type == "only-county": |
| 514 | + q.where(geo_type="county") |
| 515 | + q.conditions.append('geo_value not like "%000"') |
| 516 | + else: |
| 517 | + q.where(geo_type=geo_type) |
| 518 | + q.where_source_signal_pairs("source", "signal", [signal_pair]) |
| 519 | + q.where_time_pairs("time_type", "time_value", [TimePair("day", [time_window])]) |
| 520 | + q.group_by = "c.time_value" |
| 521 | + |
| 522 | + _handle_lag_issues_as_of(q, None, None, None) |
| 523 | + |
| 524 | + return execute_query(q.query, q.params, [], ["time_value", "count"], []) |
0 commit comments