Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ jobs:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: cmu-delphi-deploy-machine
password: ${{ secrets.CMU_DELPHI_DEPLOY_MACHINE_PAT }}

# Runs a single command using the runners shell
- name: Run a one-line script
run: make
- name: Build and deploy dashboard docker image
run: |
make deploy_dashboard
43 changes: 34 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,48 @@
.DEFAULT_GOAL:=build
S3_URL=https://forecast-eval.s3.us-east-2.amazonaws.com
S3_BUCKET=s3://forecast-eval

build: score_forecast
build: build_dashboard

r_build:
docker build -t forecast-eval-build docker_build

predictions_cards.rds score_cards_state_deaths.rds score_cards_state_cases.rds: dist
test -f dist/$@ || curl -o dist/$@ $(S3_URL)/$@

pull_data: predictions_cards.rds score_cards_state_deaths.rds score_cards_state_cases.rds

dist:
mkdir $@

clean:
rm -rf dist
rm dashboard/*.rds

score_forecast: r_build dist
docker run --rm -v ${PWD}/Report:/var/forecast-eval -w /var/forecast-eval forecast-eval-build Rscript create_reports.R
score_forecast: r_build dist pull_data
docker run --rm \
-v ${PWD}/Report:/var/forecast-eval \
-v ${PWD}/dist:/var/dist \
-w /var/forecast-eval \
forecast-eval-build \
Rscript create_reports.R --dir /var/dist

deploy: score_forecast
aws s3 cp dist/ $(S3_BUCKET)/ --recursive --exclude "*" --include "*rds"

# Starts a docker image with a full preconfigured R environment
start_dev: r_build
docker run -ti --rm \
-v ${PWD}/Report:/var/forecast-eval \
-v ${PWD}/dashboard:/var/forecast-eval-dashboard \
-v ${PWD}/dist:/var/dist \
-w /var/forecast-eval \
ghcr.io/cmu-delphi/forecast-eval:latest bash

build_dashboard: pull_data
docker build -t ghcr.io/cmu-delphi/forecast-eval:latest -f docker_dashboard/Dockerfile .

start_repl: r_build
docker run -ti --rm forecast-eval-build bash
deploy_dashboard: build_dashboard
docker push ghcr.io/cmu-delphi/forecast-eval:latest

start_dashboard:
cp Report/*.rds dashboard
docker run --rm -p 3838:3838 -v ${PWD}/dashboard:/srv/shiny-server rocker/shiny-verse
start_dashboard: build_dashboard
docker run --rm -p 3838:3838 ghcr.io/cmu-delphi/forecast-eval:latest
32 changes: 29 additions & 3 deletions Report/create_reports.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
#!/usr/bin/env Rscript
library("optparse")
library("dplyr")

option_list = list(
make_option(
c("-d", "--dir"),
type="character",
default=".",
help="Directory to read/write data",
metavar="character"
)
);

opt_parser = OptionParser(option_list=option_list);
opt = parse_args(opt_parser);

prediction_cards_filename = "predictions_cards.rds"
prediction_cards_filepath = case_when(
!is.null(opt$dir) ~ file.path(opt$dir,prediction_cards_filename),
TRUE~prediction_cards_filename
)

source("predictions.R")
create_prediction_cards()
create_prediction_cards(prediction_cards_filepath)

source("score.R")
create_score_cards("state", signal = "confirmed_incidence_num")
create_score_cards("state", signal = "deaths_incidence_num")
print("Scoring confirmed incidence...")
create_score_cards(prediction_cards_filepath, "state", signal = "confirmed_incidence_num", output_dir=opt$dir)
print("Scoring deaths incidence...")
create_score_cards(prediction_cards_filepath, "state", signal = "deaths_incidence_num", output_dir=opt$dir)
print("Done")
20 changes: 13 additions & 7 deletions Report/predictions.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
library(lubridate)
library(evalcast)
library(dplyr)
library(stringr)

# TODO: Use `get_covidhub_forecaster_names()` instead of listing forecasters
create_prediction_cards = function(){
create_prediction_cards = function(prediction_cards_filename){
start_date = today() - 100 * 7 # last 12 weeks

forecasters = get_covidhub_forecaster_names()
num_forecasters = length(forecasters)
print(str_interp("Getting forecasts for ${num_forecasters} forecasters."))

# Get all forecast dates for these forecasters from COVID Hub
forecast_dates = vector("list", length = length(forecasters))
Expand All @@ -25,12 +28,14 @@ create_prediction_cards = function(){
# that case it's no longer a true prediction. We can always restart from scratch
# by deleting predictions_cards.rds.

if (file.exists("predictions_cards.rds")) {
predictions_cards = readRDS(file = "predictions_cards.rds")
}
if(exists("predictions_cards")){
if (file.exists(prediction_cards_filename)) {
print("Reading from existing prediction cards")
predictions_cards = readRDS(file = prediction_cards_filename)
seen_dates = predictions_cards %>%
distinct(forecast_date, forecaster)
print("Existing prediction cards loaded")
}else{
print("No prediction cards found, will need to regenerate.")
}

# new_dates, as opposed to dates for which we already have data for a forecaster
Expand All @@ -51,6 +56,7 @@ create_prediction_cards = function(){
}
new_dates[[i]] = comparable_forecast_dates
}

names(new_dates) = forecasters

# Now get new predictions for each forecaster
Expand All @@ -59,7 +65,7 @@ create_prediction_cards = function(){
deaths_sig = "deaths_incidence_num"
cases_sig = "confirmed_incidence_num"
for (i in 1:length(forecasters)) {
cat(forecasters[i], "...\n")
cat(str_interp("${i}/${num_forecasters}:${forecasters[i]} ...\n"))
if (length(new_dates[[i]] > 0)){
predictions_cards_list[[i]] = tryCatch({
get_covidhub_predictions(forecasters[i],
Expand Down Expand Up @@ -89,6 +95,6 @@ create_prediction_cards = function(){

predictions_cards$data_source = "usa-facts"
saveRDS(predictions_cards,
file = "predictions_cards.rds",
file = prediction_cards_filename,
compress = "xz")
}
Binary file removed Report/predictions_cards.rds
Binary file not shown.
6 changes: 3 additions & 3 deletions Report/score.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ library("dplyr")
library("lubridate")
library("assertthat")

create_score_cards = function(geo_type, signal_name = NULL, output_file_name = NULL){
create_score_cards = function(prediction_cards_filepath, geo_type, signal_name = NULL, output_file_name = NULL, output_dir="."){
if (!exists("predictions_cards")){
predictions_cards = readRDS("predictions_cards.rds")
predictions_cards = readRDS(prediction_cards_filepath)
}
signals = (predictions_cards %>% distinct(signal))$signal
if (is.null(signal_name)){
Expand All @@ -29,7 +29,7 @@ create_score_cards = function(geo_type, signal_name = NULL, output_file_name = N
} else {
sig_suffix = "deaths"
}
output_file_name = paste0("score_cards_", geo_type, "_", sig_suffix, ".rds")
output_file_name = file.path(output_dir,paste0("score_cards_", geo_type, "_", sig_suffix, ".rds"))
}
# central coverage functions named cov_10, cov_20, etc.
central_intervals = c(0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.95, 0.98)
Expand Down
Binary file removed Report/score_cards_state_cases.rds
Binary file not shown.
Binary file removed Report/score_cards_state_deaths.rds
Binary file not shown.
14 changes: 12 additions & 2 deletions dashboard/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,18 @@ library(ggplot2)
library(RColorBrewer)
library(stringr)

dfCases <- readRDS("../Report/score_cards_state_cases.rds")
dfDeaths <- readRDS("../Report/score_cards_state_deaths.rds")

getData <- function(filename){
path = ifelse(
file.exists(filename),
filename,
file.path("../dist/",filename)
)
readRDS(path)
}

dfCases <- getData("score_cards_state_cases.rds")
dfDeaths <- getData("score_cards_state_deaths.rds")
df <- rbind(dfCases, dfDeaths)
modelChoices = sort(unique(df$forecaster))
aheadChoices = unique(df$ahead)
Expand Down
Loading