Skip to content

Commit 534dab3

Browse files
authored
Merge pull request #179 from cmu-delphi/release_v4.1
Release v4.1
2 parents cfbccbf + ca6174e commit 534dab3

File tree

4 files changed

+103
-50
lines changed

4 files changed

+103
-50
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: forecast-eval
22
Title: Forecast Evaluation Dashboard
3-
Version: 4.0
3+
Version: 4.1
44
Authors@R: person("Kate", "Harwood",
55
role = c("cre")),
66
person("Chris", "Scott",

Report/create_reports.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ prediction_cards_filepath = case_when(
2424
)
2525

2626
forecasters = unique(c(get_covidhub_forecaster_names(designations = c("primary", "secondary")),
27-
"COVIDhub-baseline", "COVIDhub-trained_ensemble"))
27+
"COVIDhub-baseline", "COVIDhub-trained_ensemble", "COVIDhub-4_week_ensemble"))
2828
locations = covidHubUtils::hub_locations
2929

3030
# also includes "us", which is national level data

dashboard/app.R

Lines changed: 89 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ ui <- fluidPage(padding=0, title="Forecast Eval Dashboard",
212212
)
213213

214214

215-
server <- function(input, output, session) {
215+
# Get and prepare data
216+
getS3Bucket <- function() {
216217
# Connect to AWS s3bucket
217218
Sys.setenv("AWS_DEFAULT_REGION" = "us-east-2")
218219
s3bucket = tryCatch(
@@ -224,40 +225,95 @@ server <- function(input, output, session) {
224225
return(NULL)
225226
}
226227
)
228+
229+
return(s3bucket)
230+
}
227231

228-
# Get and prepare data
229-
getData <- function(filename){
230-
if(!is.null(s3bucket)) {
231-
tryCatch(
232-
{
233-
s3readRDS(object = filename, bucket = s3bucket)
234-
},
235-
error = function(e) {
236-
e
237-
getFallbackData(filename)
238-
}
239-
)
240-
} else {
241-
getFallbackData(filename)
242-
}
232+
getData <- function(filename, s3bucket){
233+
if(!is.null(s3bucket)) {
234+
tryCatch(
235+
{
236+
s3readRDS(object = filename, bucket = s3bucket)
237+
},
238+
error = function(e) {
239+
e
240+
getFallbackData(filename)
241+
}
242+
)
243+
} else {
244+
getFallbackData(filename)
243245
}
246+
}
244247

245-
getFallbackData = function(filename) {
246-
path = ifelse(
247-
file.exists(filename),
248-
filename,
249-
file.path("../dist/",filename)
250-
)
251-
readRDS(path)
248+
getFallbackData = function(filename) {
249+
path = ifelse(
250+
file.exists(filename),
251+
filename,
252+
file.path("../dist/",filename)
253+
)
254+
readRDS(path)
255+
}
256+
257+
getAllData = function(s3bucket) {
258+
dfStateCases <- getData("score_cards_state_cases.rds", s3bucket)
259+
dfStateDeaths <- getData("score_cards_state_deaths.rds", s3bucket)
260+
dfNationCases = getData("score_cards_nation_cases.rds", s3bucket)
261+
dfNationDeaths = getData("score_cards_nation_deaths.rds", s3bucket)
262+
dfStateHospitalizations = getData("score_cards_state_hospitalizations.rds", s3bucket)
263+
dfNationHospitalizations = getData("score_cards_nation_hospitalizations.rds", s3bucket)
264+
265+
# Pick out expected columns only
266+
covCols = paste0("cov_", COVERAGE_INTERVALS)
267+
expectedCols = c("ahead", "geo_value", "forecaster", "forecast_date",
268+
"data_source", "signal", "target_end_date", "incidence_period",
269+
"actual", "wis", "sharpness", "ae", "value_50",
270+
covCols)
271+
272+
dfStateCases = dfStateCases %>% select(all_of(expectedCols))
273+
dfStateDeaths = dfStateDeaths %>% select(all_of(expectedCols))
274+
dfNationCases = dfNationCases %>% select(all_of(expectedCols))
275+
dfNationDeaths = dfNationDeaths %>% select(all_of(expectedCols))
276+
dfStateHospitalizations = dfStateHospitalizations %>% select(all_of(expectedCols))
277+
dfNationHospitalizations = dfNationHospitalizations %>% select(all_of(expectedCols))
278+
279+
df = rbind(dfStateCases, dfStateDeaths, dfNationCases, dfNationDeaths, dfStateHospitalizations, dfNationHospitalizations)
280+
df = df %>% rename("10" = cov_10, "20" = cov_20, "30" = cov_30, "40" = cov_40, "50" = cov_50, "60" = cov_60, "70" = cov_70, "80" = cov_80, "90" = cov_90, "95" = cov_95, "98" = cov_98)
281+
282+
return(df)
283+
}
284+
285+
getRecentDataHelper = function() {
286+
s3bucket <- getS3Bucket()
287+
df <- data.frame()
288+
289+
getRecentData = function() {
290+
newS3bucket <- getS3Bucket()
291+
292+
s3Contents <- s3bucket[attr(s3bucket, "names", exact=TRUE)]
293+
newS3Contents <- newS3bucket[attr(newS3bucket, "names", exact=TRUE)]
294+
295+
# Fetch new score data if contents of S3 bucket has changed (including file
296+
# names, sizes, and last modified timestamps). Ignores characteristics of
297+
# bucket and request, including bucket region, name, content type, request
298+
# date, request ID, etc.
299+
if ( nrow(df) == 0 || !identical(s3Contents, newS3Contents) ) {
300+
# Save new data and new bucket connection info to vars in env of
301+
# `getRecentDataHelper`. They persist between calls to `getRecentData` a
302+
# la https://stackoverflow.com/questions/1088639/static-variables-in-r
303+
s3bucket <<- newS3bucket
304+
df <<- getAllData(s3bucket)
305+
}
306+
307+
return(df)
252308
}
309+
310+
return(getRecentData)
311+
}
253312

254-
dfStateCases <- getData("score_cards_state_cases.rds")
255-
dfStateDeaths <- getData("score_cards_state_deaths.rds")
256-
dfNationCases = getData("score_cards_nation_cases.rds")
257-
dfNationDeaths = getData("score_cards_nation_deaths.rds")
258-
dfStateHospitalizations = getData("score_cards_state_hospitalizations.rds")
259-
dfNationHospitalizations = getData("score_cards_nation_hospitalizations.rds")
260-
DATA_LOADED = TRUE
313+
getRecentData <- getRecentDataHelper()
314+
315+
316+
server <- function(input, output, session) {
261317
TERRITORIES = c('AS', 'GU', 'MP', 'VI')
262318
PREV_AS_OF_DATA = reactiveVal(NULL)
263319
AS_OF_CHOICES = reactiveVal(NULL)
@@ -276,24 +332,10 @@ server <- function(input, output, session) {
276332
CURRENT_WEEK_END_DATE = reactiveVal(CASES_DEATHS_CURRENT)
277333
prevHospWeek <- seq(Sys.Date()-11,Sys.Date()-5,by='day')
278334
HOSP_CURRENT = prevHospWeek[weekdays(prevHospWeek)=='Wednesday']
279-
280-
281-
# Pick out expected columns only
282-
covCols = paste0("cov_", COVERAGE_INTERVALS)
283-
expectedCols = c("ahead", "geo_value", "forecaster", "forecast_date",
284-
"data_source", "signal", "target_end_date", "incidence_period",
285-
"actual", "wis", "sharpness", "ae", "value_50",
286-
covCols)
287-
288-
dfStateCases = dfStateCases %>% select(all_of(expectedCols))
289-
dfStateDeaths = dfStateDeaths %>% select(all_of(expectedCols))
290-
dfNationCases = dfNationCases %>% select(all_of(expectedCols))
291-
dfNationDeaths = dfNationDeaths %>% select(all_of(expectedCols))
292-
dfStateHospitalizations = dfStateHospitalizations %>% select(all_of(expectedCols))
293-
dfNationHospitalizations = dfNationHospitalizations %>% select(all_of(expectedCols))
294335

295-
df = rbind(dfStateCases, dfStateDeaths, dfNationCases, dfNationDeaths, dfStateHospitalizations, dfNationHospitalizations)
296-
df = df %>% rename("10" = cov_10, "20" = cov_20, "30" = cov_30, "40" = cov_40, "50" = cov_50, "60" = cov_60, "70" = cov_70, "80" = cov_80, "90" = cov_90, "95" = cov_95, "98" = cov_98)
336+
# Get scores
337+
df = getRecentData()
338+
DATA_LOADED = TRUE
297339

298340
# Prepare input choices
299341
forecasterChoices = sort(unique(df$forecaster))

docker_dashboard/Dockerfile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
FROM rocker/shiny-verse
22
LABEL org.opencontainers.image.source = "https://github.com/cmu-delphi/forecast-eval"
33

4+
RUN apt-get update && apt-get install -qq -y \
5+
libgdal-dev \
6+
libudunits2-dev
47

58
ADD docker_dashboard/shiny_server.conf /etc/shiny-server/shiny-server.conf
6-
RUN install2.r plotly shinyjs tsibble viridis aws.s3 covidcast stringr
9+
RUN install2.r --error \
10+
plotly \
11+
shinyjs \
12+
tsibble \
13+
viridis \
14+
aws.s3 \
15+
covidcast \
16+
stringr \
17+
markdown
718

819
COPY dist/*rds /srv/shiny-server/
920
COPY dashboard/* /srv/shiny-server/

0 commit comments

Comments
 (0)