Skip to content

Commit 10e805a

Browse files
committed
ddl and integration test for fluview
- explicitly define the table - move (well, copy) data dictionary to the ddl - introduce an integration test, which is just a simple round-trip
1 parent b6953b0 commit 10e805a

File tree

2 files changed

+170
-0
lines changed

2 files changed

+170
-0
lines changed

integrations/test_fluview.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
"""Integration tests for the `fluview` 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 FluviewTests(unittest.TestCase):
14+
"""Tests the `fluview` 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+
''')
55+
self.cnx.commit()
56+
57+
# make the request
58+
response = Epidata.fluview('nat', 202020)
59+
60+
# assert that the right data came back
61+
self.assertEqual(response, {
62+
"result": 1,
63+
"epidata": [{
64+
"release_date": "2020-04-07",
65+
"region": "nat",
66+
"issue": 202021,
67+
"epiweek": 202020,
68+
"lag": 1,
69+
"num_ili": 2,
70+
"num_patients": 3,
71+
"num_providers": 4,
72+
"num_age_0": 10,
73+
"num_age_1": 11,
74+
"num_age_2": 12,
75+
"num_age_3": 13,
76+
"num_age_4": 14,
77+
"num_age_5": 15,
78+
"wili": 3.14159,
79+
"ili": 1.41421,
80+
}],
81+
"message": "success",
82+
})

src/ddl/fluview.sql

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
Stores ILI data from the CDC.
3+
4+
+---------------+-------------+------+-----+---------+----------------+
5+
| Field | Type | Null | Key | Default | Extra |
6+
+---------------+-------------+------+-----+---------+----------------+
7+
| id | int(11) | NO | PRI | NULL | auto_increment |
8+
| release_date | date | NO | MUL | NULL | |
9+
| issue | int(11) | NO | MUL | NULL | |
10+
| epiweek | int(11) | NO | MUL | NULL | |
11+
| region | varchar(12) | NO | MUL | NULL | |
12+
| lag | int(11) | NO | MUL | NULL | |
13+
| num_ili | int(11) | NO | | NULL | |
14+
| num_patients | int(11) | NO | | NULL | |
15+
| num_providers | int(11) | NO | | NULL | |
16+
| wili | double | NO | | NULL | |
17+
| ili | double | NO | | NULL | |
18+
| num_age_0 | int(11) | YES | | NULL | |
19+
| num_age_1 | int(11) | YES | | NULL | |
20+
| num_age_2 | int(11) | YES | | NULL | |
21+
| num_age_3 | int(11) | YES | | NULL | |
22+
| num_age_4 | int(11) | YES | | NULL | |
23+
| num_age_5 | int(11) | YES | | NULL | |
24+
+---------------+-------------+------+-----+---------+----------------+
25+
26+
id:
27+
unique identifier for each record
28+
release_date:
29+
the date when this record was first published by the CDC
30+
issue:
31+
the epiweek of publication (e.g. issue 201453 includes epiweeks up to and
32+
including 2014w53, but not 2015w01 or following)
33+
epiweek:
34+
the epiweek during which the data was collected
35+
region:
36+
the name of the location (e.g. 'nat', 'hhs1', 'cen9', 'pa', 'jfk')
37+
lag:
38+
number of weeks between `epiweek` and `issue`
39+
num_ili:
40+
the number of ILI cases (numerator)
41+
num_patients:
42+
the total number of patients (denominator)
43+
num_providers:
44+
the number of reporting healthcare providers
45+
wili:
46+
weighted percent ILI
47+
ili:
48+
unweighted percent ILI
49+
num_age_0:
50+
number of cases in ages 0-4
51+
num_age_1:
52+
number of cases in ages 5-24
53+
num_age_2:
54+
number of cases in ages 25-64
55+
num_age_3:
56+
number of cases in ages 25-49
57+
num_age_4:
58+
number of cases in ages 50-64
59+
num_age_5:
60+
number of cases in ages 65+
61+
*/
62+
63+
CREATE TABLE `fluview` (
64+
`id` int(11) NOT NULL AUTO_INCREMENT,
65+
`release_date` date NOT NULL,
66+
`issue` int(11) NOT NULL,
67+
`epiweek` int(11) NOT NULL,
68+
`region` varchar(12) NOT NULL,
69+
`lag` int(11) NOT NULL,
70+
`num_ili` int(11) NOT NULL,
71+
`num_patients` int(11) NOT NULL,
72+
`num_providers` int(11) NOT NULL,
73+
`wili` double NOT NULL,
74+
`ili` double NOT NULL,
75+
`num_age_0` int(11) DEFAULT NULL,
76+
`num_age_1` int(11) DEFAULT NULL,
77+
`num_age_2` int(11) DEFAULT NULL,
78+
`num_age_3` int(11) DEFAULT NULL,
79+
`num_age_4` int(11) DEFAULT NULL,
80+
`num_age_5` int(11) DEFAULT NULL,
81+
PRIMARY KEY (`id`),
82+
UNIQUE KEY `issue` (`issue`,`epiweek`,`region`),
83+
KEY `release_date` (`release_date`),
84+
KEY `issue_2` (`issue`),
85+
KEY `epiweek` (`epiweek`),
86+
KEY `region` (`region`),
87+
KEY `lag` (`lag`)
88+
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

0 commit comments

Comments
 (0)