Skip to content

Commit 7c9bf59

Browse files
authored
Merge pull request #685 from cmu-delphi/release/delphi-epidata-0.2.8
Release Delphi Epidata 0.2.8
2 parents c6c7314 + 63da871 commit 7c9bf59

File tree

18 files changed

+224
-72
lines changed

18 files changed

+224
-72
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.2.7
2+
current_version = 0.2.8
33
commit = False
44
tag = False
55

src/acquisition/covidcast/database.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ def compute_covidcast_meta(self, table_name='covidcast', use_index=True):
257257
n_threads = max(1, cpu_count()*9//10) # aka number of concurrent db connections, which [sh|c]ould be ~<= 90% of the #cores available to SQL server
258258
# NOTE: this may present a small problem if this job runs on different hardware than the db,
259259
# but we should not run into that issue in prod.
260+
logger.info(f"using {n_threads} workers")
260261

261262
srcsigs = Queue() # multi-consumer threadsafe!
262263

@@ -305,22 +306,24 @@ def compute_covidcast_meta(self, table_name='covidcast', use_index=True):
305306
meta_lock = threading.Lock()
306307

307308
def worker():
308-
logger.info("starting thread: " + threading.current_thread().name)
309+
name = threading.current_thread().name
310+
logger.info("starting thread", thread=name)
309311
# set up new db connection for thread
310312
worker_dbc = Database()
311313
worker_dbc.connect(connector_impl=self._connector_impl)
312314
w_cursor = worker_dbc._cursor
313315
try:
314316
while True:
315317
(source, signal) = srcsigs.get_nowait() # this will throw the Empty caught below
318+
logger.info("starting pair", thread=name, pair=f"({source}, {signal})")
316319
w_cursor.execute(inner_sql, (source, signal))
317320
with meta_lock:
318321
meta.extend(list(
319322
dict(zip(w_cursor.column_names, x)) for x in w_cursor
320323
))
321324
srcsigs.task_done()
322325
except Empty:
323-
logger.info("no jobs left, thread terminating: " + threading.current_thread().name)
326+
logger.info("no jobs left, thread terminating", thread=name)
324327
finally:
325328
worker_dbc.disconnect(False) # cleanup
326329

@@ -334,7 +337,7 @@ def worker():
334337
logger.info("jobs complete")
335338
for t in threads:
336339
t.join()
337-
logger.error("threads terminated")
340+
logger.info("all threads terminated")
338341

339342
# sort the metadata because threaded workers dgaf
340343
sorting_fields = "data_source signal time_type geo_type".split()

src/client/delphi_epidata.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Epidata <- (function() {
1515
# API base url
1616
BASE_URL <- 'https://delphi.cmu.edu/epidata/api.php'
1717

18-
client_version <- '0.2.7'
18+
client_version <- '0.2.8'
1919

2020
# Helper function to cast values and/or ranges to strings
2121
.listitem <- function(value) {

src/client/delphi_epidata.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
}
2323
})(this, function (exports, fetchImpl, jQuery) {
2424
const BASE_URL = "https://delphi.cmu.edu/epidata/";
25-
const client_version = "0.2.7";
25+
const client_version = "0.2.8";
2626

2727
// Helper function to cast values and/or ranges to strings
2828
function _listitem(value) {

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

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

src/client/packaging/npm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "delphi_epidata",
33
"description": "Delphi Epidata API Client",
44
"authors": "Delphi Group",
5-
"version": "0.2.7",
5+
"version": "0.2.8",
66
"license": "MIT",
77
"homepage": "https://github.com/cmu-delphi/delphi-epidata",
88
"bugs": {
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.2.7'
4+
__version__ = '0.2.8'

src/client/packaging/pypi/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="delphi_epidata",
8-
version="0.2.7",
8+
version="0.2.8",
99
author="David Farrow",
1010
author_email="[email protected]",
1111
description="A programmatic interface to Delphi's Epidata API.",

src/server/_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
load_dotenv()
77

8-
VERSION = "0.2.7"
8+
VERSION = "0.2.8"
99

1010
MAX_RESULTS = int(10e6)
1111
MAX_COMPATIBILITY_RESULTS = int(3650)

src/server/_params.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55

66
from flask import request
77

8+
89
from ._exceptions import ValidationFailedException
9-
from .utils import days_in_range, weeks_in_range
10+
from .utils import days_in_range, weeks_in_range, guess_time_value_is_day
1011

1112

1213
def _parse_common_multi_arg(key: str) -> List[Tuple[str, Union[bool, Sequence[str]]]]:
@@ -109,6 +110,15 @@ class TimePair:
109110
time_type: str
110111
time_values: Union[bool, Sequence[Union[int, Tuple[int, int]]]]
111112

113+
@property
114+
def is_week(self) -> bool:
115+
return self.time_type == 'week'
116+
117+
@property
118+
def is_day(self) -> bool:
119+
return self.time_type != 'week'
120+
121+
112122
def count(self) -> float:
113123
"""
114124
returns the count of items in this pair
@@ -225,3 +235,45 @@ def parse_day_arg(key: str) -> int:
225235
if not isinstance(r, int):
226236
raise ValidationFailedException(f"{key} must match YYYYMMDD or YYYY-MM-DD")
227237
return r
238+
239+
def parse_week_arg(key: str) -> int:
240+
v = request.values.get(key)
241+
if not v:
242+
raise ValidationFailedException(f"{key} param is required")
243+
r = parse_week_value(v)
244+
if not isinstance(r, int):
245+
raise ValidationFailedException(f"{key} must match YYYYWW")
246+
return r
247+
248+
249+
def parse_week_range_arg(key: str) -> Tuple[int, int]:
250+
v = request.values.get(key)
251+
if not v:
252+
raise ValidationFailedException(f"{key} param is required")
253+
r = parse_week_value(v)
254+
if not isinstance(r, tuple):
255+
raise ValidationFailedException(f"{key} must match YYYYWW-YYYYWW")
256+
return r
257+
258+
def parse_day_or_week_arg(key: str, default_value: Optional[int] = None) -> Tuple[int, bool]:
259+
v = request.values.get(key)
260+
if not v:
261+
if default_value is not None:
262+
return default_value, guess_time_value_is_day(default_value)
263+
raise ValidationFailedException(f"{key} param is required")
264+
# format is either YYYY-MM-DD or YYYYMMDD or YYYYMM
265+
is_week = len(v) == 6
266+
if is_week:
267+
return parse_week_arg(key), False
268+
return parse_day_arg(key), True
269+
270+
def parse_day_or_week_range_arg(key: str) -> Tuple[Tuple[int, int], bool]:
271+
v = request.values.get(key)
272+
if not v:
273+
raise ValidationFailedException(f"{key} param is required")
274+
# format is either YYYY-MM-DD--YYYY-MM-DD or YYYYMMDD-YYYYMMDD or YYYYMM-YYYYMM
275+
# so if the first before the - has length 6, it must be a week
276+
is_week = len(v.split('-', 2)[0]) == 6
277+
if is_week:
278+
return parse_week_range_arg(key), False
279+
return parse_day_range_arg(key), True

0 commit comments

Comments
 (0)