Skip to content

Commit 7188b1b

Browse files
authored
Merge pull request #1138 from cmu-delphi/release/0.1.4
Release 0.1.4
2 parents d5bad33 + ac9660d commit 7188b1b

File tree

35 files changed

+388
-79
lines changed

35 files changed

+388
-79
lines changed

.github/workflows/python-ci.yml

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

66
on:
77
push:
8-
branches: [ main, prod, 'release/*' ]
8+
branches: [ main, prod ]
99
pull_request:
1010
types: [ opened, synchronize, reopened, ready_for_review ]
1111
branches: [ main, prod ]

.github/workflows/r-ci.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
#
6+
# See https://github.com/r-lib/actions/tree/master/examples#readme for
7+
# additional example workflows available for the R community.
8+
9+
name: R facebook survey
10+
11+
on:
12+
push:
13+
branches: [ main, prod ]
14+
pull_request:
15+
types: [ opened, synchronize, reopened, ready_for_review ]
16+
branches: [ main, prod ]
17+
18+
jobs:
19+
build:
20+
runs-on: ubuntu-20.04
21+
if: github.event.pull_request.draft == false
22+
strategy:
23+
matrix:
24+
r-version: [4.0]
25+
defaults:
26+
run:
27+
working-directory: facebook/delphiFacebook
28+
29+
steps:
30+
- uses: actions/checkout@v2
31+
- name: Set up R ${{ matrix.r-version }}
32+
uses: r-lib/actions/setup-r@v1
33+
with:
34+
r-version: ${{ matrix.r-version }}
35+
- name: Install linux dependencies
36+
run: |
37+
sudo apt-get install libcurl4-openssl-dev
38+
- name: Get date
39+
id: get-date
40+
run: |
41+
echo "::set-output name=date::$(/bin/date -u "+%Y%m%d")"
42+
- name: Cache R packages
43+
uses: actions/cache@v2
44+
with:
45+
path: ${{ env.R_LIBS_USER }}
46+
key: ${{ runner.os }}-r-facebook-survey-${{ steps.get-date.outputs.date }}
47+
restore-keys: |
48+
${{ runner.os }}-r-facebook-survey-
49+
- name: Install R dependencies
50+
run: |
51+
if ( packageVersion("readr") != "1.4.0" ) {
52+
install.packages("devtools")
53+
devtools::install_version("readr", version = "1.4.0")
54+
}
55+
install.packages("remotes")
56+
remotes::update_packages(c("rcmdcheck", "mockr"), upgrade="always")
57+
dependency_list <- remotes::dev_package_deps(dependencies=TRUE)
58+
remotes::update_packages(dependency_list$package[dependency_list$package != "readr"], upgrade="always")
59+
shell: Rscript {0}
60+
- name: Check
61+
run: |
62+
rcmdcheck::rcmdcheck(args = c("--no-manual", "--test-dir=unit-tests"), error_on = "error")
63+
shell: Rscript {0}

_delphi_utils_python/.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.1.3
2+
current_version = 0.1.4
33
commit = False
44
tag = False
55
tag_name = delphi-utils/v{new_version}

_delphi_utils_python/delphi_utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
from .signal import add_prefix
1515
from .nancodes import Nans
1616

17-
__version__ = "0.1.3"
17+
__version__ = "0.1.4"

_delphi_utils_python/delphi_utils/validator/report.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,22 @@
77
class ValidationReport:
88
"""Class for reporting the results of validation."""
99

10-
def __init__(self, errors_to_suppress: List[ValidationFailure]):
10+
def __init__(self, errors_to_suppress: List[ValidationFailure], data_source: str = ""):
1111
"""Initialize a ValidationReport.
1212
1313
Parameters
1414
----------
1515
errors_to_suppress: List[ValidationFailure]
1616
List of ValidationFailures to ignore.
17+
data_source: str
18+
Name of data source as obtained from params
1719
1820
Attributes
1921
----------
2022
errors_to_suppress: List[ValidationFailure]
2123
See above
24+
data_source: str
25+
See above
2226
num_suppressed: int
2327
Number of errors suppressed
2428
total_checks: int
@@ -31,12 +35,12 @@ def __init__(self, errors_to_suppress: List[ValidationFailure]):
3135
Errors raised from validation failures not found in `self.errors_to_suppress`
3236
"""
3337
self.errors_to_suppress = errors_to_suppress
38+
self.data_source = data_source
3439
self.num_suppressed = 0
3540
self.total_checks = 0
3641
self.raised_errors = []
3742
self.raised_warnings = []
3843
self.unsuppressed_errors = []
39-
self.summary = ""
4044

