Skip to content

Commit

Permalink
Resolves #6
Browse files Browse the repository at this point in the history
  • Loading branch information
rpc5102 committed Jul 2, 2020
1 parent eb4d389 commit c746dd5
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .lintr
Original file line number Diff line number Diff line change
@@ -1 +1 @@
linters: with_defaults(line_length_linter(120), camel_case_linter = NULL, snake_case_linter = NULL, trailing_blank_lines_linter = NULL)
linters: with_defaults(line_length_linter(120), camel_case_linter = NULL, snake_case_linter = NULL, trailing_blank_lines_linter = NULL)
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: rlocker
Type: Package
Title: Learning Locker for Shiny
Version: 0.2.4
Date: 2020-05-20
Version: 0.2.4.1
Date: 2020-05-02
Authors@R: c(person("Robert", "Carey", email = "rpc5102@psu.edu",
role = c("aut", "cre")))
Maintainer: Robert Carey <rpc5102@psu.edu>
Expand Down
2 changes: 1 addition & 1 deletion R/request.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ NULL
store <- function(session, statement = NULL, warn = FALSE, ...) {
# Pass the statement to the js handler
session$sendCustomMessage("rlocker-store", statement)

print(statement)
# HTTP Status Code
status_code <- ifelse(!is.null(session$input$storageStatus), session$input$storageStatus, 502)

Expand Down
14 changes: 10 additions & 4 deletions README.Rmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: "rlocker"
title: "rLocker"
output:
md_document:
variant: gfm
Expand All @@ -16,7 +16,7 @@ knitr::opts_chunk$set(
)
```

# rlocker <img src="https://github.com/rpc5102/rlocker/blob/master/rlocker.png?raw=true" align="right" height=140>
# rLocker <img src="https://github.com/rpc5102/rlocker/blob/master/rlocker.png?raw=true" align="right" height=140>

<!-- badges: start -->
[![lifecycle](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
Expand All @@ -26,6 +26,12 @@ knitr::opts_chunk$set(

Learning Locker xAPI support for Shiny Applications.

### About xAPI

> xAPI \[Experience API\] is 100% free, open source, lightweight, and adaptable. It can be used to augment almost any performance assessment situation. It is being used in an expanding array of learning systems, from LMSs and simulator systems to museums and emergency medical services. – [adlnet.gov](https://adlnet.gov/projects/xapi/)
See also: [What is the Experience API?](https://xapi.com/overview/)

### Assumptions

1. This package assumes that you have a [Learning Locker](https://www.ht2labs.com/learning-locker-community/overview/) instance set up and that it's reachable by your application.
Expand All @@ -34,15 +40,15 @@ Learning Locker xAPI support for Shiny Applications.

### Installation

You can install the released version of rlocker from [GitHub](https://github.com/) with:
You can install the released version of rLocker from [GitHub](https://github.com/) with:

```{r}
devtools::install_github("rpc5102/rlocker")
```

### Examples

See the [examples](./inst/examples/) folder for a demo application.
See the [examples](./inst/examples/) folder for demo code or visit [psu-eberly.shinyapps.io/rlocker](https://psu-eberly.shinyapps.io/rlocker) to see it in action.

### Storage Mechanism

Expand Down
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- README.md is generated from README.Rmd. Please edit that file -->

# rlocker <img src="https://github.com/rpc5102/rlocker/blob/master/rlocker.png?raw=true" align="right" height=140>
# rLocker <img src="https://github.com/rpc5102/rlocker/blob/master/rlocker.png?raw=true" align="right" height=140>

<!-- badges: start -->

Expand All @@ -15,7 +15,11 @@ Learning Locker xAPI support for Shiny Applications.

### About xAPI

> xAPI \[Experience API\] is 100% free, open source, lightweight, and adaptable. It can be used to augment almost any performance assessment situation. It is being used in an expanding array of learning systems, from LMSs and simulator systems to museums and emergency medical services. – [adlnet.gov](https://adlnet.gov/projects/xapi/)
> xAPI \[Experience API\] is 100% free, open source, lightweight, and
> adaptable. It can be used to augment almost any performance assessment
> situation. It is being used in an expanding array of learning systems,
> from LMSs and simulator systems to museums and emergency medical
> services. – [adlnet.gov](https://adlnet.gov/projects/xapi/)
See also: [What is the Experience API?](https://xapi.com/overview/)

Expand All @@ -36,7 +40,7 @@ See also: [What is the Experience API?](https://xapi.com/overview/)

### Installation

You can install the released version of rlocker from
You can install the released version of rLocker from
[GitHub](https://github.com/) with:

``` r
Expand All @@ -45,7 +49,9 @@ devtools::install_github("rpc5102/rlocker")

### Examples

See the [examples](./inst/examples/) folder for demo code or visit [psu-eberly.shinyapps.io/rlocker](https://psu-eberly.shinyapps.io/rlocker) to see it in action.
See the [examples](./inst/examples/) folder for demo code or visit
[psu-eberly.shinyapps.io/rlocker](https://psu-eberly.shinyapps.io/rlocker)
to see it in action.

### Storage Mechanism

Expand Down
15 changes: 2 additions & 13 deletions inst/www/js/dist/rlocker.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions inst/www/js/dist/rlocker.js.LICENSES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Fast UUID generator, RFC4122 version 4 compliant.
* @author Jeff Ward (jcward.com).
* @license MIT license
* @link https://jcward.com/UUID.js
**/

/**
* rlocker - An xAPI Statement Generator & Storage Mechanism
* @author Bob Carey (https://github.com/rpc5102).
* @license GPL-3.0+
**/
43 changes: 28 additions & 15 deletions inst/www/js/src/rlocker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* rlocker - An xAPI Statement Generator & Storage Mechanism
* @author Bob Carey (https://github.com/rpc5102).
* @license GPL-2.0+
* @license GPL-3.0+
**/

import { UUID } from './uuid.js';
Expand Down Expand Up @@ -39,7 +39,7 @@ export class Locker {
launched: null
},
this.agent = null,
this.activity = null
this.activity = null,

this.init();
}
Expand All @@ -50,26 +50,39 @@ export class Locker {
this.setSession();
this.setCurrentAgent("mailto:default@example.org");
this.setCurrentActivity(window.location.href, document.title);

this.experienced_xAPI();
}

setSession() {
// Set session id
let sid = "0000-0000-0000-0000";
try {
sid = ADL.XAPIWrapper.lrs.agent.name;
} catch(e) {
if(e instanceof ReferenceError) {
sid = UUID.generate();
}
}

// Try storing session id in sessionStorage
if (typeof Storage !== "undefined") {
let sid = sessionStorage.getItem("sid");

if (!sid) {
/* generate universally unique identifier */
sid = UUID.generate();

// Get stored session id
let ssid = sessionStorage.getItem("sid");

// Check if stored id matches the one we have
if (sid != ssid) {
sessionStorage.setItem("sid", sid);
this.session.launched = true;
} else {
this.session.launched = false;
}
this.session.id = sid;
} else {
this.session.id = "0000-0000-0000-0000";
// If we can't store the info assume each session is new
this.session.launched = true;
}
this.session.id = sid;
}

getSession() {
Expand Down Expand Up @@ -133,7 +146,7 @@ export class Locker {
return statement;
}

experienced_xAPI () {
experienced_xAPI() {
let verb = this.session.launched ? "launched" : "experienced";
this.store(this.createBasicStatement(verb));

Expand All @@ -149,7 +162,7 @@ export class Locker {
}

answered_xAPI(question, data, answered, success) {
let attempt = data["attempt"] ? data["attempt"] : 1;
let attempt = data.attempt ? data.attempt : 1;
let location = this.activity.id + "#" + question;
let title = this.activity.definition.name['en-US'] + " :: " + question;
let agent = this.getCurrentAgent();
Expand All @@ -162,10 +175,10 @@ export class Locker {

statement.object.definition.type =
"http://adlnet.gov/expapi/activities/interaction";
statement.object.definition.interactionType = data["interactionType"];
statement.object.definition.interactionType = data.interactionType;
statement.object.definition.correctResponsesPattern = [
JSON.stringify(data["validateOn"]),
data["answers"].toString()
JSON.stringify(data.validateOn),
data.answers.toString()
];

statement.result = {
Expand Down
27 changes: 27 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "rlocker",
"version": "0.1.5",
"description": "Learning Locker for R Shiny",
"repository": {
"type": "git",
"url": "git@github.com:rpc5102/rlocker.git",
"private": false
},
"main": "inst/www/rlocker.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"compile-src": "webpack --mode production",
"build": "npm run compile-src"
},
"author": "ROBERT PATRICK CAREY III",
"license": "GPL-3.0+",
"devDependencies": {
"@babel/core": "^7.10.4",
"@babel/preset-env": "^7.10.4",
"babel-loader": "^8.1.0",
"terser-webpack-plugin": "^3.0.6",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.12"
},
"dependencies": {}
}

0 comments on commit c746dd5

Please sign in to comment.