Skip to content

Commit

Permalink
Add support for querying multiple signals; cmu-delphi/covidcast-indic…
Browse files Browse the repository at this point in the history
…ators#116

* backwards-compatible signal/signals parameter
* optional 'format' parameter for retrieving results as a tree (preferred by Viz) or as a flat list (backwards-compatible); defaults to flat list
* client support: coffee, js, R, py
* integration tests to check multi-signal queries and queries for tree format
  • Loading branch information
krivard committed Jul 30, 2020
1 parent cdc590a commit 28b9f8a
Show file tree
Hide file tree
Showing 11 changed files with 178 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ def test_caching(self):
'stdev_value': 0,
'max_issue': 20200423,
'min_lag': 0,
'max_lag': 1
'max_lag': 1,
}
])
epidata1={'result':1,'message':'success','epidata':epidata1}
epidata1={'result':1, 'message':'success', 'epidata':epidata1}

# make sure the API covidcast_meta is still blank, since it only serves
# the cached version and we haven't cached anything yet
epidata2 = Epidata.covidcast_meta()
self.assertEqual(epidata2['result'], -2)
self.assertEqual(epidata2['result'], -2, json.dumps(epidata2))

# update the cache
args = None
Expand Down
6 changes: 6 additions & 0 deletions integrations/acquisition/covidcast/test_csv_uploading.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def apply_lag(expected_epidata):
'stderr': 0.1,
'sample_size': 10,
'direction': None,
'signal': 'test',
},
{
'time_value': 20200419,
Expand All @@ -129,6 +130,7 @@ def apply_lag(expected_epidata):
'stderr': 0.3,
'sample_size': 30,
'direction': None,
'signal': 'test',
},
{
'time_value': 20200419,
Expand All @@ -137,6 +139,7 @@ def apply_lag(expected_epidata):
'stderr': 0.2,
'sample_size': 20,
'direction': None,
'signal': 'test',
},
]),
'message': 'success',
Expand All @@ -159,6 +162,7 @@ def apply_lag(expected_epidata):
'stderr': 0.01,
'sample_size': 100,
'direction': None,
'signal': 'wip_prototype',
},
{
'time_value': 20200419,
Expand All @@ -167,6 +171,7 @@ def apply_lag(expected_epidata):
'stderr': 0.02,
'sample_size': 200,
'direction': None,
'signal': 'wip_prototype',
},
{
'time_value': 20200419,
Expand All @@ -175,6 +180,7 @@ def apply_lag(expected_epidata):
'stderr': 0.03,
'sample_size': 300,
'direction': None,
'signal': 'wip_prototype',
},
]),
'message': 'success',
Expand Down
27 changes: 18 additions & 9 deletions integrations/acquisition/covidcast/test_direction_updating.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ def test_uploading(self):
'sample_size': 0,
'direction': None,
'issue': 20200228,
'lag': 0
'lag': 0,
'signal': 'sig',
},
{
'time_value': 20200229,
Expand All @@ -111,7 +112,8 @@ def test_uploading(self):
'sample_size': 0,
'direction': None,
'issue': 20200229,
'lag': 0
'lag': 0,
'signal': 'sig',
},
{
'time_value': 20200301,
Expand All @@ -121,7 +123,8 @@ def test_uploading(self):
'sample_size': 0,
'direction': 1,
'issue': 20200301,
'lag': 0
'lag': 0,
'signal': 'sig',
},
{
'time_value': 20200511,
Expand All @@ -131,7 +134,8 @@ def test_uploading(self):
'sample_size': 0,
'direction': None,
'issue': 20200511,
'lag': 0
'lag': 0,
'signal': 'sig',
},
{
'time_value': 20200512,
Expand All @@ -141,7 +145,8 @@ def test_uploading(self):
'sample_size': 0,
'direction': None,
'issue': 20200512,
'lag': 0
'lag': 0,
'signal': 'sig',
},
{
'time_value': 20200517,
Expand All @@ -151,7 +156,8 @@ def test_uploading(self):
'sample_size': 0,
'direction': 0,
'issue': 20200517,
'lag': 0
'lag': 0,
'signal': 'sig',
},
{
'time_value': 20200615,
Expand All @@ -161,7 +167,8 @@ def test_uploading(self):
'sample_size': 0,
'direction': None,
'issue': 20200615,
'lag': 0
'lag': 0,
'signal': 'sig',
},
{
'time_value': 20200616,
Expand All @@ -171,7 +178,8 @@ def test_uploading(self):
'sample_size': 0,
'direction': None,
'issue': 20200616,
'lag': 0
'lag': 0,
'signal': 'sig',
},
{
'time_value': 20200617,
Expand All @@ -181,7 +189,8 @@ def test_uploading(self):
'sample_size': 0,
'direction': 1,
'issue': 20200617,
'lag': 0
'lag': 0,
'signal': 'sig',
},
],
'message': 'success',
Expand Down
85 changes: 78 additions & 7 deletions integrations/client/test_delphi_epidata.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,85 @@ def tearDown(self):

def test_covidcast(self):
"""Test that the covidcast endpoint returns expected data."""

self.maxDiff=None

# insert dummy data
self.cur.execute('''
insert into covidcast values
(0, 'src', 'sig', 'day', 'county', 20200414, '01234',
123, 1.5, 2.5, 3.5, 456, 4, 20200414, 0),
(0, 'src', 'sig2', 'day', 'county', 20200414, '01234',
123, 1.5, 2.5, 3.5, 456, 4, 20200414, 0),
(0, 'src', 'sig', 'day', 'county', 20200414, '01234',
456, 5.5, 1.2, 10.5, 789, 0, 20200415, 1),
(0, 'src', 'sig', 'day', 'county', 20200414, '01234',
345, 6.5, 2.2, 11.5, 678, 0, 20200416, 2)
''')
self.cnx.commit()

