44# cd /data1
55# sudo mkdir C03_challenge
66# sudo chown rstudio-connect: C03_challenge
7- # Then, put wine2quality.rds (from sdd_preparation ) into that directory
7+ # Then, put wine2quality.rds (from sdd_preparation) into that directory
88# scp wine2quality.rds econum@sdd.umons.ac.be:.
99# sudo mv /home/econum/wine2quality.rds /data1/C03_challenge
1010# sudo chown rstudio-connect:/data1/C03_challenge/wine2quality.rds
@@ -19,7 +19,9 @@ library(flipdownr)
1919
2020# Indicate title and deadline here
2121title <- " Challenge vins"
22- deadline <- " 2020-11-16 20:00:00"
22+ # Note: define real deadline in environment variables in RStudio Connect
23+ deadline <- Sys.getenv(" CHALLENGE_DEADLINE" ,
24+ unset = " 2020-01-01 00:00:00" )
2325
2426# Read data from the SQLite database
2527dir <- " /data1/C03_challenge"
@@ -33,6 +35,11 @@ wine2quality <- read$rds(file.path(dir, "wine2quality.rds"))$value
3335is_done <- function ()
3436 as.POSIXct(deadline ) < Sys.time()
3537
38+ # If the time difference between current date and countdown
39+ # is more than 100 days, we consider the next challenge has not started yet
40+ not_started_yet <- function ()
41+ difftime(Sys.time(), as.POSIXct(deadline ), units = " days" ) > 100
42+
3643# The function that calculates score and returns also a message
3744score_model <- function (x , reference = wine2quality ) {
3845 if (! is.factor(x ))
@@ -60,7 +67,7 @@ score_model <- function(x, reference = wine2quality) {
6067 round(prec * 100 , 1 ), " %. Votre proposition n'est pas retenue !" )))
6168 # Le classement du modèle se fait sur base du rappel pour la classe "excellent"
6269 recall <- res [" excellent" , " Recall" ]
63- score <- recall * 100 # In percents
70+ score <- recall * 100 # In percents
6471 structure(score ,
6572 message = paste0(" Votre proposition est accept\u 00e9e. Son score est de " ,
6673 round(score , 3 ), " ." ))
@@ -84,7 +91,7 @@ save_data <- function(data) {
8491 paste(data , collapse = " ', '" )
8592 )
8693 # Submit the update query and disconnect
87- dbGetQuery (db , query )
94+ dbSendStatement (db , query )
8895 dbDisconnect(db )
8996}
9097
@@ -132,7 +139,11 @@ server <- function(input, output) {
132139 validate(need(ext == " rds" , " Vous devez indiquer un fichier RDS" ))
133140 # Check that there is still time remaining
134141 if (is_done()) {
135- " Ce challenge est fini, vous ne pouvez plus soumettre de proposition !"
142+ if (not_started_yet()) {
143+ " Ce challenge n'a pas encore commenc\u 00e9, attendez le d\u 00e9part !"
144+ } else {
145+ " Ce challenge est fini, vous ne pouvez plus soumettre de proposition !"
146+ }
136147 } else {
137148 # Check that filename is correct (repos__model.rds)
138149 if (! grepl(" ^.+__.+\\ .rds" , file $ name )) {
0 commit comments