Skip to content

Commit 79f7429

Browse files
committed
switch rvdss to filter on epiweek col instead of time_value
1 parent 68f1735 commit 79f7429

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

integrations/server/test_rvdss.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# first party
22
from delphi.epidata.common.integration_test_base_class import DelphiTestBase
3-
import pdb
43

54

65
class rvdssTest(DelphiTestBase):
@@ -12,20 +11,20 @@ def localSetUp(self):
1211
def test_rvdss_repiratory_detections(self):
1312
"""Basic integration test for rvdss endpoint"""
1413
self.cur.execute(
15-
"INSERT INTO `rvdss`(`epiweek`, `time_value`,`time_type`, `issue`, `geo_type`, `geo_value`, `sarscov2_tests`, `sarscov2_positive_tests`, `sarscov2_pct_positive`, `flu_tests`, `flu_positive_tests`, `flu_pct_positive`, `fluah1n1pdm09_positive_tests`, `fluah3_positive_tests`, `fluauns_positive_tests`, `flua_positive_tests`, `flua_tests`, `flua_pct_positive`, `flub_positive_tests`, `flub_tests`, `flub_pct_positive`, `rsv_tests`, `rsv_positive_tests`, `rsv_pct_positive`, `hpiv_tests`, `hpiv1_positive_tests`, `hpiv2_positive_tests`, `hpiv3_positive_tests`, `hpiv4_positive_tests`, `hpivother_positive_tests`, `hpiv_positive_tests`, `hpiv_pct_positive`, `adv_tests`, `adv_positive_tests`, `adv_pct_positive`, `hmpv_tests`, `hmpv_positive_tests`, `hmpv_pct_positive`, `evrv_tests`, `evrv_positive_tests`, `evrv_pct_positive`, `hcov_tests`, `hcov_positive_tests`, `hcov_pct_positive`, `year`) VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
16-
(201212,20120412,"week","2012-04-17",'province','on',10,1,10,20, 10, 50, 1, 1, 1, 5, 20, 25, 4, 20, 20, 30, 3, 10, 40, 2, 2, 2, 1, 1, 8, 20, 40, 16, 40, 10, 2, 20, 1, 0, 0, 24, 3, 12.5, 2012),
14+
"INSERT INTO `rvdss` (`epiweek`, `time_value`,`time_type`, `issue`, `geo_type`, `geo_value`, `sarscov2_tests`, `sarscov2_positive_tests`, `sarscov2_pct_positive`, `flu_tests`, `flu_positive_tests`, `flu_pct_positive`, `fluah1n1pdm09_positive_tests`, `fluah3_positive_tests`, `fluauns_positive_tests`, `flua_positive_tests`, `flua_tests`, `flua_pct_positive`, `flub_positive_tests`, `flub_tests`, `flub_pct_positive`, `rsv_tests`, `rsv_positive_tests`, `rsv_pct_positive`, `hpiv_tests`, `hpiv1_positive_tests`, `hpiv2_positive_tests`, `hpiv3_positive_tests`, `hpiv4_positive_tests`, `hpivother_positive_tests`, `hpiv_positive_tests`, `hpiv_pct_positive`, `adv_tests`, `adv_positive_tests`, `adv_pct_positive`, `hmpv_tests`, `hmpv_positive_tests`, `hmpv_pct_positive`, `evrv_tests`, `evrv_positive_tests`, `evrv_pct_positive`, `hcov_tests`, `hcov_positive_tests`, `hcov_pct_positive`, `year`) VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
15+
(201212,20120412,"week",20120417,'province','on',10,1,10,20, 10, 50, 1, 1, 1, 5, 20, 25, 4, 20, 20, 30, 3, 10, 40, 2, 2, 2, 1, 1, 8, 20, 40, 16, 40, 10, 2, 20, 1, 0, 0, 24, 3, 12.5, 2012),
1716
)
1817
self.cnx.commit()
19-
pdb.set_trace()
20-
response = self.epidata_client.rvdss(geo_type="province", time_values = 20120412,geo_value="on")
18+
19+
response = self.epidata_client.rvdss(geo_type="province", time_values = 201212,geo_value="on")
2120
self.assertEqual(
2221
response,
2322
{
2423
"epidata": [
2524
{ "epiweek":201212,
2625
"time_value":20120412,
2726
"time_type":"week",
28-
"issue":"2012-04-17",
27+
"issue":20120417,
2928
"geo_type":"province",
3029
"geo_value":"on",
3130
"sarscov2_tests":10,

src/server/_query.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -483,14 +483,23 @@ def apply_issues_filter(self, history_table: str, issues: Optional[TimeValues])
483483
self.where_integers("issue", issues)
484484
return self
485485

486-
# Note: This function was originally only used by covidcast, so it assumed
487-
# that `source` and `signal` columns are always available. To make this usable
488-
# for rvdss, too, which doesn't have the `source` or `signal` columns, add the
489-
# `use_source_signal` flag to toggle inclusion of `source` and `signal` columns.
486+
# Note: This function was originally only used by covidcast. We also want
487+
# to use this function for rvdss, which doesn't meet all the assumptions
488+
# of the function.
490489
#
491-
# `use_source_signal` defaults to True so if not passed, the function
492-
# retains the historical behavior.
493-
def apply_as_of_filter(self, history_table: str, as_of: Optional[int], use_source_signal: Optional[bool] = True) -> "QueryBuilder":
490+
# The function assumes that `source` and `signal` columns are always
491+
# available, and that `time_value` is the name of the time field.
492+
#
493+
# `rvdss` doesn't have `source` or `signal` columns, so add the
494+
# `use_source_signal` flag to toggle inclusion of `source` and `signal`
495+
# columns. `use_source_signal` defaults to True so if not passed, the
496+
# function retains the historical behavior.
497+
#
498+
# `rvdss` uses `epiweek` as the time field, so let the user set the name
499+
# of the time column with`time_value_field`. `time_value_field` defaults
500+
# to `time_value`, so if not passed, the function retains the historical
501+
# behavior.
502+
def apply_as_of_filter(self, history_table: str, as_of: Optional[int], time_value_field: Optional[str] = "time_value", use_source_signal: Optional[bool] = True) -> "QueryBuilder":
494503
if as_of is not None:
495504
self.retable(history_table)
496505
sub_condition_asof = "(issue <= :as_of)"
@@ -503,9 +512,9 @@ def apply_as_of_filter(self, history_table: str, as_of: Optional[int], use_sourc
503512
source_signal_plain = ", `source`, `signal`"
504513
source_signal_alias = f" AND x.source = {alias}.source AND x.signal = {alias}.signal"
505514

506-
sub_fields = f"max(issue) max_issue, time_type, time_value{source_signal_plain}, geo_type, geo_value"
507-
sub_group = f"time_type, time_value{source_signal_plain}, geo_type, geo_value"
508-
sub_condition = f"x.max_issue = {alias}.issue AND x.time_type = {alias}.time_type AND x.time_value = {alias}.time_value{source_signal_alias} AND x.geo_type = {alias}.geo_type AND x.geo_value = {alias}.geo_value"
515+
sub_fields = f"max(issue) max_issue, time_type, {time_value_field}{source_signal_plain}, geo_type, geo_value"
516+
sub_group = f"time_type, {time_value_field}{source_signal_plain}, geo_type, geo_value"
517+
sub_condition = f"x.max_issue = {alias}.issue AND x.time_type = {alias}.time_type AND x.{time_value_field} = {alias}.{time_value_field}{source_signal_alias} AND x.geo_type = {alias}.geo_type AND x.geo_value = {alias}.geo_value"
509518
self.subquery = f"JOIN (SELECT {sub_fields} FROM {self.table} WHERE {self.conditions_clause} AND {sub_condition_asof} GROUP BY {sub_group}) x ON {sub_condition}"
510519
return self
511520

src/server/endpoints/rvdss.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ def handle():
8787
if not (len(geo_values) == 1 and geo_values[0] == "*"):
8888
q.where_strings("geo_value", geo_values)
8989

90-
q.apply_time_filter("time_type", "time_value", time_set)
90+
q.apply_time_filter("time_type", "epiweek", time_set)
9191
q.apply_issues_filter(db_table_name, issues)
92-
q.apply_as_of_filter(db_table_name, as_of, use_source_signal = False)
92+
q.apply_as_of_filter(db_table_name, as_of, time_value_field = "epiweek", use_source_signal = False)
9393

9494
# send query
9595
return execute_query(str(q), q.params, fields_string, fields_int, fields_float)

0 commit comments

Comments
 (0)