Skip to content

Commit 8e4d23c

Browse files
committed
add fluview_meta endpoint
- re-use the existing code for the `fluview` bits of the `meta` endpoint - updated all client libraries - added new integration test - wrote new doc and updated table of endpoints - all unit and integration tests pass
1 parent 27cacd7 commit 8e4d23c

File tree

8 files changed

+170
-1
lines changed

8 files changed

+170
-1
lines changed

docs/api/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ The parameters available for each source are documented in each linked source-sp
102102
| [`ecdc_ili`](ecdc_ili.md) | ECDC ILI | ECDC ILI data from the ECDC website. | no |
103103
| [`flusurv`](flusurv.md) | FluSurv | FluSurv-NET data (flu hospitaliation rates) from CDC. | no |
104104
| [`fluview`](fluview.md) | FluView | Influenza-like illness (ILI) from U.S. Outpatient Influenza-like Illness Surveillance Network (ILINet). | no |
105+
| [`fluview_meta`](fluview_meta.md) | FluView Metadata | Summary data about [`fluview`](fluview.md). | no |
105106
| [`fluview_clinical`](fluview_clinical.md) | FluView Clinical | ... <!-- TODO --> | no |
106107
| [`gft`](gft.md) | Google Flu Trends | Estimate of influenza activity based on volume of certain search queries. Google has discontinued Flu Trends, and this is now a static data source. | no |
107108
| [`ght`](ght.md) | Google Health Trends | Estimate of influenza activity based on volume of certain search queries. | yes |

