Skip to content

Commit 10f652c

Browse files
Assess API loading with sample data
1 parent 1a0e827 commit 10f652c

File tree

3 files changed

+101
-1
lines changed

3 files changed

+101
-1
lines changed

sandbox/ai_insights_server.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import sys
22
from pathlib import Path
33
sys.path.insert(0, str(Path(__file__).parent.parent))
4-
4+
import json
55
from http.server import BaseHTTPRequestHandler, HTTPServer
66
from uuid import uuid4
77
from urllib.parse import urlparse, parse_qs
8+
89
from jinja2 import Template
910

1011
from learnosity_sdk.request import Init
@@ -22,6 +23,12 @@
2223
"domain": host,
2324
}
2425

26+
assess_security = {
27+
"consumer_key": config.consumer_key,
28+
"domain": host,
29+
"user_id": "assessment_taker"
30+
}
31+
2532
def build_report_request(user_id: str, session_id: str):
2633
return {
2734
"reports": [
@@ -52,6 +59,10 @@ def build_report_request(user_id: str, session_id: str):
5259
# Build reports init per request using query parameters
5360
generated_request_Items = initItems.generate()
5461

62+
with open('sandbox/json/activity.json', 'r', encoding='utf-8') as f:
63+
assess_request = json.loads(f.read())
64+
initAssess = Init("assess", assess_security, config.consumer_secret, request=assess_request)
65+
generated_request_Assess = initAssess.generate()
5566

5667
class Server(BaseHTTPRequestHandler):
5768
def _ok(self, body: str):
@@ -67,6 +78,8 @@ def do_GET(self):
6778
user_id = (qs.get("user_id") or ["demo-user"]).pop(0)
6879
session_id = (qs.get("session_id") or ["demo-session"]).pop(0)
6980

81+
security["user_id"] = user_id
82+
7083
initReports = Init(
7184
"reports",
7285
security,
@@ -84,6 +97,8 @@ def do_GET(self):
8497
user_id = (qs.get("user_id") or ["demo-user"]).pop(0)
8598
session_id = (qs.get("session_id") or ["demo-session"]).pop(0)
8699

100+
security["user_id"] = user_id
101+
87102
initReports = Init(
88103
"reports",
89104
security,
@@ -106,6 +121,12 @@ def do_GET(self):
106121
self._ok(tpl.render(generated_request=generated_request_Items))
107122
return
108123

124+
if parsed.path == "/assess":
125+
with open('sandbox/views/assess.html', 'r', encoding='utf-8') as f:
126+
tpl = Template(f.read())
127+
self._ok(tpl.render(generated_request=generated_request_Assess))
128+
return
129+
109130
# Index with simple form submitting to /reports
110131
with open('sandbox/views/index.html', 'r', encoding='utf-8') as f:
111132
tpl = Template(f.read())

sandbox/json/activity.json

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"items": [
3+
{
4+
"content": "<span class='learnosity-response question-demoscience1234'></span>",
5+
"response_ids": ["demoscience1234"],
6+
"workflow": "",
7+
"reference": "question-demoscience1"
8+
},
9+
{
10+
"content": "<span class='learnosity-response question-demoscience5678'></span>",
11+
"response_ids": ["demoscience5678"],
12+
"workflow": "",
13+
"reference": "question-demoscience2"
14+
}
15+
],
16+
"questionsApiActivity": {
17+
"consumer_key": "yis0TYCu7U9V4o7M",
18+
"timestamp": "INSERT_CURRENT_TIMESTAMP_HERE",
19+
"signature": "INSERT_GENERATED SIGNATURE HERE",
20+
"user_id": "aeee19fb-4e7b-435c-92f9-d93a1099988b",
21+
"type": "submit_practice",
22+
"state": "initial",
23+
"id": "assessdemo",
24+
"name": "Assess API - Demo",
25+
"questions": [
26+
{
27+
"response_id": "demoscience1234",
28+
"type": "sortlist",
29+
"description": "In this question, the learner needs to sort the events, chronologically earliest to latest.",
30+
"list": [
31+
"Russian Revolution",
32+
"Discovery of the Americas",
33+
"Storming of the Bastille",
34+
"Battle of Plataea",
35+
"Founding of Rome",
36+
"First Crusade"
37+
],
38+
"instant_feedback": true,
39+
"feedback_attempts": 2,
40+
"validation": {
41+
"valid_response": [4, 3, 5, 1, 2, 0],
42+
"valid_score": 1,
43+
"partial_scoring": true,
44+
"penalty_score": -1
45+
}
46+
},
47+
{
48+
"response_id": "demoscience5678",
49+
"type": "highlight",
50+
"description": "The learner needs to mark one of the flower's anthers in the image.",
51+
"img_src": "http://www.learnosity.com/static/img/flower.jpg",
52+
"line_color": "rgb(255, 20, 0)",
53+
"line_width": "4"
54+
}
55+
]
56+
}
57+
}

sandbox/views/assess.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!doctype html>
2+
<html>
3+
<body>
4+
<h1>Assess Page</h1>
5+
<div id="learnosity_assess"></div>
6+
<script src="https://assess.learnosity.com/?developer"></script>
7+
<script>
8+
var assessApp = LearnosityAssess.init({{ generated_request }}, "#learnosity_assess", {
9+
readyListener: function () {
10+
console.log('Assess API init COMPLETE --------------');
11+
12+
if (typeof window._readyListener === 'function') {
13+
window._readyListener();
14+
}
15+
},
16+
errorListener: function () {
17+
console.log('Assess API init FAILED --------------');
18+
}
19+
});
20+
</script>
21+
</body>
22+
</html>

0 commit comments

Comments
 (0)