Skip to content

Commit 4308075

Browse files
authored
Merge pull request #1215 from cmu-delphi/release/indicators_v0.1.10_utils_v0.1.10
Release covidcast-indicators 0.1.10
2 parents d7e6aaf + 7af0bb3 commit 4308075

34 files changed

+1361
-208
lines changed

.bumpversion.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[bumpversion]
2+
current_version = 0.1.10
3+
commit = True
4+
message = chore: bump covidcast-indicators to {new_version}
5+
tag = False

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Create Delphi Utils Release
1+
name: (Deprecated) Create Delphi Utils Release
22

33
on:
44
workflow_dispatch:

.github/workflows/create-release.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Create Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
versionName:
7+
description: 'Semantic Version Number (i.e., 5.5.0 or patch, minor, major, prepatch, preminor, premajor, prerelease)'
8+
required: true
9+
default: patch
10+
11+
jobs:
12+
create-release:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Check out code
16+
uses: actions/checkout@v2
17+
with:
18+
ref: prod
19+
ssh-key: ${{ secrets.CMU_DELPHI_DEPLOY_MACHINE_SSH }}
20+
- name: Reset prod branch
21+
run: |
22+
git fetch origin main:main
23+
git reset --hard main
24+
git config --global user.email [email protected]
25+
git config --global user.name "Delphi Deploy Bot"
26+
- name: Set up Python 3.8
27+
uses: actions/setup-python@v2
28+
with:
29+
python-version: 3.8
30+
- name: Install bump2version
31+
run: python -m pip install bump2version
32+
- name: Check for delphi-utils changes
33+
uses: dorny/paths-filter@v2
34+
id: changes
35+
with:
36+
base: 'prod'
37+
ref: 'main'
38+
filters: |
39+
utils:
40+
- '_delphi_utils_python/**'
41+
- name: Bump delphi-utils version
42+
id: utils-changed
43+
if: steps.changes.outputs.utils == 'true'
44+
working-directory: ./_delphi_utils_python
45+
run: |
46+
echo -n "::set-output name=version::"
47+
bump2version --list ${{ github.event.inputs.versionName }} | grep ^new_version | sed -r s,"^.*=",,
48+
echo -e "\n::set-output name=msg::(*new*)"
49+
- name: Detect delphi-utils version
50+
id: utils-unchanged
51+
if: steps.changes.outputs.utils == 'false'
52+
working-directory: ./_delphi_utils_python
53+
run: |
54+
echo -n "::set-output name=version::"
55+
bump2version --list -n ${{ github.event.inputs.versionName }} | grep ^current_version | sed -r s,"^.*=",,
56+
echo -e "\n::set-output name=msg::(same as it was)"
57+
- name: Bump covidcast-indicators version
58+
id: indicators
59+
run: |
60+
echo -n "::set-output name=version::"
61+
bump2version --list ${{ github.event.inputs.versionName }} | grep ^new_version | sed -r s,"^.*=",,
62+
- name: Create pull request into prod
63+
uses: peter-evans/create-pull-request@v3
64+
with:
65+
branch: release/indicators_v${{ steps.indicators.outputs.version }}_utils_v${{ steps.utils-changed.outputs.version }}${{ steps.utils-unchanged.outputs.version }}
66+
base: prod
67+
title: Release covidcast-indicators ${{ steps.indicators.outputs.version }}
68+
labels: chore
69+
reviewers: krivard
70+
assignees: krivard
71+
body: |
72+
Releasing:
73+
* covidcast-indicators ${{ steps.indicators.outputs.version }}
74+
* delphi-utils ${{ steps.utils-changed.outputs.version }}${{ steps.utils-unchanged.outputs.version }} ${{steps.utils-changed.outputs.msg }}${{ steps.utils-unchanged.outputs.msg }}

