Skip to content

Commit b3ea936

Browse files
committed
Quasi-final version of 02a_base, with complete user management and more explanations based on a "real-life" test
1 parent 66c0c9b commit b3ea936

File tree

10 files changed

+540
-108
lines changed

10 files changed

+540
-108
lines changed

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ export(checker_sdd)
44
export(record_sdd)
55
export(run)
66
export(send_mail_sdd)
7+
export(user_email)
8+
export(user_name)
79
importFrom(httr,GET)
810
importFrom(httr,authenticate)
911
importFrom(httr,content)

R/record_sdd.R

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#' @param event The event that triggers the record, like `exercise_submission`
77
#' or `question_submission`
88
#' @param data A JSON field with event-dependent data content.
9+
#' @param value The new value for user name or email (if not provided, the
10+
#' current value is returned).
911
#'
1012
#' @description Record tutorial submissions in a centralized database. The
1113
#' function is used by learnr tutorials and is not for end-users.
@@ -22,12 +24,6 @@ record_sdd <- function(tutorial_id, tutorial_version, user_id, event, data) {
2224
dir.create(dirname(file), showWarnings = FALSE, recursive = TRUE)
2325
cat(str, "\n", file = file, append = TRUE)
2426
}
25-
user_name <- suppressWarnings(system("git config user.name",
26-
intern = TRUE, ignore.stderr = TRUE))
27-
user_email <- suppressWarnings(system("git config user.email",
28-
intern = TRUE, ignore.stderr = TRUE))
29-
#user_full_id <- paste(user_id, user_name, user_email, sep = "/")
30-
date <- Sys.time()
3127
label <- data$label
3228
if (is.null(label)) label <- ""
3329
data$label <- NULL
@@ -38,9 +34,9 @@ record_sdd <- function(tutorial_id, tutorial_version, user_id, event, data) {
3834
correct <- ""
3935
}
4036
data$correct <- NULL
41-
entry <- data.frame(date = date, tutorial = tutorial_id,
42-
version = tutorial_version, user = user_id, user_name = user_name,
43-
user_email = user_email, label = label, correct = correct, event = event,
37+
entry <- data.frame(date = Sys.time(), tutorial = tutorial_id,
38+
version = tutorial_version, user = user_id, user_name = user_name(),
39+
user_email = user_email(), label = label, correct = correct, event = event,
4440
data = list_to_json(data))
4541
# Not a good idea: if user never clicks "Submit", nothing is fed to database
4642
#if (correct == "") {
@@ -86,3 +82,51 @@ collect_sdd <- function() {
8682
mdb$find()
8783
}
8884
#sdd_data <- collect_sdd(); View(sdd_data)
85+
86+
#' @export
87+
#' @rdname record_sdd
88+
user_name <- function(value) {
89+
if (missing(value)) {
90+
Sys.unsetenv("SDD_USER")
91+
user <- Sys.getenv("SDD_USER", unset = "")
92+
if (user == "") {
93+
user <- try(suppressWarnings(system("git config --global user.name",
94+
intern = TRUE, ignore.stderr = TRUE)), silent = TRUE)
95+
if (inherits(user, "try-error")) user <- ""
96+
}
97+
user
98+
} else {# Change user
99+
# Make sure new_user is correct
100+
new_user <- as.character(value)[1]
101+
new_user <- gsub(" ", "_", new_user)
102+
Sys.setenv(SDD_USER = new_user)
103+
cmd <- paste0("git config --global user.name '", new_user, "'")
104+
try(suppressWarnings(system(cmd, intern = TRUE, ignore.stderr = TRUE)),
105+
silent = TRUE)
106+
new_user
107+
}
108+
}
109+
110+
#' @export
111+
#' @rdname record_sdd
112+
user_email <- function(value) {
113+
if (missing(value)) {
114+
Sys.unsetenv("SDD_EMAIL")
115+
email <- Sys.getenv("SDD_EMAIL", unset = "")
116+
if (email == "") {
117+
email <- try(suppressWarnings(system("git config --global user.email",
118+
intern = TRUE, ignore.stderr = TRUE)), silent = TRUE)
119+
if (inherits(email, "try-error")) email <- ""
120+
}
121+
email
122+
} else {# Change email
123+
# Make sure new_email is correct
124+
new_email <- as.character(value)[1]
125+
new_email <- gsub(" ", "_", new_email)
126+
Sys.setenv(SDD_EMAIL = new_email)
127+
cmd <- paste0("git config --global user.email '", new_email, "'")
128+
try(suppressWarnings(system(cmd, intern = TRUE, ignore.stderr = TRUE)),
129+
silent = TRUE)
130+
new_email
131+
}
132+
}

TODO

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
= BioDataScience To Do list
1+
# BioDataScience To Do list
22

3-
* Integrate learnr documents.
3+
- Integrate learnr documents.
44

5-
* Datasets for the course.
5+
- Datasets for the course.
66

7-
* Create an RStudio addin to run tutorial and monitor progression.
7+
- Create an RStudio addin to run tutorial and monitor progression (and check if
8+
data is pending, and if so, propose to send it by email).
9+
10+
- Explanation about how to use the tutorial interface.
11+
12+
- Translate buttons (.js file).

inst/tutorials/02a_base/base.Rmd

Lines changed: 216 additions & 33 deletions
Large diffs are not rendered by default.

inst/tutorials/02a_base/base.html

Lines changed: 251 additions & 62 deletions
Large diffs are not rendered by default.
8.68 KB
Loading
10 KB
Loading
18.7 KB
Loading
-19 KB
Binary file not shown.

man/record_sdd.Rd

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)