docs/api/fluview_meta.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# About
2+
3+
This is the documentation of the API for accessing the FluView metadata
4+
(`fluview_meta`) data source of [Delphi](https://delphi.cmu.edu/)'s
5+
epidemiological data.
6+
7+
General topics not specific to any particular data source are discussed in the
8+
[API overview](README.md). Such topics include:
9+
[contributing](README.md#contributing), [citing](README.md#citing), and
10+
[data licensing](README.md#data-licensing).
11+
12+
## FluView Metadata
13+
14+
Returns information about the [`fluview` endpoint](fluview.md).
15+
16+
# The API
17+
18+
The base URL is: https://delphi.cmu.edu/epidata/api.php
19+
20+
See [this documentation](README.md) for details on specifying epiweeks, dates, and lists.
21+
22+
## Parameters
23+
24+
There are no parameters for this endpoint.
25+
26+
## Response
27+
28+
| Field | Description | Type |
29+
| --- | --- | --- |
30+
| `result` | result code: 1 = success, 2 = too many results, -2 = no results | integer |
31+
| `epidata` | list of results | array of objects |
32+
| `epidata[].latest_update` | date when data was last updated | string |
33+
| `epidata[].latest_issue` | most recent "issue" (epiweek) in the data | integer |
34+
| `epidata[].table_rows` | total number of rows in the table | integer |
35+
| `message` | `success` or error message | string |
36+
37+
# Example URLs
38+
39+
### FluView Metadata
40+
https://delphi.cmu.edu/epidata/api.php?source=fluview_meta
41+
42+
```json
43+
{
44+
"result": 1,
45+
"epidata": [
46+
{
47+
"latest_update": "2020-04-24",
48+
"latest_issue": 202016,
49+
"table_rows": 957673
50+
}
51+
],
52+
"message": "success"
53+
}
54+
```
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
"""Integration tests for the `fluview_meta` endpoint."""
2+
3+
# standard library
4+
import unittest
5+
6+
# third party
7+
import mysql.connector
8+
9+
# first party
10+
from delphi.epidata.client.delphi_epidata import Epidata
11+
12+
13+
class FluviewMetaTests(unittest.TestCase):
14+
"""Tests the `fluview_meta` endpoint."""
15+
16+
@classmethod
17+
def setUpClass(cls):
18+
"""Perform one-time setup."""
19+
20+
# use the local instance of the Epidata API
21+
Epidata.BASE_URL = 'http://delphi_web_epidata/epidata/api.php'
22+
23+
def setUp(self):
24+
"""Perform per-test setup."""
25+
26+
# connect to the `epidata` database and clear the `fluview` table
27+
cnx = mysql.connector.connect(
28+
user='user',
29+
password='pass',
30+
host='delphi_database_epidata',
31+
database='epidata')
32+
cur = cnx.cursor()
33+
cur.execute('truncate table fluview')
34+
cnx.commit()
35+
cur.close()
36+
37+
# make connection and cursor available to test cases
38+
self.cnx = cnx
39+
self.cur = cnx.cursor()
40+
41+
def tearDown(self):
42+
"""Perform per-test teardown."""
43+
self.cur.close()
44+
self.cnx.close()
45+
46+
def test_round_trip(self):
47+
"""Make a simple round-trip with some sample data."""
48+
49+
# insert dummy data
50+
self.cur.execute('''
51+
insert into fluview values
52+
(0, "2020-04-07", 202021, 202020, "nat", 1, 2, 3, 4, 3.14159, 1.41421,
53+
10, 11, 12, 13, 14, 15),
54+
(0, "2020-04-28", 202022, 202022, "hhs1", 5, 6, 7, 8, 1.11111, 2.22222,
55+
20, 21, 22, 23, 24, 25)
56+
''')
57+
self.cnx.commit()
58+
59+
# make the request
60+
response = Epidata.fluview_meta()
61+
62+
# assert that the right data came back
63+
self.assertEqual(response, {
64+
'result': 1,
65+
'epidata': [{
66+
'latest_update': '2020-04-28',
67+
'latest_issue': 202022,
68+
'table_rows': 2,
69+
}],
70+
'message': 'success',
71+
})

src/client/delphi_epidata.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ Epidata <- (function() {
7676
return(.request(params))
7777
}
7878

79+
# Fetch FluView metadata
80+
fluview_meta <- function() {
81+
# Set up request
82+
params <- list(
83+
source = 'fluview_meta'
84+
)
85+
# Make the API call
86+
return(.request(params))
87+
}
88+
7989
# Fetch FluView virological data
8090
fluview_clinical <- function(regions, epiweeks, issues, lag) {
8191
# Check parameters
@@ -521,6 +531,7 @@ Epidata <- (function() {
521531
return(list(
522532
range = range,
523533
fluview = fluview,
534+
fluview_meta = fluview_meta,
524535
fluview_clinical = fluview_clinical,
525536
flusurv = flusurv,
526537
gft = gft,

src/client/delphi_epidata.coffee

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,16 @@ class Epidata
8282
params.auth = auth
8383
# Make the API call
8484
_request(callback, params)
85-
85+
86+
87+
# Fetch FluView metadata
88+
@fluview_meta: (callback) ->
89+
# Set up request
90+
params =
91+
'source': 'fluview_meta'
92+
# Make the API call
93+
_request(callback, params)
94+
8695
# Fetch FluView clinical data
8796
@fluview_clinical: (callback, regions, epiweeks, issues, lag) ->
8897
# Check parameters

src/client/delphi_epidata.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/client/delphi_epidata.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,17 @@ def fluview(regions, epiweeks, issues=None, lag=None, auth=None):
8888
# Make the API call
8989
return Epidata._request(params)
9090

91+
# Fetch FluView metadata
92+
@staticmethod
93+
def fluview_meta():
94+
"""Fetch FluView metadata."""
95+
# Set up request
96+
params = {
97+
'source': 'fluview_meta',
98+
}
99+
# Make the API call
100+
return Epidata._request(params)
101+
91102
# Fetch FluView clinical data
92103
@staticmethod
93104
def fluview_clinical(regions, epiweeks, issues=None, lag=None):

src/server/api.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,10 @@ function meta_delphi() {
11341134
$epidata = get_fluview($epiweeks, $regions, $issues, $lag, $authorized);
11351135
store_result($data, $epidata);
11361136
}
1137+
} else if($source === 'fluview_meta') {
1138+
// get the data
1139+
$epidata = meta_fluview();
1140+
store_result($data, $epidata);
11371141
} else if ($source === 'fluview_clinical') {
11381142
if(require_all($data, array('epiweeks', 'regions'))) {
11391143
// parse the request

0 commit comments

Comments
 (0)