Skip to content

Commit 92b38cc

Browse files
committed
2 parents 20881ac + a76ce42 commit 92b38cc

File tree

55 files changed

+325819
-41866
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+325819
-41866
lines changed

.github/workflows/pull_baselines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
required: false
1212
default: true
1313
schedule:
14-
- cron: "20 19 * * 3"
14+
- cron: "10 17 * * 3"
1515

1616
permissions:
1717
contents: write
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Pull ensembles
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
name:
6+
description: 'Pull Ensembles'
7+
required: false
8+
publish:
9+
description: 'Pull ensemble forecasts'
10+
type: boolean
11+
required: false
12+
default: true
13+
14+
permissions:
15+
contents: write
16+
pull-requests: write
17+
18+
jobs:
19+
pull_ensembles:
20+
if: github.repository_owner == 'cdcepi'
21+
runs-on: macOS-latest
22+
steps:
23+
- name: Checkout repo
24+
uses: actions/checkout@v3
25+
with:
26+
fetch-depth: 0
27+
- name: Setup R
28+
uses: r-lib/actions/setup-r@v2
29+
with:
30+
use-public-rspm: true
31+
- name: Install dependencies
32+
run: |
33+
install.packages("pak")
34+
pak::pkg_install(c(
35+
"readr", "dplyr", "tidyr",
36+
"lubridate", "fs",
37+
"github::hubverse-org/hubValidations"))
38+
shell: Rscript {0}
39+
- name: Pull ensemble csv files
40+
run: Rscript auxiliary-data/pull-flusight-ensembles.R
41+
- name: Show validation output in logs (for debugging)
42+
run: cat validation_result.md || echo "No validation_result.md found"
43+
- name: Read validation result
44+
id: validation
45+
run: |
46+
{
47+
echo 'body<<EOF'
48+
cat validation_result.md
49+
echo 'EOF'
50+
} >> "$GITHUB_OUTPUT"
51+
- name: Commit changes and create PR 🚀
52+
if: ${{ inputs.publish || github.event_name == 'schedule' }}
53+
env:
54+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55+
run: |
56+
PR_DATETIME=$(date +'%Y-%m-%d_%H-%M-%S')
57+
git config user.name "github-actions[bot]"
58+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
59+
git checkout -b pull/ensembles/"$PR_DATETIME"
60+
git add .
61+
git commit -m "Pull ensemble forecasts"
62+
git push --set-upstream origin pull/ensembles/"$PR_DATETIME"
63+
gh pr create --title "Add new ensemble forecasts" \
64+
--body "${{ steps.validation.outputs.body }}" \
65+
--base main \
66+
--head pull/ensembles/"$PR_DATETIME"
67+
shell: bash
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
2+
# Script that runs with the Pull ensembles action to download and save the weekly ensembles from the FluSight-ensemble repository.
3+
# Retrieves specifically FluSight-ensemble, FluSight-lop_norm, FluSight-trained_mean, FluSight-trained_median, FluSight-baseline_cat,FluSight-equal_cat, and
4+
# FluSight-ens_q_cat.
5+
# Runs Hub Validations on the files.
6+
7+
# Load required libraries
8+
library(lubridate)
9+
library(hubValidations)
10+
library(fs)
11+
12+
# Prepare output file for PR body
13+
result_file <- "validation_result.md"
14+
15+
# Wrap the entire script in a top-level tryCatch
16+
tryCatch({
17+
18+
# Set up reference date and file names
19+
current_ref_date <- ceiling_date(Sys.Date(), "week") - days(1)
20+
date_str <- format(current_ref_date, "%Y-%m-%d")
21+
22+
ensemble_types <- c("FluSight-ensemble",
23+
"FluSight-lop_norm",
24+
"FluSight-trained_mean",
25+
"FluSight-trained_med",
26+
"FluSight-baseline_cat",
27+
"FluSight-equal_cat",
28+
"FluSight-ens_q_cat")
29+
ensemble_folders <- ensemble_types
30+
31+
downloaded_files <- c()
32+
validation_results <- list()
33+
34+
for (i in seq_along(ensemble_types)) {
35+
type <- ensemble_types[i]
36+
folder <- ensemble_folders[i]
37+
filename <- paste0(date_str, "-", type, ".csv")
38+
39+
file_url <- paste0(
40+
"https://raw.githubusercontent.com/cdcepi/Flusight-ensemble/main/model-output/",
41+
folder, "/", filename
42+
)
43+
44+
target_dir <- file.path("model-output", type)
45+
dir_create(target_dir, recurse = TRUE)
46+
destfile <- file.path(target_dir, filename)
47+
48+
# Attempt to download
49+
download_success <- tryCatch({
50+
download.file(url = file_url, destfile = destfile, method = "libcurl")
51+
cat("✅ Downloaded and saved:", destfile, "\n")
52+
downloaded_files <- c(downloaded_files, file.path(type, filename))
53+
TRUE
54+
}, error = function(e) {
55+
msg <- paste("❌ Failed to download", filename, "Reason:", e$message)
56+
cat(msg, "\n")
57+
validation_results[[file.path(type, filename)]] <- list(status = "error", message = msg)
58+
FALSE
59+
})
60+
61+
# Only attempt validation if download succeeded
62+
if (download_success) {
63+
file_path <- file.path(type, filename)
64+
result <- tryCatch({
65+
v <- hubValidations::validate_submission(hub_path = ".", file_path = file_path)
66+
67+
# Try to check for validation errors
68+
err_msg <- tryCatch({
69+
hubValidations::check_for_errors(v, verbose = TRUE)
70+
NULL # Passed
71+
}, error = function(e) {
72+
e$message # Return error message
73+
})
74+
75+
list(status = if (is.null(err_msg)) "pass" else "fail", message = err_msg)
76+
77+
}, error = function(e) {
78+
list(status = "error", message = e$message)
79+
})
80+
81+
validation_results[[file_path]] <- result
82+
}
83+
}
84+
85+
# Compose validation_result.md content
86+
messages <- c("### 🧪 Validation Results")
87+
88+
for (file in names(validation_results)) {
89+
res <- validation_results[[file]]
90+
if (res$status == "pass") {
91+
messages <- c(messages, paste0("✅ **", file, "** passed validation."))
92+
} else {
93+
messages <- c(messages, paste0("❌ **", file, "**: ", res$message))
94+
}
95+
}
96+
97+
writeLines(messages, result_file)
98+
99+
}, error = function(e) {
100+
writeLines(c("### 🧪 Validation Results", "❌ Script failed unexpectedly:", e$message), result_file)
101+
})

0 commit comments

Comments
 (0)