Skip to content

Commit

Permalink
added logging
Browse files Browse the repository at this point in the history
  • Loading branch information
seankross committed Feb 18, 2016
1 parent f36ea38 commit 1b9bbea
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 11 deletions.
14 changes: 4 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
language: r
warnings_are_errors: true
sudo: required

env:
global:
- CRAN: http://cran.rstudio.com

before_install: echo "options(repos = c(CRAN='http://cran.rstudio.com'))" > ~/.Rprofile
language: R
cache: packages
sudo: false

notifications:
email:
on_success: always
on_failure: always
on_failure: always
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Description: Use the R console as an interactive learning
environment. Users receive immediate feedback as they are guided through
self-paced lessons in data science and R programming.
URL: http://swirlstats.com
Version: 2.3.1.9009
Version: 2.3.1.9010
License: MIT + file LICENSE
Authors@R: c(
person("Sean", "Kross", email = "[email protected]", role = c("aut", "cre")),
Expand Down
15 changes: 15 additions & 0 deletions R/instructionSet.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ testResponse <- function(current.row, e)UseMethod("testResponse")
testResponse.default <- function(current.row, e){
# Increment attempts counter
e$attempts <- 1 + e$attempts

if(isTRUE(getOption("swirl_logging"))){
e$log$question_number <- c(e$log$question_number, e$row)
e$log$attempt <- c(e$log$attempt, e$attempts)
e$log$datetime <- c(e$log$datetime, as.numeric(Sys.time()))
}

# Get answer tests
tests <- current.row[,"AnswerTests"]
if(is.na(tests) || tests == ""){
Expand All @@ -165,13 +172,21 @@ testResponse.default <- function(current.row, e){
}
correct <- !(FALSE %in% unlist(results))
if(correct){
if(isTRUE(getOption("swirl_logging"))){
e$log$correct <- c(e$log$correct, TRUE)
}

mes <- praise()
post_result(e, passed = correct, feedback = mes, hint = NULL)
e$iptr <- 1
e$row <- 1 + e$row
# Reset attempts counter, since correct
e$attempts <- 1
} else {
if(isTRUE(getOption("swirl_logging"))){
e$log$correct <- c(e$log$correct, FALSE)
}

# Restore the previous global environment from the official
# in case the user has garbled it, e.g., has typed x <- 3*x
# instead of x <- 2*x by mistake. The hint might say to type
Expand Down
7 changes: 7 additions & 0 deletions R/log.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
saveLog <- function(e)UseMethod("saveLog")

saveLog.default <- function(e){
# save log
suppressMessages(suppressWarnings(
saveRDS(e$log, file.path(e$udat, paste0(as.numeric(Sys.time()), ".swlog")))))
}
12 changes: 12 additions & 0 deletions R/menu.R
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,18 @@ mainMenu.default <- function(e){
e$progress <- file.path(e$udat, fname)
# indicator that swirl is not reacting to console input
e$playing <- FALSE

# Create log
if(isTRUE(getOption("swirl_logging"))){
e$log <- list(user = e$usr,
course_name = attr(e$les,"course_name"),
lesson_name = attr(e$les,"lesson_name"),
question_number = NULL,
correct = NULL,
attempt = NULL,
datetime = NULL)
}

# create the file
suppressMessages(suppressWarnings(saveRDS(e, e$progress)))
# post initialization message
Expand Down
6 changes: 6 additions & 0 deletions R/swirl.R
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,12 @@ resume.default <- function(e, ...){
# Reset skip count if it exists
if(exists("skips", e)) e$skips <- 0
clearCustomTests()

# Save log
if(isTRUE(getOption("swirl_logging"))){
saveLog(e)
}

# Let user know lesson is complete
swirl_out(s()%N%"You've reached the end of this lesson! Returning to the main menu...")
# let the user select another course lesson
Expand Down

0 comments on commit 1b9bbea

Please sign in to comment.