4145
def add_raised_error(self, error):
4246
"""Add an error to the report.
@@ -74,21 +78,25 @@ def add_raised_warning(self, warning):
7478
"""
7579
self.raised_warnings.append(warning)
7680

77-
def set_summary(self):
78-
"""Represent summary of report as a string."""
79-
out_str = f"{self.total_checks} checks run\n"
80-
out_str += f"{len(self.unsuppressed_errors)} checks failed\n"
81-
out_str += f"{self.num_suppressed} checks suppressed\n"
82-
out_str += f"{len(self.raised_warnings)} warnings\n"
83-
self.summary = out_str
84-
8581
def log(self, logger=None):
8682
"""Log errors and warnings."""
8783
if logger is None:
8884
logger = get_structured_logger(__name__)
8985

90-
self.set_summary()
91-
logger.info(self.summary)
86+
if self.success():
87+
logger.info("Validation run successful",
88+
data_source = self.data_source,
89+
checks_run = self.total_checks,
90+
checks_failed = len(self.unsuppressed_errors),
91+
checks_suppressed = self.num_suppressed,
92+
warnings = len(self.raised_warnings))
93+
else:
94+
logger.info("Validation run unsuccessful",
95+
data_source = self.data_source,
96+
checks_run = self.total_checks,
97+
checks_failed = len(self.unsuppressed_errors),
98+
checks_suppressed = self.num_suppressed,
99+
warnings = len(self.raised_warnings))
92100
for error in self.unsuppressed_errors:
93101
logger.critical(str(error))
94102
for warning in self.raised_warnings:

_delphi_utils_python/delphi_utils/validator/validate.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def __init__(self, params):
3737
# Date/time settings
3838
self.time_window = TimeWindow.from_params(validation_params["common"]["end_date"],
3939
validation_params["common"]["span_length"])
40+
self.data_source = validation_params["common"].get("data_source", "")
4041

