Add additional web output and figure handling

This commit is contained in:
Fabian Valka 2020-04-10 19:45:56 +02:00
Родитель 86369e1e62
Коммит 4891771d15
6 изменённых файлов: 44 добавлений и 70 удалений

58
.github/workflows/run-model-and-publish.yml поставляемый
Просмотреть файл

@ -1,58 +0,0 @@
# This is a basic workflow to help you get started with Actions
name: RUN_MODEL_AND_PUBLISH
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
# This workflow can be started manually by using the GitHub API
# send a POST request to https://api.github.com/repos/ImperialCollegeLondon/covid19model/dispatches
# with a an Authorization token <GitHub_Token> header and JSON payload:
# {"event_type": "run-and-publish"}
on:
repository_dispatch:
types: run-and-publish
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
run-and-publish:
# Set secret to enable the workflow
# The type of runner that the job will run on
runs-on: ubuntu-18.04
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# should throw an error if the token is not set, to enable the action only for repos which have set this token
- name: Check if access token is set
env:
SECRET_TEST: ${{ secrets.GH_PAGES_ACCESS_TOKEN }}
run: "[ -z \"$SECRET_TEST\" ] && exit 1 || exit 0 "
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
# Docker build
- name: Build docker image
run: |
docker build -f docker/Dockerfile -t covid19model:latest .
- name: Download the newest data from the ECDC
run: |
docker run --rm -v $(pwd):/var/model --user $(id -u):$(id -g) covid19model:latest Rscript data/fetch-ecdc.R
- name: Perform the full model run, aprox. 90 minutes
run: |
docker run --rm -v $(pwd):/var/model --user $(id -u):$(id -g) --env FULL=TRUE covid19model:latest
- name: Fix SVG font families for publishing
run: |
docker run --rm -v $(pwd):/var/model --user $(id -u):$(id -g) covid19model:latest Rscript web-fix-fonts.R
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
personal_token: ${{ secrets.GH_PAGES_ACCESS_TOKEN }}
external_repository: ImperialCollegeLondon/covid19estimates
publish_branch: master
publish_dir: ./web
keep_files: true

48
base.r
Просмотреть файл

@ -5,6 +5,7 @@ library(gdata)
library(dplyr)
library(tidyr)
library(EnvStats)
library(optparse)
countries <- c(
"Denmark",
@ -23,17 +24,43 @@ countries <- c(
"Netherlands"
)
# Commandline options and parsing
parser <- OptionParser()
parser <- add_option(parser, c("-D", "--debug"), action="store_true",
help="Perform a debug run of the model")
parser <- add_option(parser, c("-F", "--full"), action="store_true",
help="Perform a full run of the model")
cmdoptions <- parse_args(parser, args = commandArgs(trailingOnly = TRUE), positional_arguments = TRUE)
# Default run parameters for the model
DEBUG = FALSE
FULL = FALSE
if(is.null(cmdoptions$options$debug)) {
DEBUG = Sys.getenv("DEBUG") == "TRUE"
} else {
DEBUG = cmdoptions$options$debug
}
args = commandArgs(trailingOnly=TRUE)
if(length(args) == 0) {
args = 'base'
}
StanModel = args[1]
if(is.null(cmdoptions$options$full)) {
FULL = Sys.getenv("FULL") == "TRUE"
} else {
FULL = cmdoptions$options$full
}
if(DEBUG && FULL) {
stop("Setting both debug and full run modes at once is invalid")
}
if(length(cmdoptions$args) == 0) {
StanModel = 'base'
} else {
StanModel = cmdoptions$args[1]
}
print(sprintf("Running %s",StanModel))
if(DEBUG) {
print("Running in DEBUG mode")
} else if (FULL) {
print("Running in FULL mode")
}
## Reading all data
d=readRDS('data/COVID-19-up-to-date.rds')
@ -65,7 +92,6 @@ covariates$self_isolating_if_ill[covariates$self_isolating_if_ill > covariates$l
forecast = 0
DEBUG = FALSE
N2 = 90 # increase if you need more forecast
dates = list()
@ -202,10 +228,8 @@ m = stan_model(paste0('stan-models/',StanModel,'.stan'))
if(DEBUG) {
fit = sampling(m,data=stan_data,iter=40,warmup=20,chains=2)
} else if (FULL) {
fit = sampling(m,data=stan_data,iter=4000,warmup=2000,chains=8,thin=4,control = list(adapt_delta = 0.90, max_treedepth = 10))
fit = sampling(m,data=stan_data,iter=4000,warmup=2000,chains=4,thin=4,control = list(adapt_delta = 0.95, max_treedepth = 10))
} else {
# uncomment the line below for a full run to replicate results and comment the second line below
# fit = sampling(m,data=stan_data,iter=4000,warmup=2000,chains=4,thin=4,control = list(adapt_delta = 0.95, max_treedepth = 10))
fit = sampling(m,data=stan_data,iter=200,warmup=100,chains=4,thin=4,control = list(adapt_delta = 0.95, max_treedepth = 10))
}
@ -242,3 +266,5 @@ verify_result <- system(paste0("Rscript web-verify-output.r ", filename,'.Rdata'
if(verify_result != 0){
stop("Verification of web output failed!")
}
system("Rscript web-fix-fonts.r")

Просмотреть файл

@ -7,7 +7,7 @@ RUN apt-get update && apt-get install -y \
fonts-adf-verana
RUN install2.r --error --deps TRUE \
gdata EnvStats ggpubr svglite jsonlite \
gdata EnvStats ggpubr svglite jsonlite optparse \
&& rm -rf /tmp/downloaded_packages/ /tmp/*.rds
WORKDIR /var/model

Просмотреть файл

@ -9,5 +9,6 @@ dependencies:
- r-tidyr
- r-dplyr
- r-rstan
- r-optparse
channels:
- conda-forge

Просмотреть файл

@ -118,6 +118,10 @@ total_infected[order(total_infected$countries),c("countries","value")]
total_infected <- total_infected[,c("countries","value")]
write.csv(total_infected,paste0("results/total_infected_",date_till_percentage,".csv"),row.names=F)
# Store copy for web output
dir.create("web/data/", showWarnings = FALSE, recursive = TRUE)
write.csv(total_infected,paste0("web/data/total_infected.csv"),row.names=F)
fraction_obs_infected <- do.call(rbind, fraction_obs_infected)
fraction_obs_infected_df <- as.data.frame(fraction_obs_infected)
names(fraction_obs_infected_df) <- dates_italy

Просмотреть файл

@ -4,6 +4,7 @@ for( f in filenames ){
x <- readLines(f)
y <- gsub( "Aerial", "Arial, Helvetica, sans-serif", x )
y <- gsub( "Arimo", "Arial, Helvetica, sans-serif", x )
cat(y, file=f, sep="\n")
}