Skip to content

Commit bde5d40

Browse files
authored
Merge pull request #595 from cmu-delphi/dev
Release minor workflow and docs fixes
2 parents 7d9f8bb + b6e7e94 commit bde5d40

File tree

7 files changed

+50
-35
lines changed

7 files changed

+50
-35
lines changed

.github/workflows/create-delphi-epidata-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Reset dev branch
2121
run: |
2222
git fetch origin dev:dev
23-
git reset --hard dev
23+
git reset --hard origin/dev
2424
- name: Set up Python 3.8
2525
uses: actions/setup-python@v2
2626
with:

.github/workflows/deploy-docs.yaml

Lines changed: 0 additions & 20 deletions
This file was deleted.

docs/api/covid_hosp.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ General topics not specific to any particular data source are discussed in the
2525

2626
This data source provides various measures of COVID-19 burden on patients and healthcare in the US.
2727
- Data source: US Department of Health & Human Services (HHS) [COVID-19 Reported Patient Impact and
28-
Hospital Capacity by State Timeseries](https://healthdata.gov/Hospital/COVID-19-Reported-Patient-Impact-and-Hospital-Capa/g62h-syeh)
28+
Hospital Capacity by State Timeseries](https://healthdata.gov/Hospital/COVID-19-Reported-Patient-Impact-and-Hospital-Capa/g62h-syeh)
2929
and [COVID-19 Reported Patient Impact and Hospital Capacity by State](https://healthdata.gov/dataset/COVID-19-Reported-Patient-Impact-and-Hospital-Capa/6xf2-c3ie)
3030
- Temporal Resolution: Daily, starting 2020-01-01
3131
- Spatial Resolution: US States plus DC, PR, and VI
@@ -36,7 +36,7 @@ weekly.
3636

3737
# The API
3838

39-
The base URL is: https://delphi.cmu.edu/epidata/api.php
39+
The base URL is: https://delphi.cmu.edu/epidata/covid_hosp_state_timeseries/
4040

4141
See [this documentation](README.md) for details on specifying locations and dates.
4242

@@ -72,7 +72,7 @@ If `issues` is not specified, then the most recent issue is used by default.
7272
# Example URLs
7373

7474
### MA on 2020-05-10 (per most recent issue)
75-
https://delphi.cmu.edu/epidata/covid_hosp/?states=MA&dates=20200510
75+
https://delphi.cmu.edu/epidata/covid_hosp_state_timeseries/?states=MA&dates=20200510
7676

7777
```json
7878
{

integrations/acquisition/covid_hosp/state_daily/test_scenarios.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
"""Integration tests for acquisition of COVID hospitalization."""
22

33
# standard library
4+
from datetime import date
45
import unittest
5-
from unittest.mock import MagicMock
66
from unittest.mock import patch
77

88
# third party
99
from freezegun import freeze_time
10+
import pandas as pd
1011

1112
# first party
12-
from delphi.epidata.acquisition.covid_hosp.common.database import Database
13+
from delphi.epidata.acquisition.covid_hosp.state_daily.database import Database
1314
from delphi.epidata.acquisition.covid_hosp.common.test_utils import UnitTestUtils
1415
from delphi.epidata.client.delphi_epidata import Epidata
1516
from delphi.epidata.acquisition.covid_hosp.state_daily.update import Update
1617
from delphi.epidata.acquisition.covid_hosp.state_daily.network import Network
18+
from delphi.epidata.acquisition.covid_hosp.common.utils import Utils
1719
import delphi.operations.secrets as secrets
1820

1921
# py3tester coverage target (equivalent to `import *`)
@@ -97,3 +99,31 @@ def test_acquire_dataset(self):
9799
response = Epidata.covid_hosp('WY', Epidata.range(20200101, 20210101))
98100
self.assertEqual(response['result'], 1)
99101
self.assertEqual(len(response['epidata']), 1)
102+
103+
104+
@freeze_time("2021-03-16")
105+
def test_acquire_specific_issue(self):
106+
"""Acquire a new dataset."""
107+
108+
# make sure the data does not yet exist
109+
with self.subTest(name='no data yet'):
110+
response = Epidata.covid_hosp('MA', Epidata.range(20200101, 20210101))
111+
self.assertEqual(response['result'], -2)
112+
113+
# acquire sample data into local database
114+
# mock out network calls to external hosts
115+
with Database.connect() as db:
116+
pre_max_issue = db.get_max_issue()
117+
self.assertEqual(pre_max_issue, pd.Timestamp('1900-01-01 00:00:00'))
118+
with self.subTest(name='first acquisition'), \
119+
patch.object(Network, 'fetch_metadata', return_value=self.test_utils.load_sample_metadata()) as mock_fetch_meta, \
120+
patch.object(Network, 'fetch_dataset', side_effect=[self.test_utils.load_sample_dataset("dataset0.csv")]
121+
) as mock_fetch:
122+
acquired = Utils.update_dataset(Database,
123+
Network,
124+
date(2021, 3, 12),
125+
date(2021, 3, 14))
126+
with Database.connect() as db:
127+
post_max_issue = db.get_max_issue()
128+
self.assertEqual(post_max_issue, pd.Timestamp('2021-03-13 00:00:00'))
129+
self.assertTrue(acquired)

src/acquisition/covid_hosp/common/utils.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ def issues_to_fetch(metadata, newer_than, older_than):
8282
Upper bound (exclusive) of days to get issues for
8383
Returns
8484
-------
85-
Dictionary of {issue day: list of download urls} for issues after newer_than and before older_than
85+
Dictionary of {issue day: list of (download urls, index)}
86+
for issues after newer_than and before older_than
8687
"""
8788
daily_issues = {}
8889
for index in sorted(set(metadata.index)):
@@ -127,7 +128,7 @@ def merge_by_key_cols(dfs, key_cols):
127128
return result.reset_index(level=key_cols)
128129

129130
@staticmethod
130-
def update_dataset(database, network):
131+
def update_dataset(database, network, newer_than=None, older_than=None):
131132
"""Acquire the most recent dataset, unless it was previously acquired.
132133
133134
Parameters
@@ -136,18 +137,22 @@ def update_dataset(database, network):
136137
A `Database` subclass for a particular dataset.
137138
network : delphi.epidata.acquisition.covid_hosp.common.network.Network
138139
A `Network` subclass for a particular dataset.
140+
newer_than : date
141+
Lower bound (exclusive) of days to get issues for.
142+
older_than : date
143+
Upper bound (exclusive) of days to get issues for
139144
140145
Returns
141146
-------
142147
bool
143148
Whether a new dataset was acquired.
144149
"""
145-
today = datetime.datetime.today().date()
146150
metadata = network.fetch_metadata()
147-
148151
with database.connect() as db:
149152
max_issue = db.get_max_issue()
150-
daily_issues = Utils.issues_to_fetch(metadata, max_issue, today)
153+
older_than = datetime.datetime.today().date() if newer_than is None else older_than
154+
newer_than = max_issue if newer_than is None else newer_than
155+
daily_issues = Utils.issues_to_fetch(metadata, newer_than, older_than)
151156
if not daily_issues:
152157
print("no new issues, nothing to do")
153158
return False

src/client/packaging/npm/package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from .delphi_epidata import Epidata
22

33
name = 'delphi_epidata'
4-
__version__ = '0.0.12'
4+
__version__ = '0.1.0'

0 commit comments

Comments
 (0)