Skip to content

Commit 3a1a818

Browse files
committed
factored out Codeopticon code and more minor cleanups
1 parent 0927a13 commit 3a1a818

12 files changed

Lines changed: 233 additions & 153 deletions

‎v3/codeopticon/README.txt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ The ideas behind Codeopticon are described in this research paper:
22

33
http://pgbovine.net/publications/Codeopticon-one-to-many-tutoring-interface_UIST-2015.pdf
44

5-
Prototype started in Jan 2015
5+
Prototype started being built in Jan 2015, ported over to OPT GitHub
6+
repo on 2016-05-28
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/* customized by Philip Guo for using with codeopticon-learner.js
2+
(learner chat box) */
3+
4+
/* style sheets */
5+
.ui-chatbox {
6+
position: fixed;
7+
bottom:0;
8+
padding: 2px;
9+
background: #CCCCCC;
10+
font-size: 10pt;
11+
}
12+
13+
.ui-chatbox-titlebar {
14+
padding: 3px;
15+
height: 20px;
16+
cursor: pointer;
17+
}
18+
19+
.ui-chatbox-content {
20+
padding: 0px;
21+
margin: 0px;
22+
border: 0px;
23+
}
24+
25+
.ui-chatbox-log {
26+
padding: 3px;
27+
height: 250px;
28+
overflow-y: auto;
29+
overflow-x: hidden;
30+
background: #FFFFFF !important;
31+
}
32+
33+
.ui-chatbox-input {
34+
padding: 3px;
35+
border-top: 1px solid grey;
36+
overflow: hidden;
37+
}
38+
39+
.ui-chatbox-input-box {
40+
margin: 5px;
41+
border: 2px solid lightgrey;/* #6699FF */
42+
padding: 2px;
43+
height: 50px;
44+
background: #FFFFFF !important;
45+
}
46+
47+
.ui-chatbox-icon {
48+
float: right;
49+
}
50+
51+
.ui-chatbox-input-focus {
52+
border-color: #6699FF;
53+
}
54+
55+
.ui-chatbox-msg {
56+
margin-top: 10px;
57+
float: left;
58+
clear: both;
59+
/* Source: http://snipplr.com/view/10979/css-cross-browser-word-wrap */
60+
white-space: pre-wrap; /* CSS3 */
61+
white-space: -moz-pre-wrap; /* Firefox */
62+
white-space: -pre-wrap; /* Opera <7 */
63+
white-space: -o-pre-wrap; /* Opera 7 */
64+
word-wrap: break-word; /* IE */
65+
}

v3/codeopticon/css/jquery.ui.chatbox.CUSTOM.css renamed to v3/codeopticon/css/jquery.ui.chatbox-OBSERVER.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/* customized by Philip Guo */
1+
/* customized by Philip Guo for using with observer.js
2+
(observer's chat box, which differs from the learner's chatbox) */
23

