Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trim whitespace on save #226

Merged
merged 1 commit into from
Apr 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions R/evaluators.R
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@

# inline execution evaluator
inline_evaluator <- function(expr, timelimit) {

result <- NULL

list(
start = function() {

# setTimeLimit -- if the timelimit is exceeeded an error will occur
# during knit which we will catch and format within evaluate_exercise
setTimeLimit(elapsed=timelimit, transient=TRUE);
on.exit(setTimeLimit(cpu=Inf, elapsed=Inf, transient=FALSE), add = TRUE);

# execute and capture result
result <<- force(expr)
},

completed = function() {
TRUE
},

result = function() {
result
}
Expand All @@ -28,12 +28,12 @@ inline_evaluator <- function(expr, timelimit) {

# forked execution evaluator
forked_evaluator <- function(expr, timelimit) {

# closure members
job <- NULL
start_time <- NULL
result <- NULL

# helper to call a hook function
call_hook <- function(name, default = NULL) {
hook <- getOption(paste0("tutorial.exercise.evaluator.", name))
Expand All @@ -42,70 +42,70 @@ forked_evaluator <- function(expr, timelimit) {
else if (!is.null(default))
default(job$pid)
}

# default cleanup function
default_cleanup <- function(pid) {
system(paste("kill -9", pid))
}

list(

start = function() {
start_time <<- Sys.time()
job <<- parallel::mcparallel(mc.interactive = FALSE, {

# close all connections
closeAllConnections()

# call onstart hook
call_hook("onstart")

# evaluate the expression
force(expr)
})
},

completed = function() {

# attempt to collect the result
collect <- parallel::mccollect(jobs = job, wait = FALSE, timeout = 0.01)

# got result
if (!is.null(collect)) {

# final reaping of process
parallel::mccollect(jobs = job, wait = FALSE)

# call cleanup hook
call_hook("oncleanup", default = default_cleanup)

# return result
result <<- collect[[1]]

# check if it's an error and convert it to an html error if it is
if(inherits(result, "try-error"))
result <<- error_result(result)

TRUE
}
}

# hit timeout
else if ((Sys.time() - start_time) >= timelimit) {

# call cleanup hook
call_hook("oncleanup", default = default_cleanup)

# return error result
result <<- error_result(timeout_error_message())
TRUE
}

# not yet completed
else {
FALSE
}
},

result = function() {
result
}
Expand Down
68 changes: 34 additions & 34 deletions R/events.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
record_event <- function(session, event, data) {
recorder <- getOption("tutorial.event_recorder", default = NULL)
if (!is.null(recorder)) {
recorder(tutorial_id = read_request(session, "tutorial.tutorial_id"),
recorder(tutorial_id = read_request(session, "tutorial.tutorial_id"),
tutorial_version = read_request(session, "tutorial.tutorial_version"),
user_id = read_request(session, "tutorial.user_id"),
event = event,
user_id = read_request(session, "tutorial.user_id"),
event = event,
data = data)
}
invisible(NULL)
Expand All @@ -21,8 +21,8 @@ broadcast_progress_event_to_client <- function(session, event, data) {
}

broadcast_question_event_to_client <- function(session, label, answer) {
broadcast_progress_event_to_client(session = session,
event = "question_submission",
broadcast_progress_event_to_client(session = session,
event = "question_submission",
data = list(label = label, answer = answer))
}
question_submission_event <- function(session,
Expand All @@ -37,16 +37,16 @@ question_submission_event <- function(session,
question = question,
answer = answer,
correct = correct))

# notify client side listeners
broadcast_question_event_to_client(session = session,
label = label,
broadcast_question_event_to_client(session = session,
label = label,
answer = answer)

# store submission for later replay
save_question_submission(session = session,
label = label,
question = question,
save_question_submission(session = session,
label = label,
question = question,
answer = answer)
}

Expand All @@ -57,7 +57,7 @@ reset_question_submission_event <- function(session, label, question) {
data = list(label = label,
question = question,
reset = TRUE))

# notify client side listeners
broadcast_progress_event_to_client(
session,
Expand All @@ -67,37 +67,37 @@ reset_question_submission_event <- function(session, label, question) {


# store submission for later replay
save_reset_question_submission(session = session,
label = label,
save_reset_question_submission(session = session,
label = label,
question = question)
}


section_skipped_event <- function(session, sectionId) {

# event data
event_data <- list(sectionId = sectionId)

# notify server-side listeners
record_event(session = session,
event = "section_skipped",
data = event_data)

# notify client side listeners
broadcast_progress_event_to_client(session = session,
broadcast_progress_event_to_client(session = session,
event = "section_skipped",
data = event_data)

# save for later replay
save_section_skipped(session = session, sectionId = sectionId)
}

exercise_submission_event <- function(session,
label,
code,
output,
label,
code,
output,
error_message,
checked = FALSE,
checked = FALSE,
feedback = NULL) {
# notify server-side listeners
record_event(session = session,
Expand All @@ -108,16 +108,16 @@ exercise_submission_event <- function(session,
error_message = error_message,
checked = checked,
feedback = feedback))

# notify client side listeners
if (checked)
correct <- feedback$correct
else
correct <- TRUE
broadcast_progress_event_to_client(session = session,
broadcast_progress_event_to_client(session = session,
event = "exercise_submission",
data = list(label = label, correct = correct))

# save submission for later replay
save_exercise_submission(
session = session,
Expand All @@ -131,20 +131,20 @@ exercise_submission_event <- function(session,
}

video_progress_event <- function(session, video_url, time, total_time) {

# data for event
data <- list(
video_url = video_url,
time = time,
total_time = total_time
)

# notify server side listeners
record_event(session = session,
event = "video_progress",
data = data)
# notify client side listeners

# notify client side listeners
broadcast_progress_event_to_client(session, "video_progress", data)

# save for later replay
Expand All @@ -153,10 +153,10 @@ video_progress_event <- function(session, video_url, time, total_time) {



debug_event_recorder <- function(tutorial_id,
debug_event_recorder <- function(tutorial_id,
tutorial_version,
user_id,
event,
user_id,
event,
data) {
cat(tutorial_id, " (", tutorial_version, "): ", user_id , "\n", sep = "")
cat("event: ", event, "\n", sep = "")
Expand Down
Loading