.github/workflows/publish-release.yml

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
name: Publish release
2+
3+
on:
4+
push:
5+
branches: [ prod ]
6+
workflow_dispatch:
7+
8+
jobs:
9+
correct_repository:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: fail on fork
13+
if: github.repository_owner != 'cmu-delphi'
14+
run: exit 1
15+
16+
check:
17+
runs-on: ubuntu-latest
18+
needs: correct_repository
19+
steps:
20+
- name: Check out code
21+
uses: actions/checkout@v2
22+
with:
23+
ssh-key: ${{ secrets.CMU_DELPHI_DEPLOY_MACHINE_SSH }}
24+
- name: Set up Python 3.8
25+
uses: actions/setup-python@v2
26+
with:
27+
python-version: 3.8
28+
- name: Install bump2version
29+
run: python -m pip install bump2version
30+
- name: Check for delphi-utils changes
31+
uses: dorny/paths-filter@v2
32+
id: changes
33+
with:
34+
# when base and ref are the same, changes are detected against the most recent commit before the push.
35+
# see https://github.com/dorny/paths-filter#usage for details.
36+
base: 'prod'
37+
ref: 'prod'
38+
filters: |
39+
utils:
40+
- '_delphi_utils_python/**'
41+
- name: Extract indicators version
42+
id: indicators
43+
run: |
44+
echo -n "::set-output name=version::"
45+
bump2version --dry-run --list patch | grep ^current_version | sed -r s,"^.*=",,
46+
- name: Tag indicators
47+
run: git tag covidcast-indicators/v${{ steps.indicators.outputs.version }}
48+
- name: Extract utils version
49+
id: utils
50+
working-directory: ./_delphi_utils_python
51+
run: |
52+
echo -n "::set-output name=version::"
53+
bump2version --dry-run --list patch | grep ^current_version | sed -r s,"^.*=",,
54+
- name: Tag utils
55+
if: ${{ steps.changes.outputs.utils == 'true' }}
56+
run: git tag delphi-utils/v${{ steps.utils.outputs.version }}
57+
- name: Publish tags
58+
run: git push --tags
59+
outputs:
60+
indicators-version: ${{ steps.indicators.outputs.version }}
61+
utils-version: ${{ steps.utils.outputs.version }}
62+
publish-utils: ${{ steps.changes.outputs.utils }}
63+
64+
upload_pypi:
65+
needs: check
66+
if: ${{ needs.check.outputs.publish-utils == 'true' }}
67+
runs-on: ubuntu-latest
68+
defaults:
69+
run:
70+
working-directory: _delphi_utils_python
71+
steps:
72+
- name: Check out code
73+
uses: actions/checkout@v2
74+
- name: Set up Python 3.8
75+
uses: actions/setup-python@v2
76+
with:
77+
python-version: 3.8
78+
- name: Install testing dependencies
79+
run: |
80+
python -m pip install --upgrade pip
81+
pip install pylint pytest pydocstyle wheel twine
82+
- name: Install
83+
run: |
84+
make install
85+
- name: Release
86+
run: |
87+
make release
88+
- uses: actions/upload-artifact@v2
89+
with:
90+
name: delphi_utils
91+
path: _delphi_utils_python/dist/*.tar.gz
92+
- name: Publish a Python distribution to PyPI
93+
uses: pypa/gh-action-pypi-publish@release/v1
94+
with:
95+
user: __token__
96+
password: ${{ secrets.DELPHI_PYPI_PROD_TOKEN }}
97+
packages_dir: _delphi_utils_python/dist/
98+
skip_existing: true
99+
100+
sync_main:
101+
needs: correct_repository
102+
runs-on: ubuntu-latest
103+
steps:
104+
- name: Check out code
105+
uses: actions/checkout@v2
106+
with:
107+
ref: main
108+
ssh-key: ${{ secrets.CMU_DELPHI_DEPLOY_MACHINE_SSH }}
109+
- name: Reset main branch
110+
run: |
111+
git fetch origin prod:prod
112+
git reset --hard prod
113+
- name: Create pull request into main
114+
uses: peter-evans/create-pull-request@v3
115+
with:
116+
token: ${{ secrets.CMU_DELPHI_DEPLOY_MACHINE_PAT }}
117+
branch: bot/sync-prod-main
118+
commit-message: 'chore: sync prod-main'
119+
base: main
120+
title: 'chore: sync prod->main'
121+
labels: chore
122+
reviewers: krivard
123+
assignees: krivard
124+
body: |
125+
Syncing Prod->Main.

.github/workflows/release-delphi-utils.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
name: Release Delphi Utils
1+
name: (Deprecated) Release Delphi Utils
22

33
on:
44
push:
55
branches:
6-
- prod
6+
- not_prod
77
paths:
88
- '_delphi_utils_python/**'
99
workflow_dispatch:

_delphi_utils_python/.bumpversion.cfg

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[bumpversion]
2-
current_version = 0.1.9
3-
commit = False
2+
current_version = 0.1.10
3+
commit = True
4+
message = chore: bump delphi_utils to {new_version}
45
tag = False
5-
tag_name = delphi-utils/v{new_version}
66

77
[bumpversion:file:setup.py]
88

_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.9"
17+
__version__ = "0.1.10"

_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.9",
27+
version="0.1.10",
2828
description="Shared Utility Functions for Indicators",
2929
long_description=long_description,
3030
long_description_content_type="text/markdown",

_template_python/REVIEW.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ outputs should be given for non-trivial functions
1414

1515
**Structure**
1616

17-
- [ ] code should use 4 spaces for indentation; other style decisions are
18-
flexible, but be consistent within a module
17+
- [ ] code should pass lint checks (`make lint`)
1918
- [ ] any required metadata files are checked into the repository and placed
2019
within the directory `static`
2120
- [ ] any intermediate files that are created and stored by the module should
@@ -29,11 +28,11 @@ included in this template file
2928

3029
**Testing**
3130

32-
- [ ] module can be installed in a new virtual environment
33-
- [ ] pylint with the default `.pylint` settings run over the module produces
34-
minimal warnings; warnings that do exist have been confirmed as false positives
31+
- [ ] module can be installed in a new virtual environment (`make install`)
3532
- [ ] reasonably high level of unit test coverage covering all of the main logic
3633
of the code (e.g., missing coverage for raised errors that do not currently seem
3734
possible to reach are okay; missing coverage for options that will be needed are
3835
not)
39-
- [ ] all unit tests run without errors
36+
- [ ] all unit tests run without errors (`make test`)
37+
- [ ] indicator directory has been added to GitHub CI
38+
(`covidcast-indicators/.github/workflows/python-ci.yml`)

_template_python/delphi_NAME/constants.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
"""
2-
Registry for signal names
2+
Registry for variations
33
"""
44

5+
## example:
6+
#GEOS = [
7+
# "nation",
8+
# "hhs",
9+
# "state",
10+
# "hrr",
11+
# "msa",
12+
# "county"
13+
#]
14+
15+
GEOS = []
516

617
## example:
718
# FULL_TIME = "full_time_work_prop"
@@ -15,3 +26,11 @@
1526
# ]
1627

1728
SIGNALS = []
29+
30+
## example:
31+
#SMOOTHERS = [
32+
# (Smoother("identity", impute_method=None), ""),
33+
# (Smoother("moving_average", window_length=7), "_7dav"),
34+
#]
35+
36+
SMOOTHERS = []

_template_python/delphi_NAME/run.py

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@
1414
unpublished signals are. See `delphi_utils.add_prefix()`
1515
- Any other indicator-specific settings
1616
"""
17-
from delphi_utils import add_prefix
18-
from .constants import SIGNALS
17+
from datetime import timedelta
18+
import pandas as pd
19+
import time
20+
21+
from delphi_utils.export import create_export_csv
22+
from delphi_utils.geomap import GeoMapper
23+
from delphi_utils import get_structured_logger
24+
25+
from .constants import GEOS, SIGNALS, SMOOTHERS
1926

2027
def run_module(params):
2128
"""
@@ -25,11 +32,46 @@ def run_module(params):
2532
--------
2633
params: Dict[str, Any]
2734
Nested dictionary of parameters.
28-
29-
Returns
30-
-------
31-
prints the updated signal names
3235
"""
33-
wip_signal = params["indicator"]["wip_signal"]
34-
signal_names = add_prefix(SIGNALS, wip_signal, prefix="wip_")
35-
print(signal_names)
36+
start_time = time.time()
37+
logger = get_structured_logger(
38+
__name__, filename=params["common"].get("log_filename"),
39+
log_exceptions=params["common"].get("log_exceptions", True))
40+
mapper = GeoMapper()
41+
run_stats = []
42+
## build the base version of the signal at the most detailed geo level you can get.
43+
## compute stuff here or farm out to another function or file
44+
all_data = pd.DataFrame(columns=["timestamp", "val", "zip", "sample_size", "se"])
45+
## aggregate & smooth
46+
## TODO: add num/prop variations if needed
47+
for sensor, smoother, geo in product(SIGNALS, SMOOTHERS, GEOS):
48+
df = mapper.replace_geocode(
49+
all_data, "zip", geo,
50+
new_col="geo_id",
51+
date_col="timestamp")
52+
## TODO: recompute sample_size, se here if not NA
53+
df["val"] = df[["geo_id", "val"]].groupby("geo_id")["val"].transform(
54+
smoother[0].smooth
55+
)
56+
sensor_name = sensor + smoother[1] ## TODO: +num/prop variation if used
57+
# don't export first 6 days for smoothed signals since they'll be nan.
58+
start_date = min(df.timestamp) + timedelta(6) if smoother[1] else min(df.timestamp)
59+
dates = create_export_csv(
60+
df,
61+
params["common"]["export_dir"],
62+
geo,
63+
sensor_name,
64+
start_date=start_date)
65+
if len(dates) > 0:
66+
run_stats.append((max(dates), len(dates)))
67+
## log this indicator run
68+
elapsed_time_in_seconds = round(time.time() - start_time, 2)
69+
min_max_date = run_stats and min(s[0] for s in run_stats)
70+
csv_export_count = sum(s[-1] for s in run_stats)
71+
max_lag_in_days = min_max_date and (datetime.now() - min_max_date).days
72+
formatted_min_max_date = min_max_date and min_max_date.strftime("%Y-%m-%d")
73+
logger.info("Completed indicator run",
74+
elapsed_time_in_seconds = elapsed_time_in_seconds,
75+
csv_export_count = csv_export_count,
76+
max_lag_in_days = max_lag_in_days,
77+
oldest_final_export_date = formatted_min_max_date)

0 commit comments

Comments
 (0)