34
/* style sheets */
45
.ui-chatbox {
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
// Codeopticon learner interface. Include on a page AFTER AFTER AFTER
2+
// opt-frontend-common.js and opt-frontend.js
3+
//
4+
// assumes that an empty #chat_div div exists on the webpage page,
5+
// preferably on the BOTTOM.
6+
// also requires jquery.ui.chatbox-LEARNER.js and jquery.ui.chatbox-LEARNER.css
7+
8+
var codeopticonSocketIO = undefined; // socket.io instance
9+
var codeopticonSession = undefined;
10+
//var codeopticonSession = 'CODEOPTICON_TESTING'; // to turn all monitoring on
11+
12+
var reconnectAttempts = 0;
13+
var logEventQueue = []; // TODO: make sure this doesn't grow too large if socketio isn't enabled
14+
var chatBox = undefined;
15+
16+
17+
function createChatBox() {
18+
assert(!chatBox);
19+
chatBox = $("#chat_div").chatbox({id: "Me",
20+
user: {key : "value"},
21+
title: "Live Chat With Tutor",
22+
width: 250,
23+
offset: 2, // offset from right edge
24+
messageSent: chatMsgSent,
25+
boxClosed: chatBoxClosed,
26+
chatboxToggled: chatBoxToggled,
27+
});
28+
}
29+
30+
function chatMsgSent(id, user, msg) {
31+
$("#chat_div").chatbox("option", "boxManager").addMsg(id, msg);
32+
logEventCodeopticon({type: 'opt-client-chat',
33+
text: msg,
34+
sid: codeopticonSocketIO ? codeopticonSocketIO.id : undefined
35+
});
36+
}
37+
38+
// only called when the user hits the X button to explicitly close the chat box
39+
function chatBoxClosed(id) {
40+
logEventCodeopticon({type: 'opt-client-chat',
41+
text: '[closed chat box]',
42+
sid: codeopticonSocketIO ? codeopticonSocketIO.id : undefined
43+
});
44+
}
45+
46+
// called when the user toggles the chat box open or close
47+
function chatBoxToggled(visible) {
48+
var msg = '[minimized chat box]';
49+
if (visible) {
50+
msg = '[maximized chat box]';
51+
}
52+
logEventCodeopticon({type: 'opt-client-chat',
53+
text: msg,
54+
sid: codeopticonSocketIO ? codeopticonSocketIO.id : undefined
55+
});
56+
}
57+
58+
function initCodeopticon() {
59+
// only initialize if you have a valid session ID
60+
if (!codeopticonSession) {
61+
return;
62+
}
63+
64+
// hide header elements only if we're not doing CODEOPTICON_TESTING
65+
if (codeopticonSession !== 'CODEOPTICON_TESTING') {
66+
$("#ssDiv,#surveyHeader,#sharedSessionDisplayDiv").hide();
67+
$("#togetherjsStatus").css("font-size", "8pt");
68+
$("#togetherjsStatus").html("Codeopticon session " + codeopticonSession);
69+
}
70+
71+
// connect on-demand in logEventCodeopticon(), not here
72+
codeopticonSocketIO = io('http://104.237.139.253:5000/userlog'); // PRODUCTION_PORT
73+
//codeopticonSocketIO = io('http://104.237.139.253:5001/userlog'); // DEBUG_PORT
74+
//codeopticonSocketIO = io('http://localhost:5000/userlog'); // localhost debugging
75+
76+
if (codeopticonSocketIO) {
77+
codeopticonSocketIO.on('connect', function() {
78+
//console.log('CONNECTED and emitting', logEventQueue.length, 'events');
79+
80+
if (logEventQueue.length > 0) {
81+
// the reconnectAttempts field that denotes how many times you've
82+
// attempted to reconnect (which is also how many times you've
83+
// been kicked off by the logging server for, say, being idle).
84+
// add this as an extra field on the FIRST event
85+
if (reconnectAttempts > 0) {
86+
logEventQueue[0].reconnectAttempts = reconnectAttempts;
87+
}
88+
89+
while (logEventQueue.length > 0) {
90+
codeopticonSocketIO.emit('opt-client-event', logEventQueue.pop());
91+
}
92+
}
93+
assert(logEventQueue.length === 0);
94+
95+
reconnectAttempts++;
96+
});
97+
98+
codeopticonSocketIO.on('opt-codeopticon-observer-chat', function(msg) {
99+
if (!chatBox) {
100+
createChatBox();
101+
} else {
102+
$("#chat_div").chatbox("option", "hidden", false);
103+
$("#chat_div").chatbox("showContent");
104+
}
105+
106+
$("#chat_div").chatbox("option", "boxManager").addMsg('Tutor', msg.text);
107+
});
108+
}
109+
}
110+
111+
// using socket.io:
112+
function logEventCodeopticon(obj) {
113+
//console.log(obj);
114+
if (codeopticonSocketIO) {
115+
assert(codeopticonSession);
116+
obj.codeopticonSession = codeopticonSession;
117+
118+
obj.user_uuid = supports_html5_storage() ? localStorage.getItem('opt_uuid') : undefined,
119+
obj.session_uuid = sessionUUID;
120+
121+
// this probably won't match the server time due to time zones, etc.
122+
obj.clientTime = new Date().getTime();
123+
124+
if (codeopticonSocketIO.connected) {
125+
codeopticonSocketIO.emit('opt-client-event', obj);
126+
//console.log('emitted opt-client-event:', obj);
127+
} else {
128+
// TODO: be careful about this getting HUGE if codeopticonSocketIO
129+
// never connects properly ...
130+
logEventQueue.push(obj); // queue this up to be logged when the client
131+
// finishes successfully connecting to the server
132+
133+
// we're not yet connected, or we've been disconnected by the
134+
// server, so try to connect/reconnect first before emitting the event
135+
codeopticonSocketIO.connect(); // will trigger the .on('connect', ...) handler
136+
}
137+
}
138+
}

v3/js/jquery.ui.chatbox.js renamed to v3/codeopticon/js/jquery.ui.chatbox-LEARNER.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/* customized by Philip Guo */
1+
/* customized by Philip Guo for using with codeopticon-learner.js
2+
(learner chat box) */
23

34
/*
45
* Copyright 2010, Wen Pu (dexterpu at gmail dot com)

v3/codeopticon/js/jquery.ui.chatbox.CUSTOM.js renamed to v3/codeopticon/js/jquery.ui.chatbox-OBSERVER.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/* customized by Philip Guo */
1+
/* customized by Philip Guo for using with observer.js
2+
(observer's chat box, which differs from the learner's chatbox) */
23

34
/*
45
* Copyright 2010, Wen Pu (dexterpu at gmail dot com)

‎v3/codeopticon/js/observer.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ var warningBorderColor = 'green';
6565
var lockedBorderColor = '#E66767'; // make it reddish
6666

6767

68+
// TODO: can get rid of ... only for user study for backup
6869
function logCoEvent(evt) {
6970
evt.dt = new Date().getTime();
7071
allCoEvents.push(evt);

‎v3/codeopticon/observer.html‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
<script src="../js/jquery.ba-dotimeout.min.js"></script>
1818

1919
<!-- chat box widget -->
20-
<link type="text/css" href="css/jquery.ui.chatbox.CUSTOM.css" rel="stylesheet" />
21-
<script type="text/javascript" src="js/jquery.ui.chatbox.CUSTOM.js"></script>
20+
<link type="text/css" href="css/jquery.ui.chatbox-OBSERVER.css" rel="stylesheet" />
21+
<script type="text/javascript" src="js/jquery.ui.chatbox-OBSERVER.js"></script>
2222

2323
<script type="text/javascript" src="js/usermon-class.js"></script>
2424
<script type="text/javascript" src="js/observer.js"></script>

‎v3/js/opt-frontend-common.js‎

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,6 @@ var useCodeMirror = false; // true -> use CodeMirror, false -> use Ace
124124
var prevExecutionExceptionObjLst = [];
125125

126126

127-
// OPTIONAL for Codeopticon - not all frontends use these:
128-
var codeopticonSocketIO = undefined; // socket.io instance
129-
var codeopticonSession = undefined;
130-
//var codeopticonSession = 'CODEOPTICON_TESTING'; // to turn all monitoring on
131-
132127
// From http://stackoverflow.com/a/8809472
133128
function generateUUID(){
134129
var d = new Date().getTime();
@@ -191,6 +186,7 @@ function initAceEditor(height) {
191186
pyInputAceEditor.setHighlightActiveLine(false);
192187
pyInputAceEditor.setShowPrintMargin(false);
193188
pyInputAceEditor.setBehavioursEnabled(false);
189+
pyInputAceEditor.$blockScrolling = Infinity; // kludgy to shut up weird warnings
194190

195191
// auto-grow height as fit
196192
pyInputAceEditor.setOptions({minLines: 18, maxLines: 1000});
@@ -1081,7 +1077,7 @@ function parseQueryString() {
10811077
}
10821078

10831079
if (queryStrOptions.codeopticonSession) {
1084-
codeopticonSession = queryStrOptions.codeopticonSession; // GLOBAL!
1080+
codeopticonSession = queryStrOptions.codeopticonSession; // GLOBAL defined in codeopticon-learner.js
10851081
}
10861082

10871083
if (queryStrOptions.testCasesLst) {
@@ -2187,32 +2183,6 @@ display a brief "Thanks!" note]
21872183
*/
21882184
}
21892185