# fetch data
response = Epidata.covidcast(
'src', ['sig','sig2'], 'day', 'county', 20200414, '01234')

# check result
self.assertEqual(response, {
'result': 1,
'epidata': [{
'time_value': 20200414,
'geo_value': '01234',
'value': 6.5,
'stderr': 2.2,
'sample_size': 11.5,
'direction': 0,
'issue': 20200416,
'lag': 2,
'signal': 'sig',
},{
'time_value': 20200414,
'geo_value': '01234',
'value': 1.5,
'stderr': 2.5,
'sample_size': 3.5,
'direction': 4,
'issue': 20200414,
'lag': 0,
'signal': 'sig2',
}],
'message': 'success',
})

# fetch data
response = Epidata.covidcast(
'src', ['sig','sig2'], 'day', 'county', 20200414, '01234', format='tree')

# check result
self.assertEqual(response, {
'result': 1,
'epidata': [{
'sig': [{
'time_value': 20200414,
'geo_value': '01234',
'value': 6.5,
'stderr': 2.2,
'sample_size': 11.5,
'direction': 0,
'issue': 20200416,
'lag': 2,
}],
'sig2': [{
'time_value': 20200414,
'geo_value': '01234',
'value': 1.5,
'stderr': 2.5,
'sample_size': 3.5,
'direction': 4,
'issue': 20200414,
'lag': 0,
}],
}],
'message': 'success',
})

# fetch data, without specifying issue or lag
response_1 = Epidata.covidcast(
'src', 'sig', 'day', 'county', 20200414, '01234')
Expand All @@ -73,7 +139,8 @@ def test_covidcast(self):
'sample_size': 11.5,
'direction': 0,
'issue': 20200416,
'lag': 2
'lag': 2,
'signal': 'sig',
}],
'message': 'success',
})
Expand All @@ -94,7 +161,8 @@ def test_covidcast(self):
'sample_size': 10.5,
'direction': 0,
'issue': 20200415,
'lag': 1
'lag': 1,
'signal': 'sig',
}],
'message': 'success',
})
Expand All @@ -115,7 +183,8 @@ def test_covidcast(self):
'sample_size': 3.5,
'direction': 4,
'issue': 20200414,
'lag': 0
'lag': 0,
'signal': 'sig',
}, {
'time_value': 20200414,
'geo_value': '01234',
Expand All @@ -124,7 +193,8 @@ def test_covidcast(self):
'sample_size': 10.5,
'direction': 0,
'issue': 20200415,
'lag': 1
'lag': 1,
'signal': 'sig',
}],
'message': 'success',
})
Expand All @@ -145,7 +215,8 @@ def test_covidcast(self):
'sample_size': 11.5,
'direction': 0,
'issue': 20200416,
'lag': 2
'lag': 2,
'signal': 'sig',
}],
'message': 'success',
})
Expand Down Expand Up @@ -189,7 +260,7 @@ def test_covidcast_meta(self):
'last_update': 345,
'max_issue': 20200416,
'min_lag': 1,
'max_lag': 2
'max_lag': 2,
}],
'message': 'success',
})
15 changes: 12 additions & 3 deletions integrations/server/test_covidcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ def test_round_trip(self):
'sample_size': 3.5,
'direction': 4,
'issue': 20200414,
'lag': 0
'lag': 0,
'signal': 'sig',
}],
'message': 'success',
})
Expand Down Expand Up @@ -125,6 +126,7 @@ def test_location_wildcard(self):
'direction': 13,
'issue': 20200414,
'lag': 0,
'signal': 'sig',
}, {
'time_value': 20200414,
'geo_value': '22222',
Expand All @@ -134,6 +136,7 @@ def test_location_wildcard(self):
'direction': 23,
'issue': 20200414,
'lag': 0,
'signal': 'sig',
}, {
'time_value': 20200414,
'geo_value': '33333',
Expand All @@ -142,7 +145,8 @@ def test_location_wildcard(self):
'sample_size': 32,
'direction': 33,
'issue': 20200414,
'lag': 0
'lag': 0,
'signal': 'sig',
},
],
'message': 'success',
Expand Down Expand Up @@ -195,6 +199,7 @@ def test_location_timeline(self):
'direction': 13,
'issue': 20200413,
'lag': 2,
'signal': 'sig',
}, {
'time_value': 20200412,
'geo_value': '01234',
Expand All @@ -204,6 +209,7 @@ def test_location_timeline(self):
'direction': 23,
'issue': 20200413,
'lag': 1,
'signal': 'sig',
}, {
'time_value': 20200413,
'geo_value': '01234',
Expand All @@ -213,6 +219,7 @@ def test_location_timeline(self):
'direction': 33,
'issue': 20200413,
'lag': 0,
'signal': 'sig',
},
],
'message': 'success',
Expand Down Expand Up @@ -280,6 +287,7 @@ def test_nullable_columns(self):
'direction': None,
'issue': 20200414,
'lag': 0,
'signal': 'sig',
}],
'message': 'success',
})
Expand Down Expand Up @@ -327,7 +335,8 @@ def test_temporal_partitioning(self):
'sample_size': 32,
'direction': 33,
'issue': 202016,
'lag': 0
'lag': 0,
'signal': 'sig',
}],
'message': 'success',
})
Loading

0 comments on commit 28b9f8a

Please sign in to comment.