4142
self.static_validation = StaticValidator(validation_params)
4243
self.dynamic_validation = DynamicValidator(validation_params)
@@ -51,7 +52,7 @@ def validate(self):
5152
Returns:
5253
- ValidationReport collating the validation outcomes
5354
"""
54-
report = ValidationReport(self.suppressed_errors)
55+
report = ValidationReport(self.suppressed_errors, self.data_source)
5556
frames_list = load_all_files(self.export_dir, self.time_window.start_date,
5657
self.time_window.end_date)
5758
self.static_validation.validate(frames_list, report)

_delphi_utils_python/setup.py

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

2525
setup(
2626
name="delphi_utils",
27-
version="0.1.3",
27+
version="0.1.4",
2828
description="Shared Utility Functions for Indicators",
2929
long_description=long_description,
3030
long_description_content_type="text/markdown",

_delphi_utils_python/tests/validator/test_report.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ def test_str(self):
4040
report.add_raised_warning(ImportWarning("right import"))
4141
report.add_raised_error(self.ERROR_1)
4242
report.add_raised_error(self.ERROR_2)
43-
report.set_summary()
44-
45-
assert report.summary ==\
46-
"3 checks run\n1 checks failed\n1 checks suppressed\n2 warnings\n"
4743

4844
def test_log(self):
4945
"""Test that the logs contain all failures and warnings."""

ansible/templates/sir_complainsalot-params-prod.json.j2

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@
4646
"max_age":6,
4747
"maintainers": ["U01AP8GSWG3","U01069KCRS7"],
4848
"retired-signals": ["raw_pct_negative","smoothed_pct_negative","raw_tests_per_device","smoothed_tests_per_device"]
49+
},
50+
"nchs-mortality": {
51+
"max_age":16,
52+
"maintainers": []
53+
},
54+
"covid-act-now": {
55+
"max_age":5,
56+
"maintainers": []
57+
},
58+
"hhs": {
59+
"max_age":8,
60+
"maintainers": []
4961
}
5062
}
5163
}

combo_cases_and_deaths/delphi_combo_cases_and_deaths/run.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ def run_module(params):
322322
variants = [tuple((metric, geo_res)+sensor_signal(metric, sensor, smoother))
323323
for (metric, geo_res, sensor, smoother) in
324324
product(METRICS, GEO_RESOLUTIONS, SENSORS, SMOOTH_TYPES)]
325+
variants = [i for i in variants if not ("7dav" in i[2] and "cumulative" in i[2])]
325326
params = configure(variants, params)
326327
logger = get_structured_logger(
327328
__name__, filename=params["common"].get("log_filename"),

combo_cases_and_deaths/tests/receiving/.gitkeep

Whitespace-only changes.

combo_cases_and_deaths/tests/test_run.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
"""Tests for running combo cases and deaths indicator."""
22
from datetime import date
33
from itertools import product
4+
import os
45
import unittest
56
from unittest.mock import patch, call
67
import pandas as pd
78
import numpy as np
89

910
from delphi_combo_cases_and_deaths.run import (
10-
extend_raw_date_range, get_updated_dates,
11+
run_module,
12+
extend_raw_date_range,
13+
get_updated_dates,
1114
sensor_signal,
1215
combine_usafacts_and_jhu,
1316
compute_special_geo_dfs,
@@ -244,6 +247,50 @@ def test_no_nation_jhu(mock_covidcast_signal):
244247
"sample_size": [None]},)
245248
)
246249

250+
@patch("delphi_combo_cases_and_deaths.run.combine_usafacts_and_jhu")
251+
def test_output_files(mock_combine):
252+
params = {
253+
"common": {
254+
"export_dir": "./receiving"
255+
},
256+
"indicator": {
257+
"export_start_date": [2020, 4, 1],
258+
"source":"indicator-combination",
259+
"wip_signal": ""
260+
}
261+
}
262+
mock_combine.return_value = pd.DataFrame(
263+
{
264+
"geo_id": ["01000"],
265+
"val": [10],
266+
"timestamp": [pd.to_datetime("2021-01-04")],
267+
"issue": [pd.to_datetime("2021-01-04")],
268+
"se": 0,
269+
"sample_size": 0
270+
},
271+
index=[1]
272+
)
273+
run_module(params)
274+
csv_files = [f for f in os.listdir("receiving") if f.endswith(".csv")]
275+
dates = ["20210104"]
276+
geos = ["county", "hrr", "msa", "state", "hhs", "nation"]
277+
278+
# enumerate metric names.
279+
metrics = []
280+
for event, span, stat in product(["deaths", "confirmed"],
281+
["cumulative", "incidence"],
282+
["num", "prop"]):
283+
metrics.append("_".join([event, span, stat]))
284+
metrics.append("_".join([event, "7dav", span, stat]))
285+
286+
expected_files = []
287+
for date in dates:
288+
for geo in geos:
289+
for metric in metrics:
290+
if "7dav" in metric and "cumulative" in metric:
291+
continue
292+
expected_files += [date + "_" + geo + "_" + metric + ".csv"]
293+
assert set(csv_files) == set(expected_files)
247294

248295
if __name__ == '__main__':
249296
unittest.main()

facebook/contingency-combine.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ write_rollup <- function(newly_seen_files, seen_file, output_df, output_file) {
189189

190190
args <- commandArgs(TRUE)
191191

192-
if (length(args) < 2) {
192+
if (length(args) != 2) {
193193
stop("Usage: Rscript contingency-combine.R path/to/individual/files/ path/to/rollup/files/")
194194
}
195195

facebook/delphiFacebook/NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export(get_filenames_in_range)
1818
export(get_range_prev_full_month)
1919
export(get_range_prev_full_period)
2020
export(get_range_prev_full_week)
21+
export(get_sparse_filenames)
2122
export(jeffreys_se)
2223
export(join_weights)
2324
export(load_archive)

0 commit comments

Comments
 (0)