Skip to content

Instantly share code, notes, and snippets.

@fluidglassml
Forked from scottgwald/glass.html
Created May 19, 2014 18:23
Show Gist options
  • Save fluidglassml/8e2e5b6688aafdbaf3d6 to your computer and use it in GitHub Desktop.
Save fluidglassml/8e2e5b6688aafdbaf3d6 to your computer and use it in GitHub Desktop.
[wearscript] kevin beta app
<html style="width:100%; height:100%; overflow:hidden">
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="http://www.parsecdn.com/js/parse-1.2.18.min.js"></script>
</head>
<body style="width:100%; height:100%; overflow:hidden; margin:0">
<canvas id="canvas" width="640" height="360" style="display:block"></canvas>
<script>
console.log('welcome!');
WS.say('Welcome! Please Wait to receive Context...');
var kimonoSet = [['frog','ribbit'],['snake','hiss'],['cat','meow'],['dog','bark'],['horse','neigh'],['lion','roar'],['mouse','squeak'],['wolf','howl']];
var kimonoTitle = 'Animal Sounds';
function kimonoCallback(data) {
if(data.lastrunstatus=="success"){
console.log('kimonocallback');
window.kimonoSet.length = 0;
for(var i=0;i<data.results.collection1.length;i++){
window.kimonoSet.push([data.results.collection1[i].question,data.results.collection1[i].answer]);
}
window.kimonoTitle=data.results.collection2[0].title;
console.log(JSON.stringify(window.kimonoTitle));
console.log(JSON.stringify(window.kimonoSet));
WS.say('Ready! New Context is: '+window.kimonoTitle);
} else {
getRandomWords();
}
}
function getRandomWords(){
console.log('getrandomwords');
var url = "http://www.kimonolabs.com/api/dwrmpm04?apikey=989877be85a3ca05477428c8b41d4fbe&callback=kimonoCallback&kimpath1=";
var num = Math.floor(Math.random()*1000000)+3000000;
console.log('kimono number: '+num);
url = url+num+"&kimpath2=";
$.ajax({
"url": url,
"crossDomain":true,
"dataType":"jsonp"
});
}
// Constants
var DBG = true;
var i = 0;
var secondLineText = "Second line";
var wakeTime;
var timeDeltaText = "";
var wakeInterval = 15*60*1000;
var wordInterval = 10*1000;
var timeNow = new Date().getTime();
var tillNextSet = Math.floor(wakeInterval / 1000);
var tillNextWord = Math.floor(wordInterval / 1000);
var deltasMaxLength = 10;
var timeDeltas = [];
var woken;
var timeDeltaTitleText = "Between Last Wakes:";
var batteryLevelText = "Battery level: ";
var showDashboard = true;
var cameraCB;
var showImageInterval = 10000;
var pauseFudgeFactor = 500;
var videoLength = 10;
var wordsDone = 0;
var wordsRight = 0;
var accuracy = 100.0;
var setSize = 4;
var counter = 0;
var setIndex = Math.floor((Math.random()*setSize));
var quizzing = false;
var currWord;
var currDef;
var idle = true;
var context;
var wordsToDisplay = new Array();
var glassID=WS.groupDevice();
var isBurst = false;
var sceneryMode = false;
var refreshIntervalId = '';
function server() {
WS.wake();
getRandomWords();
Parse.initialize("lMinQat7ZP9hRStvRtrifnBTsJoELfX5ksc5tJyT", "jHBA4ehcvlTGY83wAtx2xJ1nPly6PPCyudz3Z5mZ");
var GuessObject = Parse.Object.extend("GuessObject");
// if (!DBG) WS.serverConnect('0.0.0.0', null);
WS.log('Welcome to WearScript');
// WS.say('Welcome to WearScript');
WS.sound('SUCCESS');
WS.dataLog(true, false, 1);
WS.sensorOn("battery", 1, function (data) {
console.log("Got battery callback");
console.log(JSON.stringify(data));
batteryLevelText = "Battery Level: " + Math.round(data.values[0] * 100) + "%";
if (Math.round(data.values[0] * 100) <= 20) WS.say("Low battery.");
batteryLevelText += " @ " + new Date(parseInt(data.timestamp * 1000)).timeNow();
});
var toggle_burst = function(){
if(window.isBurst == true){
window.isBurst = false;
window.wakeInterval = 15*60*1000;
WS.say('Burst Mode is now Off');
} else {
window.isBurst = true;
window.wakeInterval = 1.5*60*1000;
WS.say('Burst Mode is now On');
}
runInterval();
}
var temp_func = function(){
// do nothing
}
var new_context = function(){
getRandomWords();
WS.say('Please wait');
}
var createDisplay = function(wordsDone,accuracy){
WS.activityDestroy();
setIndex = Math.floor((Math.random()*setSize));
var tree = new WS.Cards();
var roundedAcc = Math.round(accuracy * 100) / 100;
tree.add('Words Quizzed: '+wordsDone+'\n'+'Accuracy: '+roundedAcc+'%', 'Tap for a new word!',temp_func,temp_func,'Start Quiz',createQuiz,'New Context',new_context,'Toggle Burst Mode',toggle_burst);
WS.cardTree(tree);
WS.displayCardTree();
}
var test = function(wordsDone,accuracy){
var temp = accuracy;
if(quizzing){
var ansTree = new WS.Cards();
ansTree.add(currWord+'\n'+currDef,window.kimonoTitle);
WS.cardTree(ansTree);
WS.displayCardTree();
setTimeout(function() {
quizzing = false;
test(wordsDone,accuracy);
}, 4000);
return
}
if(counter>4){
// getRandomWords();
createDisplay(wordsDone,accuracy);
counter = 0;
window.idle = true;
}
else{
window.idle = false;
quizzing = true;
createQuiz();
}
}
var processWord = function(w, d){
word = w;
def = d;
var isCorrect=false;
// WS.say(word);
var incorrectPhrase= "incorrect. The correct definition is: " + def;
WS.speechRecognize(word,
function speech(data) {
console.log('WS.speechRecognize: ' + data);
if(data=='' || data===''){
console.log('SWIPE BACK FUNCTION CAUGHT!!!!!!!');
processWord(word,def);
return;}
if(def.toUpperCase().indexOf(data.toUpperCase())!=-1){
isCorrect=true;
WS.say('correct');
wordsRight+=1;}
else{
isCorrect=false;
WS.say('incorrect')}
wordsDone+=1;
accuracy=100*wordsRight/wordsDone;
counter+=1;
var guessObject = new GuessObject();
guessObject.save({user:window.glassID,
context:window.kimonoTitle,
word:word,
def:def,
guess:data,
word_correct:isCorrect}).then(
function(object){console.log('PARSE WORKED!!!!!!!!!');});
test(wordsDone,accuracy);});
}
var swipe_callback = function(){
// WS.say('Try Again!');
createQuiz();
}
var createQuiz = function(){
window.sceneryMode = false;
WS.displayCardTree();
quizzing = true;
var quiztree = new WS.Cards();
console.log(JSON.stringify(kimonoSet));
var currentSetSize=JSON.stringify(kimonoSet.length);
console.log('set size: '+currentSetSize);
var wordIndex = Math.floor((Math.random()*currentSetSize));
console.log('word index: '+wordIndex);
console.log(JSON.stringify(kimonoSet[wordIndex][0]));
console.log(JSON.stringify(kimonoSet[wordIndex][1]));
quiztree.add('', '', function(){processWord(kimonoSet[wordIndex][0],kimonoSet[wordIndex][1]);}, function(){processWord(kimonoSet[wordIndex][0],kimonoSet[wordIndex][1]);});
currWord = kimonoSet[wordIndex][0];
currDef = kimonoSet[wordIndex][1];
WS.cardTree(quiztree);
}
createDisplay(0,0);
var processScenery = function(wordsToDisplay,context,index){
WS.wake();
w = wordsToDisplay[0][0];
d = wordsToDisplay[0][1];
c = context;
displayScenery(w,d,c);
}
var displayScenery = function(w,d,c){
WS.wake();
var tree = new WS.Cards();
tree.add(w+'\n'+d,c,temp_func,temp_func,'Start Quiz',createQuiz,'New Context',new_context,'Toggle Burst Mode',toggle_burst);
WS.cardTree(tree);
WS.displayCardTree();
}
var newWord = function(){
if(window.sceneryMode){
WS.wake();
// display a new word.
processScenery(wordsToDisplay,context);
wordsToDisplay.splice(0, 1);
if(wordsToDisplay.length==0){
window.sceneryMode=false;
createDisplay(wordsDone,accuracy);
}
WS.wake();
}
}
var wakeUp = function(){
if(window.idle){
window.sceneryMode = true;
setIndex = Math.floor((Math.random()*setSize));
var currentSetSize=window.kimonoSet.length;
for (var i=0;i<6;i++){
var wordIndex = Math.floor((Math.random()*currentSetSize));
wordsToDisplay.push([window.kimonoSet[wordIndex][0],window.kimonoSet[wordIndex][1]]);
}
context = window.kimonoTitle;
}
}
var runInterval = function(){
if(window.refreshIntervalId!=null){
clearInterval(window.refreshIntervalId);
}
window.refreshIntervalId = setInterval(wakeUp,window.wakeInterval);
}
runInterval();
setInterval(newWord,wordInterval);
// Below this are more examples, uncomment to use them
WS.liveCardCreate(true, .2);
WSRAW.recordWSVideo(videoLength);
}
function main() {
if (WS.scriptVersion(1)) return;
context = document.getElementById('canvas').getContext("2d");
WS.serverConnect('{{WSUrl}}', server);
}
window.onload = main;
</script>
</body>
</html>
{
"name": "Vocab Beta"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment