Skip to content

Commit dec69c4

Browse files
authored
Merge pull request #245 from sgratzl/sgratzl/geo_values_clients
add geo_values support in raw clients
2 parents ede6632 + d001359 commit dec69c4

File tree

5 files changed

+109
-8
lines changed

5 files changed

+109
-8
lines changed

integrations/client/test_delphi_epidata.py

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def tearDown(self):
4646
def test_covidcast(self):
4747
"""Test that the covidcast endpoint returns expected data."""
4848
self.maxDiff=None
49-
49+
5050
# insert dummy data
5151
self.cur.execute('''
5252
insert into covidcast values
@@ -123,7 +123,7 @@ def test_covidcast(self):
123123
}],
124124
'message': 'success',
125125
})
126-
126+
127127
# fetch data, without specifying issue or lag
128128
response_1 = Epidata.covidcast(
129129
'src', 'sig', 'day', 'county', 20200414, '01234')
@@ -221,6 +221,92 @@ def test_covidcast(self):
221221
'message': 'success',
222222
})
223223

224+
def test_geo_value(self):
225+
"""test different variants of geo types: single, *, multi."""
226+
227+
# insert dummy data
228+
self.cur.execute('''
229+
insert into covidcast values
230+
(0, 'src', 'sig', 'day', 'county', 20200414, '11111',
231+
123, 10, 11, 12, 456, 13, 20200414, 0, 1, False),
232+
(0, 'src', 'sig', 'day', 'county', 20200414, '22222',
233+
123, 20, 21, 22, 456, 23, 20200414, 0, 1, False),
234+
(0, 'src', 'sig', 'day', 'county', 20200414, '33333',
235+
123, 30, 31, 32, 456, 33, 20200414, 0, 1, False),
236+
(0, 'src', 'sig', 'day', 'msa', 20200414, '11111',
237+
123, 40, 41, 42, 456, 43, 20200414, 0, 1, False),
238+
(0, 'src', 'sig', 'day', 'msa', 20200414, '22222',
239+
123, 50, 51, 52, 456, 53, 20200414, 0, 1, False),
240+
(0, 'src', 'sig', 'day', 'msa', 20200414, '33333',
241+
123, 60, 61, 62, 456, 634, 20200414, 0, 1, False)
242+
''')
243+
self.cnx.commit()
244+
245+
def fetch(geo_value):
246+
# make the request
247+
response = Epidata.covidcast(
248+
'src', 'sig', 'day', 'county', 20200414, geo_value)
249+
return response
250+
251+
counties = [{
252+
'time_value': 20200414,
253+
'geo_value': '11111',
254+
'value': 10,
255+
'stderr': 11,
256+
'sample_size': 12,
257+
'direction': 13,
258+
'issue': 20200414,
259+
'lag': 0,
260+
'signal': 'sig',
261+
}, {
262+
'time_value': 20200414,
263+
'geo_value': '22222',
264+
'value': 20,
265+
'stderr': 21,
266+
'sample_size': 22,
267+
'direction': 23,
268+
'issue': 20200414,
269+
'lag': 0,
270+
'signal': 'sig',
271+
}, {
272+
'time_value': 20200414,
273+
'geo_value': '33333',
274+
'value': 30,
275+
'stderr': 31,
276+
'sample_size': 32,
277+
'direction': 33,
278+
'issue': 20200414,
279+
'lag': 0,
280+
'signal': 'sig',
281+
}]
282+
283+
# test fetch all
284+
r = fetch('*')
285+
self.assertEqual(r['message'], 'success')
286+
self.assertEqual(r['epidata'], counties)
287+
# test fetch a specific region
288+
r = fetch('11111')
289+
self.assertEqual(r['message'], 'success')
290+
self.assertEqual(r['epidata'], [counties[0]])
291+
# test fetch a specific yet not existing region
292+
r = fetch('55555')
293+
self.assertEqual(r['message'], 'no results')
294+
# test fetch a multiple regions
295+
r = fetch(['11111', '22222'])
296+
self.assertEqual(r['message'], 'success')
297+
self.assertEqual(r['epidata'], [counties[0], counties[1]])
298+
# test fetch a multiple regions in another variant
299+
r = fetch(['11111', '33333'])
300+
self.assertEqual(r['message'], 'success')
301+
self.assertEqual(r['epidata'], [counties[0], counties[2]])
302+
# test fetch a multiple regions but one is not existing
303+
r = fetch(['11111', '55555'])
304+
self.assertEqual(r['message'], 'success')
305+
self.assertEqual(r['epidata'], [counties[0]])
306+
# test fetch a multiple regions but specify no region
307+
r = fetch([])
308+
self.assertEqual(r['message'], 'no results')
309+
224310
def test_covidcast_meta(self):
225311
"""Test that the covidcast_meta endpoint returns expected data."""
226312

src/client/delphi_epidata.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,9 +522,13 @@ Epidata <- (function() {
522522
time_type = time_type,
523523
geo_type = geo_type,
524524
time_values = .list(time_values),
525-
geo_value = geo_value,
526525
format = format
527526
)
527+
if(is.list(geo_value)) {
528+
params$geo_values = paste(geo_value, collapse=',')
529+
} else {
530+
params$geo_value = geo_value
531+
}
528532
if(!missing(as_of)) {
529533
params$as_of <- as_of
530534
}

src/client/delphi_epidata.coffee

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,10 @@ class Epidata
370370
'time_type': time_type
371371
'geo_type': geo_type
372372
'time_values': _list(time_values)
373-
'geo_value': geo_value
373+
if Array.isArray(geo_value)
374+
params.geo_values = geo_value.join(',')
375+
else
376+
params.geo_value = geo_value
374377
if as_of?
375378
params.as_of = as_of
376379
if issues?

src/client/delphi_epidata.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,10 +573,15 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
573573
'signals': signals,
574574
'time_type': time_type,
575575
'geo_type': geo_type,
576-
'time_values': _list(time_values),
577-
'geo_value': geo_value
576+
'time_values': _list(time_values)
578577
};
579578

579+
if (Array.isArray(geo_value)) {
580+
params.geo_values = geo_value.join(',');
581+
} else {
582+
params.geo_value = geo_value;
583+
}
584+
580585
if (as_of != null) {
581586
params.as_of = as_of;
582587
}

src/client/delphi_epidata.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,10 +573,13 @@ def covidcast(
573573
'signals': Epidata._list(signals),
574574
'time_type': time_type,
575575
'geo_type': geo_type,
576-
'time_values': Epidata._list(time_values),
577-
'geo_value': geo_value,
576+
'time_values': Epidata._list(time_values)
578577
}
579578

579+
if isinstance(geo_value, (list, tuple)):
580+
params['geo_values'] = ','.join(geo_value)
581+
else:
582+
params['geo_value'] = geo_value
580583
if as_of is not None:
581584
params['as_of'] = as_of
582585
if issues is not None:

0 commit comments

Comments
 (0)