@@ -10,9 +10,22 @@ library(tsibble)
10
10
library(aws.s3 )
11
11
library(covidcast )
12
12
library(stringr )
13
+ library(memoise )
13
14
14
15
source(' ./common.R' )
15
16
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
+
16
29
# All data is fully loaded from AWS
17
30
DATA_LOADED = FALSE
18
31
@@ -88,7 +101,7 @@ ui <- fluidPage(padding=0, title="Forecast Eval Dashboard",
88
101
" Log Scale" ,
89
102
value = FALSE ,
90
103
)),
91
- conditionalPanel(condition = " input.scoreType != 'coverage' && input.targetVariable != 'Hospitalizations' " ,
104
+ conditionalPanel(condition = " input.scoreType != 'coverage'" ,
92
105
checkboxInput(
93
106
" scaleByBaseline" ,
94
107
" Scale by Baseline Forecaster" ,
@@ -321,16 +334,15 @@ server <- function(input, output, session) {
321
334
322
335
# Get most recent target end date
323
336
# 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' )
331
343
CASES_DEATHS_CURRENT = prevWeek [weekdays(prevWeek )== ' Saturday' ]
332
344
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' )
334
346
HOSP_CURRENT = prevHospWeek [weekdays(prevHospWeek )== ' Wednesday' ]
335
347
336
348
# Get scores
@@ -469,7 +481,7 @@ server <- function(input, output, session) {
469
481
filteredScoreDf = filteredScoreDf [c(" Forecaster" , " Forecast_Date" , " Week_End_Date" , " Score" , " ahead" )]
470
482
filteredScoreDf = filteredScoreDf %> % mutate(across(where(is.numeric ), ~ round(. , 2 )))
471
483
if (input $ scoreType != ' coverage' ) {
472
- if (input $ scaleByBaseline && input $ targetVariable != " Hospitalizations " ) {
484
+ if (input $ scaleByBaseline ) {
473
485
baselineDf = filteredScoreDf %> % filter(Forecaster %in% ' COVIDhub-baseline' )
474
486
filteredScoreDfMerged = merge(filteredScoreDf , baselineDf , by = c(" Week_End_Date" ," ahead" ))
475
487
# Scaling score by baseline forecaster
@@ -915,7 +927,7 @@ server <- function(input, output, session) {
915
927
fetchDate = as.Date(input $ asOf ) + 1
916
928
917
929
# Covidcast API call
918
- asOfTruthData = covidcast_signal (data_source = dataSource , signal = targetSignal ,
930
+ asOfTruthData = covidcast_signal_mem (data_source = dataSource , signal = targetSignal ,
919
931
start_day = " 2020-02-15" , end_day = fetchDate ,
920
932
as_of = fetchDate ,
921
933
geo_type = location )
0 commit comments