@@ -10,9 +10,22 @@ library(tsibble)
1010library(aws.s3 )
1111library(covidcast )
1212library(stringr )
13+ library(memoise )
1314
1415source(' ./common.R' )
1516
17+ # Set application-level caching location. Stores up to 1GB of caches. Removes
18+ # least recently used objects first.
19+ shinyOptions(cache = cachem :: cache_mem(max_size = 1000 * 1024 ^ 2 , evict = " lru" ))
20+ cache <- getShinyOption(" cache" )
21+
22+ # Since covidcast data updates about once a day. Add date arg to
23+ # covidcast_signal so caches aren't used after that.
24+ covidcast_signal_mem <- function (... , date = Sys.Date()) {
25+ return (covidcast_signal(... ))
26+ }
27+ covidcast_signal_mem <- memoise(covidcast_signal_mem , cache = cache )
28+
1629# All data is fully loaded from AWS
1730DATA_LOADED = FALSE
1831
@@ -88,7 +101,7 @@ ui <- fluidPage(padding=0, title="Forecast Eval Dashboard",
88101 " Log Scale" ,
89102 value = FALSE ,
90103 )),
91- conditionalPanel(condition = " input.scoreType != 'coverage' && input.targetVariable != 'Hospitalizations' " ,
104+ conditionalPanel(condition = " input.scoreType != 'coverage'" ,
92105 checkboxInput(
93106 " scaleByBaseline" ,
94107 " Scale by Baseline Forecaster" ,
@@ -321,16 +334,15 @@ server <- function(input, output, session) {
321334
322335 # Get most recent target end date
323336 # Prev Saturday for Cases and Deaths, prev Wednesday for Hospitalizations
324- # Since we don't upload new observed data until Monday:
325- # Use 8 and 2 for Cases and Deaths so that Sundays will not use the Saturday directly beforehand
326- # since we don't have data for it yet.
327- # Use 5 and 11 for Hospitalizations since Thurs-Sun should also not use the Wednesday directly beforehand.
328- # (This means that on Mondays until the afternoon when pipeline completes, the "as of" will show
329- # most recent Saturday / Wednesday date even though the actual updated data won't be there yet)
330- prevWeek <- seq(Sys.Date()- 8 ,Sys.Date()- 2 ,by = ' day' )
337+ # Since we don't upload new observed data until Sunday:
338+ # Use 7 and 1 for Cases and Deaths so that Sundays will use the Saturday directly beforehand.
339+ # Use 4 and 10 for Hospitalizations since Thurs-Sat should not use the Wednesday directly beforehand.
340+ # (This means that on Sundays until the afternoon when the pipeline completes, the "as of" will show
341+ # the most recent Saturday / Wednesday date even though the actual updated data won't be there yet)
342+ prevWeek <- seq(Sys.Date()- 7 ,Sys.Date()- 1 ,by = ' day' )
331343 CASES_DEATHS_CURRENT = prevWeek [weekdays(prevWeek )== ' Saturday' ]
332344 CURRENT_WEEK_END_DATE = reactiveVal(CASES_DEATHS_CURRENT )
333- prevHospWeek <- seq(Sys.Date()- 11 ,Sys.Date()- 5 ,by = ' day' )
345+ prevHospWeek <- seq(Sys.Date()- 10 ,Sys.Date()- 4 ,by = ' day' )
334346 HOSP_CURRENT = prevHospWeek [weekdays(prevHospWeek )== ' Wednesday' ]
335347
336348 # Get scores
@@ -469,7 +481,7 @@ server <- function(input, output, session) {
469481 filteredScoreDf = filteredScoreDf [c(" Forecaster" , " Forecast_Date" , " Week_End_Date" , " Score" , " ahead" )]
470482 filteredScoreDf = filteredScoreDf %> % mutate(across(where(is.numeric ), ~ round(. , 2 )))
471483 if (input $ scoreType != ' coverage' ) {
472- if (input $ scaleByBaseline && input $ targetVariable != " Hospitalizations " ) {
484+ if (input $ scaleByBaseline ) {
473485 baselineDf = filteredScoreDf %> % filter(Forecaster %in% ' COVIDhub-baseline' )
474486 filteredScoreDfMerged = merge(filteredScoreDf , baselineDf , by = c(" Week_End_Date" ," ahead" ))
475487 # Scaling score by baseline forecaster
@@ -915,7 +927,7 @@ server <- function(input, output, session) {
915927 fetchDate = as.Date(input $ asOf ) + 1
916928
917929 # Covidcast API call
918- asOfTruthData = covidcast_signal (data_source = dataSource , signal = targetSignal ,
930+ asOfTruthData = covidcast_signal_mem (data_source = dataSource , signal = targetSignal ,
919931 start_day = " 2020-02-15" , end_day = fetchDate ,
920932 as_of = fetchDate ,
921933 geo_type = location )
0 commit comments