2190-
2191-
// using socket.io:
2192-
function logEventCodeopticon(obj) {
2193-
//console.log(obj);
2194-
if (codeopticonSocketIO) {
2195-
assert(codeopticonSession);
2196-
obj.codeopticonSession = codeopticonSession;
2197-
2198-
obj.user_uuid = supports_html5_storage() ? localStorage.getItem('opt_uuid') : undefined,
2199-
obj.session_uuid = sessionUUID;
2200-
2201-
// this probably won't match the server time due to time zones, etc.
2202-
obj.clientTime = new Date().getTime();
2203-
2204-
if (codeopticonSocketIO.connected) {
2205-
codeopticonSocketIO.emit('opt-client-event', obj);
2206-
//console.log('emitted opt-client-event:', obj);
2207-
} else {
2208-
// TODO: be careful about this getting HUGE if codeopticonSocketIO
2209-
// never connects properly ...
2210-
logEventQueue.push(obj); // queue this up to be logged when the client
2211-
// finishes successfully connecting to the server
2212-
2213-
// we're not yet connected, or we've been disconnected by the
2214-
// server, so try to connect/reconnect first before emitting the event
2215-
codeopticonSocketIO.connect(); // will trigger the .on('connect', ...) handler
2216-
}
2217-
}
2218-
}
2186+
// empty stub so that our code doesn't crash.
2187+
// override this with a version in codeopticon-learner.js if needed
2188+
function logEventCodeopticon(obj) {}

0 commit comments

Comments
 (0)