Skip to content

Commit 28bf80f

Browse files
committed
Adapt to the new database scheme (h5p + learnr + shiny -> events)
1 parent 1a829b9 commit 28bf80f

11 files changed

Lines changed: 63 additions & 40 deletions

File tree

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ Makefile
2222
^CODE_OF_CONDUCT\.md$
2323
^revdep$
2424
data-raw
25+
rsconnect

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ vignettes/*.pdf
3131
*_cache/
3232
/cache/
3333

34+
# RSconnect
35+
rsconnect/
36+
3437
# Temporary files created by R markdown
3538
*.utf8.md
3639
*.knit.md

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: learnitprogress
22
Type: Package
3-
Version: 0.9.0
3+
Version: 0.10.0
44
Title: Report Student Progress in 'LearnIt::R' Courses
55
Description: A Shiny app that connects to you LRS ("Learning Record Store"
66
database, as created and managed by the 'learnitdown' package) and displays a
@@ -33,7 +33,7 @@ License: MIT + file LICENSE
3333
URL: https://github.com/learnitr/learnitprogress, https://learnitr.github.io/learnitprogress/
3434
BugReports: https://github.com/learnitr/learnitprogress/issues
3535
Roxygen: list(markdown = TRUE)
36-
RoxygenNote: 7.2.3
36+
RoxygenNote: 7.3.1
3737
VignetteBuilder: knitr
3838
Encoding: UTF-8
3939
Language: en-US

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# learnitprogress 0.10.0
2+
3+
- Update code for new database structure (h5p + shiny + learnr -> events).
4+
15
# learnitprogress 0.9.0
26

37
- Code developed so far is now placed in the {learnitprogress} package.

R/class.R

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ class_aa <- function(aa, url = getOption("learnitr.lrs_url"), as.json = FALSE,
8383
if (isTRUE(as.json)) {
8484
switch(aa,
8585
sdd1mq1 = ,
86-
sdd1cq1 = '{ "$regex": "^A0[1-6][^A]", "$options": "" }',
86+
sdd1cq1 = '{ "$regex": "^A0[1-5][^A]", "$options": "" }',
8787
sdd1mq2 = ,
88-
sdd1cq2 = '{ "$regex": "^A(0[7-9])|(1[0-2])[^A]", "$options": "" }',
88+
sdd1cq2 = '{ "$regex": "^A(0[6-9])|(10)[^A]", "$options": "" }',
8989
sdd1mq3 = ,
9090
sdd1cq3 = '{ "$regex": "^A(0[1-9])|(1[0-2])[^A]", "$options": "" }',
9191
sdd2mq1 = ,
@@ -95,17 +95,17 @@ class_aa <- function(aa, url = getOption("learnitr.lrs_url"), as.json = FALSE,
9595
#sdd2cq3 = '{ "$regex": "^B(09)|(1[0-2])[^A]", "$options": "" }',
9696
sdd2mq3 = ,
9797
sdd2cq3 = '{ "$regex": "^B(0[1-9])|(10)[^A]", "$options": "" }',
98-
sdd3mq1 = '{ "$regex": "^C0[1-6][^A]", "$options": "" }',
99-
sdd3mq3 = '{ "$regex": "^C0[1-6][^A]", "$options": "" }',
100-
sdd4mq1 = '{ "$regex": "^D0[1-6][^A]", "$options": "" }',
98+
sdd3mq1 = '{ "$regex": "^C0[1-5][^A]", "$options": "" }',
99+
sdd3mq3 = '{ "$regex": "^C0[1-5][^A]", "$options": "" }',
100+
sdd4mq1 = '{ "$regex": "^D0[1-5][^A]", "$options": "" }',
101101
#sdd5mq1 = '{ "$regex": "^E0[1-4][^A]", "$options": "" }',
102102
stop("Not implemented for this aa"))
103103
} else {
104104
switch(aa,
105105
sdd1mq1 = ,
106-
sdd1cq1 = "^A0[1-6][^A]",
106+
sdd1cq1 = "^A0[1-5][^A]",
107107
sdd1mq2 = ,
108-
sdd1cq2 = "^A(0[7-9])|(1[0-2])[^A]",
108+
sdd1cq2 = "^A(0[6-9])|(10)[^A]",
109109
sdd1mq3 = ,
110110
sdd1cq3 = "^A(0[1-9])|(1[0-2])[^A]",
111111
sdd2mq1 = ,
@@ -114,9 +114,9 @@ class_aa <- function(aa, url = getOption("learnitr.lrs_url"), as.json = FALSE,
114114
sdd2cq2 = "^B(0[6-9])|(10)[^A]",
115115
sdd2mq3 = ,
116116
sdd2cq3 = "^B(0[1-9])|(10)[^A]",
117-
sdd3mq1 = "^C0[1-6][^A]",
118-
sdd3mq3 = "^C0[1-6][^A]",
119-
sdd4mq1 = "^D0[1-6][^A]",
117+
sdd3mq1 = "^C0[1-5][^A]",
118+
sdd3mq3 = "^C0[1-5][^A]",
119+
sdd4mq1 = "^D0[1-5][^A]",
120120
#sdd5mq1 = "^E0[1-4][^A]",
121121
stop("Not implemented for this aa"))
122122
}
@@ -127,7 +127,7 @@ class_aa <- function(aa, url = getOption("learnitr.lrs_url"), as.json = FALSE,
127127
#' @rdname class_logins
128128
#' @param email The email of the student
129129
user_login <- function(email, url = getOption("learnitr.lrs_url")) {
130-
# Make xsure email is in lowercase
130+
# Make sure email is in lowercase
131131
email <- tolower(email)
132132
# Get the login associated with a given email address
133133
# In case we have several login, return the most recent one

R/progression.R

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,18 @@ shiny_prog <- function(user_login, class_logins, class_aa, class_data = NULL,
9797
# Get Learnr data for a whole class
9898
learnr_class_prog <- function(class_logins, class_aa,
9999
url = getOption("learnitr.lrs_url")) {
100-
mdb_learnr <- try(mongolite::mongo("learnr", url = url), silent = TRUE)
100+
mdb_learnr <- try(mongolite::mongo("events", url = url), silent = TRUE)
101101
if (inherits(mdb_learnr, "try-error"))
102102
stop("Error: impossible to connect to the learnr database")
103103

104-
if (!mdb_learnr$count(paste0('{ "login": ', class_logins, ',
104+
if (!mdb_learnr$count(paste0('{ "type" : "learnr", "login": ', class_logins, ',
105105
"app": ', class_aa, ', "max": { "$gt": 0 },
106106
"verb": { "$in": ["answered", "submitted"] } }')))
107107
return(NULL)
108108

109109
part1 <- mdb_learnr$aggregate(paste0('[ {
110110
"$match": {
111+
"type" : "learnr",
111112
"login": ', class_logins, ',
112113
"app": ', class_aa, ',
113114
"max": { "$gt": 0 },
@@ -139,6 +140,7 @@ learnr_class_prog <- function(class_logins, class_aa,
139140
# raw_score_avg
140141
part2 <- mdb_learnr$aggregate(paste0('[ {
141142
"$match": {
143+
"type" : "learnr",
142144
"login": ', class_logins, ',
143145
"app": ', class_aa, ',
144146
"max": { "$gt": 0 },
@@ -177,17 +179,18 @@ learnr_class_prog <- function(class_logins, class_aa,
177179
# Get learnrs progression for one student
178180
learnr_user_prog <- function(user_login, class_aa,
179181
url = getOption("learnitr.lrs_url")) {
180-
mdb_learnr <- try(mongolite::mongo("learnr", url = url), silent = TRUE)
182+
mdb_learnr <- try(mongolite::mongo("events", url = url), silent = TRUE)
181183
if (inherits(mdb_learnr, "try-error"))
182184
stop("Error: impossible to connect to the learnr database")
183185

184-
if (!mdb_learnr$count(paste0('{ "login": "', user_login, '",
186+
if (!mdb_learnr$count(paste0('{ "type" : "learnr", "login": "', user_login, '",
185187
"app": ', class_aa, ', "max": { "$gt": 0 },
186188
"verb": { "$in": ["answered", "submitted"] } }')))
187189
return(NULL)
188190

189191
mdb_learnr$aggregate(paste0('[ {
190192
"$match": {
193+
"type" : "learnr",
191194
"login": "', user_login, '",
192195
"app": ', class_aa, ',
193196
"max": { "$gt": 0 },
@@ -218,16 +221,17 @@ learnr_user_prog <- function(user_login, class_aa,
218221
# Get H5P data for a whole class
219222
h5p_class_prog <- function(class_logins, class_aa,
220223
url = getOption("learnitr.lrs_url")) {
221-
mdb_h5p <- try(mongolite::mongo("h5p", url = url), silent = TRUE)
224+
mdb_h5p <- try(mongolite::mongo("events", url = url), silent = TRUE)
222225
if (inherits(mdb_h5p, "try-error"))
223226
stop("Error: impossible to connect to the H5P database")
224227

225-
if (!mdb_h5p$count(paste0('{ "login": ', class_logins, ',
228+
if (!mdb_h5p$count(paste0('{ "type" : "h5p", "login": ', class_logins, ',
226229
"app": ', class_aa, ' }')))
227230
return(NULL)
228231

229232
part1 <- mdb_h5p$aggregate(paste0('[ {
230233
"$match": {
234+
"type" : "h5p",
231235
"login": ', class_logins, ',
232236
"app": ', class_aa, '
233237
}
@@ -253,6 +257,7 @@ h5p_class_prog <- function(class_logins, class_aa,
253257

254258
part2 <- mdb_h5p$aggregate(paste0('[ {
255259
"$match": {
260+
"type" : "h5p",
256261
"login": ', class_logins, ',
257262
"app": ', class_aa, ',
258263
"verb": "answered",
@@ -306,16 +311,17 @@ h5p_class_prog <- function(class_logins, class_aa,
306311
# Get progression in H5P exercises for one student
307312
h5p_user_prog <- function(user_login, class_aa,
308313
url = getOption("learnitr.lrs_url")) {
309-
mdb_h5p <- try(mongolite::mongo("h5p", url = url), silent = TRUE)
314+
mdb_h5p <- try(mongolite::mongo("events", url = url), silent = TRUE)
310315
if (inherits(mdb_h5p, "try-error"))
311316
stop("Error: impossible to connect to the H5P database")
312317

313-
if (!mdb_h5p$count(paste0('{ "login": "', user_login, '",
318+
if (!mdb_h5p$count(paste0('{ "type" : "h5p", "login": "', user_login, '",
314319
"app": ', class_aa, ' }')))
315320
return(NULL)
316321

317322
part1 <- mdb_h5p$aggregate(paste0('[ {
318323
"$match": {
324+
"type" : "h5p",
319325
"login": "', user_login, '",
320326
"app": ', class_aa, '
321327
}
@@ -334,7 +340,7 @@ h5p_user_prog <- function(user_login, class_aa,
334340
}
335341
} ]'))
336342

337-
if (!mdb_h5p$count(paste0('{ "login": "', user_login, '",
343+
if (!mdb_h5p$count(paste0('{ "type" : "h5p", "login": "', user_login, '",
338344
"app": ', class_aa, ', "verb": "answered", "max": { "$gt": 0 } }'))) {
339345
# Fake data because the student did not answered to anything yet
340346
n <- nrow(part1)
@@ -343,6 +349,7 @@ h5p_user_prog <- function(user_login, class_aa,
343349
} else {
344350
part2 <- mdb_h5p$aggregate(paste0('[ {
345351
"$match": {
352+
"type" : "h5p",
346353
"login": "', user_login, '",
347354
"app": ', class_aa, ',
348355
"verb": "answered",
@@ -389,7 +396,7 @@ h5p_user_prog <- function(user_login, class_aa,
389396
# Get Shiny apps data for a whole class
390397
shiny_class_prog <- function(class_logins, class_aa,
391398
url = getOption("learnitr.lrs_url")) {
392-
mdb_shiny <- try(mongolite::mongo("shiny", url = url), silent = TRUE)
399+
mdb_shiny <- try(mongolite::mongo("events", url = url), silent = TRUE)
393400
if (inherits(mdb_shiny, "try-error"))
394401
stop("Error: impossible to connect to the shiny database")
395402

@@ -398,12 +405,13 @@ shiny_class_prog <- function(class_logins, class_aa,
398405
# "$cond": [ { "$in": ["$verb", ["evaluated"] ] }, "$max", null ]
399406
#} },
400407

401-
if (!mdb_shiny$count(paste0('{ "login": ', class_logins, ',
408+
if (!mdb_shiny$count(paste0('{ "type" : "shiny", "login": ', class_logins, ',
402409
"app": ', class_aa, ' }')))
403410
return(NULL)
404411

405412
mdb_shiny$aggregate(paste0('[ {
406413
"$match": {
414+
"type" : "shiny",
407415
"login": ', class_logins, ',
408416
"app": ', class_aa, '
409417
}
@@ -432,16 +440,17 @@ shiny_class_prog <- function(class_logins, class_aa,
432440
# Get the progression in Shiny apps for one student
433441
shiny_user_prog <- function(user_login, class_aa,
434442
url = getOption("learnitr.lrs_url")) {
435-
mdb_shiny <- try(mongolite::mongo("shiny", url = url), silent = TRUE)
443+
mdb_shiny <- try(mongolite::mongo("events", url = url), silent = TRUE)
436444
if (inherits(mdb_shiny, "try-error"))
437445
stop("Error: impossible to connect to the shiny database")
438446

439-
if (!mdb_shiny$count(paste0('{ "login": "', user_login, '",
447+
if (!mdb_shiny$count(paste0('{ "type" : "shiny", "login": "', user_login, '",
440448
"app": ', class_aa, ' }')))
441449
return(NULL)
442450

443451
mdb_shiny$aggregate(paste0('[ {
444452
"$match": {
453+
"type" : "shiny",
445454
"login": "', user_login, '",
446455
"app": ', class_aa, '
447456
}

R/report_progress.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ report_progress <- function(email, second.course = FALSE, course = NULL,
3939

4040
# In user iemail, I have a lowercase version, but I need -
4141
# email instead
42-
user$iemail <- user$email
42+
#No! user$iemail <- user$email
4343
encode_param <- function(param, data = user) {
4444
value <- URLencode(as.character(data[[param]]), reserved = TRUE)
4545
paste0(param, "=", value)
@@ -82,6 +82,7 @@ report_progress <- function(email, second.course = FALSE, course = NULL,
8282
browseURL(url)
8383
invisible(url)
8484
}
85+
8586
#' @export
8687
#' @rdname report_progress
8788
run_progress_report <- function(port = 3260) {

R/url.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
#' Check student profile to identify it from URL's parameters
44
#'
5+
#' @description
6+
#' Check if a GitHub user profile exists by checking its homepage.
7+
#'
58
#' @param profile Profile data gathered from the LRS
69
#' @param url_profile Profile data gathered from the URL
710
#'
@@ -47,7 +50,8 @@ check_profile <- function(profile, url_profile) {
4750

4851
#' URL parameters used to identify a student
4952
#'
50-
#' # Get the list of required parameters to identify a student from the URL.
53+
#' @description
54+
#' Get the list of required parameters to identify a student from the URL.
5155
#'
5256
#' @return A character vector with the list of parameters
5357
#' @details

inst/WORDLIST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ iref
1414
iurl
1515
LearnIt
1616
learnitdown
17+
learnitprogress
1718
Learnr
1819
learnr
1920
learnrs

inst/shiny/progress-report/app.R

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Individual student's progress report for BioDataScience-Course at UMONS
2-
# Version 3.0.0, Copyright (c), 2021-2024, Philippe Grosjean & Guyliann Engels
2+
# Version 3.1.0, Copyright (c), 2021-2024, Philippe Grosjean & Guyliann Engels
33
#
44
# TODO:
55
# - Rework to allow using outside of SDD context
@@ -15,14 +15,15 @@
1515
#date_query_def <- '"date": { "$gt": "2022-09-18 00:00:00.000000" }, '
1616

1717
library(shiny)
18+
suppressMessages(library(DT))
1819
#library(shinyjs)
1920
library(shinybusy)
2021
library(shinythemes)
2122
#library(shinyFeedback)
2223
library(RCurl)
2324
library(mongolite)
2425
#library(PKI)
25-
library(dplyr)
26+
suppressMessages(library(dplyr))
2627
library(ggplot2)
2728
library(cowplot)
2829
library(fs)
@@ -37,13 +38,9 @@ options(learnitr.lrs_url = getOption("learnitr.lrs_url",
3738
default = Sys.getenv("LEARNITR_LRS_URL",
3839
unset = "mongodb://127.0.0.1/sdd")))
3940

40-
mdb_h5p <- mongolite::mongo('h5p', url = getOption("learnitr.lrs_url"))
41+
# Test connection to the database
42+
mdb_h5p <- mongolite::mongo('events', url = getOption("learnitr.lrs_url"))
4143
mdb_h5p$disconnect()
42-
mdb_learnr <- mongolite::mongo('learnr', url = getOption("learnitr.lrs_url"))
43-
mdb_learnr$disconnect()
44-
mdb_shiny <- mongolite::mongo('shiny', url = getOption("learnitr.lrs_url"))
45-
mdb_shiny$disconnect()
46-
4744

4845
# The Shiny app -----------------------------------------------------------
4946

@@ -87,7 +84,7 @@ ui <- fluidPage(theme = shinytheme("lumen"),
8784
h4("Grilles de correction des projets GitHub"),
8885
htmlOutput("gridMessage"), # Message specific for the correction grids
8986
selectInput("gridSelect", " ", c()),
90-
dataTableOutput("gridTable"),
87+
DTOutput("gridTable"),
9188

9289
tags$a("Page d'aide",
9390
href = "https://wp.sciviews.org/progress-report")
@@ -165,7 +162,8 @@ server <- function(input, output, session) {
165162

166163
} else {# Our app will be in state #3, create the progress report now
167164
user$login <- user_profile$login
168-
user$email <- user_profile$email
165+
#user$email <- user_profile$email
166+
user$email <- user_data['iemail']
169167

170168
# Get data for the learnrs and the Github activity
171169
if (is.null(user$course)) {
@@ -426,7 +424,7 @@ server <- function(input, output, session) {
426424
} else ""
427425
})
428426

429-
output$gridTable <- renderDataTable({
427+
output$gridTable <- renderDT({
430428
grid <- input$gridSelect
431429
if (!is.null(grid) && !is.na(grid) && grid != "") {
432430
tab <- try(read.csv(grid))

0 commit comments

Comments
 (0)