Widget:WJG Sandbox: Difference between revisions

Jump to navigation Jump to search
No edit summary
Undo revision 1008029 by William J Gibson (talk)
 
Line 411: Line 411:
}
}
function chooseQBank(event) {
function chooseQBank(event) {
window.exam.examtype = $(this).attr('id');
event.data.examtype = $(this).attr('id');
$("#chooseQBank").remove();//Once the QBank is picked, we'll remove the div that held it.
$("#chooseQBank").remove();//Once the QBank is picked, we'll remove the div that held it.
$("#exam").show();
$("#exam").show();
var divs = null;
var divs = null;
divs = "<div class= 'container' id='optionScreenHeader' style='height:200px' ><header><h1>" +window.exam.examtype+ " </br> <span> Select your options below</span></h1></header></div><div id='Pat' class='noSelect WBRButton stepTwo'><br />USMLE Format</div><div id='Flash' class='noSelect WBRButton stepTwo'><br />Flash Cards</div><br /><br /><br />";
divs = "<div class= 'container' id='optionScreenHeader' style='height:200px' ><header><h1>" +event.data.examtype+ " </br> <span> Select your options below</span></h1></header></div><div id='Pat' class='noSelect WBRButton stepTwo'><br />USMLE Format</div><div id='Flash' class='noSelect WBRButton stepTwo'><br />Flash Cards</div><br /><br /><br />";
$("#exam").html(divs);
$("#exam").html(divs);
var temp_str="<div id= 'examOptions'></div>";
var temp_str="<div id= 'examOptions'></div>";
//$("#exam").append(temp_str);
//$("#exam").append(temp_str);
var tutorOrExam="<div class='container' id='tutorOrExamContainer' style='height:110px'>"+
var tutorOrExam="<div class='container' id='tutorOrExamContainer' style='height:110px'>"+
"<div class='round-button Curric' id='tutorModeBigButton' style='margin-left:calc(50% - 100px);margin-top: 5px;'><div class='round-button-circle'><p class='round-button' style='font-size:1.5em;'>Tutor \n Mode</p></div></div><div id='spacer'  style='display: inline'></div>"+
"<div class='round-button Curric' id='tutorModeBigButton' style='margin-left:calc(50% - 100px); margin-top:5px'><div class='round-button-circle'><p class='round-button' style='font-size:1.5em;'>Tutor \n Mode</p></div></div><div id='spacer'  style='display: inline'></div>"+
"<div class='round-button Curric' id='examModeBigButton' style='margin-top: 5px;'><div class='round-button-circle><p class='round-button' style='font-size:1.5em;'>Exam \n Mode</p></div></div><div id='spacer'  style='display: inline'></div>"+
"<div class='round-button Curric' id='examModeBigButton'><div class='round-button-circle'><p class='round-button' style='font-size:1.5em;'>Exam \n Mode</p></div></div><div id='spacer'  style='display: inline'></div>"+
"</div>"
"</div>"
$("#optionScreenHeader").after(tutorOrExam);
$("#optionScreenHeader").after(tutorOrExam);
Line 451: Line 451:
$("#tutorOrExamContainer").after(examOptionButtons);
$("#tutorOrExamContainer").after(examOptionButtons);
recordResponses()
recordResponses()
countCats(window.exam)
$('.stepTwo').click(event.data, tutorOrExam);
$('.stepTwo').click(window.exam, tutorOrExam);
Line 487: Line 486:
//$("#exam").append("<div id='displayVals'></div>");
//$("#exam").append("<div id='displayVals'></div>");
}
}


function displayVals() {
function displayVals() {
Line 496: Line 496:
"<b> Timed or Untimed: </b>" + timerSetting);
"<b> Timed or Untimed: </b>" + timerSetting);
}
}


function tutorOrExam(event) {
function tutorOrExam(event) {


window.exam.qbank = $(this).attr('id');
event.data.qbank = $(this).attr('id');
var buttons = '';
var buttons = '';
buttons = "<div id='Tutor' class='noSelect WBRButton ToE'><br />Tutor Mode</div><div id='Exam' class='noSelect WBRButton ToE'><br />Exam Mode</div><br /><br /><br />";
buttons = "<div id='Tutor' class='noSelect WBRButton ToE'><br />Tutor Mode</div><div id='Exam' class='noSelect WBRButton ToE'><br />Exam Mode</div><br /><br /><br />";
$("#exam").append(buttons);
$("#exam").append(buttons);
$('.ToE').click(window.exam, categoryOrKeyword);
$('.ToE').click(event.data, categoryOrKeyword);
}
}
function categoryOrKeyword(event) {
function categoryOrKeyword(event) {
window.exam.examType = $(this).attr('id');
event.data.examType = $(this).attr('id');
var buttons = '';
var buttons = '';
buttons = "<div id='Category' class='noSelect WBRButton CoK'><br />Category</div><div id='Keyword' class='noSelect WBRButton CoK'><br />Keyword</div><br /><br /><br />";
buttons = "<div id='Category' class='noSelect WBRButton CoK'><br />Category</div><div id='Keyword' class='noSelect WBRButton CoK'><br />Keyword</div><br /><br /><br />";
$("#exam").append(buttons);
$("#exam").append(buttons);
$('.CoK').click(window.exam, timerToggle);
$('.CoK').click(event.data, timerToggle);
}
}
function timerToggle(event) {
function timerToggle(event) {
window.exam.searchMethod = $(this).attr('id');
event.data.searchMethod = $(this).attr('id');
var form = null;
var form = null;
form = "<div id='yes' class='noSelect WBRButton stepThree'><br />Enable Timer</div><div id='nop' class='noSelect WBRButton stepThree'><br />Disable Timer</div><br /><br /><br />";
form = "<div id='yes' class='noSelect WBRButton stepThree'><br />Enable Timer</div><div id='nop' class='noSelect WBRButton stepThree'><br />Disable Timer</div><br /><br /><br />";
Line 519: Line 523:
$("#exam").append(form);
$("#exam").append(form);
}
}
$('#yes').click(window.exam, timerDuration);
$('#yes').click(event.data, timerDuration);


if (window.exam.searchMethod === "Category") {
if (event.data.searchMethod === "Category") {
$('#nop').click(window.exam, countCats);
$('#nop').click(event.data, countCats);
} else {
} else {
$('#nop').click(window.exam, Keywords);
$('#nop').click(event.data, Keywords);
}
}
}
}
function timerDuration(event) {
function timerDuration(event) {
window.exam.timer = true;
event.data.timer = true;
var form = null;
var form = null;
form = "<div id='1' class='noSelect WBRButton stepFour'><br />1 Minute</div><div id='10' class='noSelect WBRButton stepFour'><br />10 Minute</div><div id='20' class='noSelect WBRButton stepFour'><br />20 Minutes</div><div id='40' class='noSelect WBRButton stepFour'><br />40 Minutes</div><br /><br /><br />"
form = "<div id='1' class='noSelect WBRButton stepFour'><br />1 Minute</div><div id='10' class='noSelect WBRButton stepFour'><br />10 Minute</div><div id='20' class='noSelect WBRButton stepFour'><br />20 Minutes</div><div id='40' class='noSelect WBRButton stepFour'><br />40 Minutes</div><br /><br /><br />"
Line 534: Line 538:
$("#exam").append(form);
$("#exam").append(form);
}
}
if (window.exam.searchMethod === "Category") {
if (event.data.searchMethod === "Category") {
$('.stepFour').click(window.exam, countCats);
$('.stepFour').click(event.data, countCats);
} else {
} else {
$('.stepFour').click(window.exam, Keywords);
$('.stepFour').click(event.data, Keywords);
}
}
}
}
Line 583: Line 587:
});
});


$("#showQueries").click(window.exam, showQueries);
$("#showQueries").click(event.data, showQueries);
function showQueries(event) {
function showQueries(event) {
$("#removeNum").remove();
$("#removeNum").remove();
window.exam.queries = [];
event.data.queries = [];
window.exam.questionListAll = [];
event.data.questionListAll = [];
window.exam.keyword = {};
event.data.keyword = {};
window.exam.keyword.iterator = 0;
event.data.keyword.iterator = 0;
$.each($(".query"), function (index, value) {
$.each($(".query"), function (index, value) {
window.exam.queries[index] = "[[ExamType::" + window.exam.examtype + "]]";
event.data.queries[index] = "[[ExamType::" + event.data.examtype + "]]";
$.each($(this).children(), function (ind, val) {
$.each($(this).children(), function (ind, val) {
window.exam.queries[index] += "[[WBRKeyword::" + $(this).val() + "]]";
event.data.queries[index] += "[[WBRKeyword::" + $(this).val() + "]]";
});
});
});
});
runQueries(window.exam);
runQueries(event.data);
}
}
function runQueries(obj) {
function runQueries(obj) {
Line 635: Line 639:
}
}
function TNG(event) {
function TNG(event) {
window.exam.numQuestion = $("#numQues").val();
event.data.numQuestion = $("#numQues").val();
         if(window.exam.numQuestion > 0 && window.exam.numQuestion <= 45){
         if(event.data.numQuestion > 0 && event.data.numQuestion <= 45){
loadNextQuestion(window.exam);
loadNextQuestion(event.data);
         } else {
         } else {
         alert('Invalid number of questions entered.');
         alert('Invalid number of questions entered.');
Line 738: Line 742:
Sub.push($(this).val());
Sub.push($(this).val());
});
});
window.exam.mainCat = Main;
event.data.mainCat = Main;
window.exam.subCat = Sub;
event.data.subCat = Sub;
var api = new mw.Api(event, Main, Sub);
var api = new mw.Api(event, Main, Sub);
api.get({
api.get({
Line 745: Line 749:
main : JSON.stringify(Main),
main : JSON.stringify(Main),
sub : JSON.stringify(Sub),
sub : JSON.stringify(Sub),
exam : window.exam.examtype,
exam : event.data.examtype,
format : 'json'
format : 'json'
}, {
}, {
ok : function (res) {
ok : function (res) {
                 if( res.Count > 45){
                 if( res.Count > 45){
                         window.exam.maxQ = 45;
                         event.data.maxQ = 45;
                 } else {
                 } else {
                         window.exam.maxQ = res.Count;
                         event.data.maxQ = res.Count;
                 }
                 }
var output = "<b>Choose the number of questions you would like to answer. The maximum number of questions you can select is <span id='countShow'>" + window.exam.maxQ + "</span>.</b><br /><br /><br />Number of questions:<input type='text' id='numQues' /><br /><br /><div id='Go' class='noSelect WBRButton'>Click here to begin the exam</div>";
var output = "<b>Choose the number of questions you would like to answer. The maximum number of questions you can select is <span id='countShow'>" + event.data.maxQ + "</span>.</b><br /><br /><br />Number of questions:<input type='text' id='numQues' /><br /><br /><div id='Go' class='noSelect WBRButton'>Click here to begin the exam</div>";
if ($("#exam").find('#numQues').length == 0) {
if ($("#exam").find('#numQues').length == 0) {
$("#exam").append(output);
$("#exam").append(output);


}
}
$("#Go").click(window.exam, inputValidation);
$("#Go").click(event.data, inputValidation);
}
}
});
});
Line 768: Line 772:
function inputValidation(event) {
function inputValidation(event) {
if ($("#numQues").val().length > 0 && parseInt($("#numQues").val(), 10) <= parseInt($("#countShow").html(), 10) && parseInt($("#numQues").val(), 10) > 0) {
if ($("#numQues").val().length > 0 && parseInt($("#numQues").val(), 10) <= parseInt($("#countShow").html(), 10) && parseInt($("#numQues").val(), 10) > 0) {
window.exam.numQuestion = $("#numQues").val();
event.data.numQuestion = $("#numQues").val();
$("#exam").html("<img src='http://static.wikidoc.org/5/51/Index.gif' />");
$("#exam").html("<img src='http://static.wikidoc.org/5/51/Index.gif' />");
if (window.exam.timer) {
if (event.data.timer) {
window.exam.examTimer = $.timer(function () {
event.data.examTimer = $.timer(function () {
var rem = parseInt($("#timeRem").html());
var rem = parseInt($("#timeRem").html());
$('#timerBox').css("visibility", "visible");
$('#timerBox').css("visibility", "visible");
$('#timerBox').html(formatTime(rem));
$('#timerBox').html(formatTime(rem));
if (rem == 0) {
if (rem == 0) {
window.exam.examTimer.stop();
event.data.examTimer.stop();
$("#content").click(window.exam, endExam);
$("#content").click(event.data, endExam);
} else {
} else {
var temp = rem - 7;
var temp = rem - 7;
Line 787: Line 791:
}, 70, false);
}, 70, false);


window.exam.examTimer.toggle();
event.data.examTimer.toggle();
}
}
loadNextQuestion(window.exam);
loadNextQuestion(event.data);
} else {
} else {
alert('Invalid entry in number of questions input');
alert('Invalid entry in number of questions input');
Line 1,048: Line 1,052:
if($("#exam").find('#submit').length == 0){  
if($("#exam").find('#submit').length == 0){  
$("#examSpace").append("<div class='noSelect WBRButton' id='submit'><br />Submit</div>");
$("#examSpace").append("<div class='noSelect WBRButton' id='submit'><br />Submit</div>");
                 $("#submit").click(window.exam, answerSubmitted);
                 $("#submit").click(event.data, answerSubmitted);
}
}
}
}
Line 1,090: Line 1,094:
function answerSubmitted(event) {
function answerSubmitted(event) {
         $("#submit").remove();
         $("#submit").remove();
window.exam.examQuestions[window.exam.currentQuestion].selectedAnswer = $(".answer.boxed").attr("id");
event.data.examQuestions[event.data.currentQuestion].selectedAnswer = $(".answer.boxed").attr("id");
if (!window.exam.examQuestions[window.exam.currentQuestion].creditRecieved && window.exam.examQuestions[window.exam.currentQuestion].selectedAnswer === window.exam.examQuestions[window.exam.currentQuestion].RightAnswer) {
if (!event.data.examQuestions[event.data.currentQuestion].creditRecieved && event.data.examQuestions[event.data.currentQuestion].selectedAnswer === event.data.examQuestions[event.data.currentQuestion].RightAnswer) {


window.exam.answeredRight += 1;
event.data.answeredRight += 1;
window.exam.examQuestions[window.exam.currentQuestion].creditRecieved = true;
event.data.examQuestions[event.data.currentQuestion].creditRecieved = true;
}
}
if (window.exam.examType === "Tutor") {
if (event.data.examType === "Tutor") {
$(".answerExp").css("height", "auto");
$(".answerExp").css("height", "auto");
$(".answerExp").css("visibility", "visible");
$(".answerExp").css("visibility", "visible");
                 $(".answerExp").each(function(){
                 $(".answerExp").each(function(){
                               if($(this).attr('id') === window.exam.examQuestions[window.exam.currentQuestion].RightAnswer+"e"){
                               if($(this).attr('id') === event.data.examQuestions[event.data.currentQuestion].RightAnswer+"e"){
                                       $(this).prepend("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Correct:</b> ");
                                       $(this).prepend("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Correct:</b> ");
                               } else {
                               } else {
Line 1,113: Line 1,117:
action : 'wbrinsertmetric',
action : 'wbrinsertmetric',
username : mw.user.getName(),
username : mw.user.getName(),
question : window.exam.examQuestions[window.exam.currentQuestion].PageName,
question : event.data.examQuestions[event.data.currentQuestion].PageName,
selectedAnswer : window.exam.examQuestions[window.exam.currentQuestion].selectedAnswer,
selectedAnswer : event.data.examQuestions[event.data.currentQuestion].selectedAnswer,
format : 'json'
format : 'json'
})
})
Line 1,120: Line 1,124:
console.log('API result:', data);
console.log('API result:', data);
});
});
if (window.exam.examType === "Exam") {
if (event.data.examType === "Exam") {
$("#" + window.exam.examQuestions[window.exam.currentQuestion].selectedAnswer).addClass("boxed");
$("#" + event.data.examQuestions[event.data.currentQuestion].selectedAnswer).addClass("boxed");
} else if (window.exam.examType === "Tutor") {
} else if (event.data.examType === "Tutor") {
$("#examSpace").append("<br /><br />The correct answer is: " + window.exam.examQuestions[window.exam.currentQuestion].RightAnswer + "<br /><br />" + window.exam.examQuestions[window.exam.currentQuestion].Explanation + "<br />");
$("#examSpace").append("<br /><br />The correct answer is: " + event.data.examQuestions[event.data.currentQuestion].RightAnswer + "<br /><br />" + event.data.examQuestions[event.data.currentQuestion].Explanation + "<br />");
                 $("#examSpace").append("<b>Author:</b> " +  window.exam.examQuestions[window.exam.currentQuestion].PageAuthor + "<br /><br /><b>Wiki Page:</b>" + window.exam.examQuestions[window.exam.currentQuestion].PageName + "<br /><br />Discuss this question <a href='http://www.wikidoc.org/index.php/Talk:" + window.exam.examQuestions[window.exam.currentQuestion].PageName + "'>Here</a>");
                 $("#examSpace").append("<b>Author:</b> " +  event.data.examQuestions[event.data.currentQuestion].PageAuthor + "<br /><br /><b>Wiki Page:</b>" + event.data.examQuestions[event.data.currentQuestion].PageName + "<br /><br />Discuss this question <a href='http://www.wikidoc.org/index.php/Talk:" + event.data.examQuestions[event.data.currentQuestion].PageName + "'>Here</a>");
$("#" + window.exam.examQuestions[window.exam.currentQuestion].selectedAnswer).addClass("boxed");
$("#" + event.data.examQuestions[event.data.currentQuestion].selectedAnswer).addClass("boxed");
$("#" + window.exam.examQuestions[window.exam.currentQuestion].RightAnswer).addClass("redBoxed");
$("#" + event.data.examQuestions[event.data.currentQuestion].RightAnswer).addClass("redBoxed");
addRatyRating(window.exam);
addRatyRating(event.data);
}
}
          
          
}
}
function questionNavigation(event) {
function questionNavigation(event) {
$("#" + window.exam.currentQuestion).removeClass("boxed");
$("#" + event.data.currentQuestion).removeClass("boxed");
if ($(this).attr("id") === "back") {
if ($(this).attr("id") === "back") {
window.exam.currentQuestion--;
event.data.currentQuestion--;
} else if ($(this).attr("id") === "next") {
} else if ($(this).attr("id") === "next") {
window.exam.currentQuestion++;
event.data.currentQuestion++;
} else if ($(this).attr("class") === "navPaneButton") {
} else if ($(this).attr("class") === "navPaneButton") {
window.exam.currentQuestion = $(this).attr("id");
event.data.currentQuestion = $(this).attr("id");
}
}
$("#" + window.exam.currentQuestion).addClass("boxed");
$("#" + event.data.currentQuestion).addClass("boxed");
questionDisplay(window.exam);
questionDisplay(event.data);
}
}
function questionReviewNavigation(event) {
function questionReviewNavigation(event) {
$("#" + window.exam.currentQuestion).removeClass("boxed");
$("#" + event.data.currentQuestion).removeClass("boxed");
if ($(this).attr("id") === "back") {
if ($(this).attr("id") === "back") {
window.exam.currentQuestion--;
event.data.currentQuestion--;
} else if ($(this).attr("id") === "next") {
} else if ($(this).attr("id") === "next") {
window.exam.currentQuestion++;
event.data.currentQuestion++;
} else if ($(this).attr("class") === "navPaneButton") {
} else if ($(this).attr("class") === "navPaneButton") {
window.exam.currentQuestion = $(this).attr("id");
event.data.currentQuestion = $(this).attr("id");
}
}
$("#" + window.exam.currentQuestion).addClass("boxed");
$("#" + event.data.currentQuestion).addClass("boxed");
questionReview(window.exam);
questionReview(event.data);
}
}


Line 1,159: Line 1,163:
//var cur_q=exam.currentQuestion;
//var cur_q=exam.currentQuestion;
// var temp_flag_div_id='.navPaneButton#'+cur_q;
// var temp_flag_div_id='.navPaneButton#'+cur_q;
// $("#" + window.exam.currentQuestion).toggleClass('flagged');
// $("#" + event.data.currentQuestion).toggleClass('flagged');
//alert("You clicked the flag!"+temp_flag_div_id);
//alert("You clicked the flag!"+temp_flag_div_id);
// })
// })
function flagQ(event) {
function flagQ(event) {
$("#" + window.exam.currentQuestion).toggleClass("flagged");
$("#" + event.data.currentQuestion).toggleClass("flagged");
}
}


function showLabs(event) {
function showLabs(event) {
$("#details").stop();
$("#details").stop();
$("#details").slideToggle("slow");
$("#details").slideToggle("slow");}
}


function convolve_bernouli(qprobs){
function convolve_bernouli(qprobs){
Line 1,198: Line 1,201:


function endExam(event) {
function endExam(event) {
if (window.exam.timer) {
if (event.data.timer) {
$('#timerBox').html("");
$('#timerBox').html("");
$('#timerBox').css("visibility", "hidden");
$('#timerBox').css("visibility", "hidden");
window.exam.examTimer.stop();
event.data.examTimer.stop();
}
}
$("#examSpace").html("");
$("#examSpace").html("");
var datas;
var datas;
datas = "";
datas = "";
datas += "<br />You answered " + window.exam.answeredRight + " out of " + window.exam.examQuestions.length + " correctly.<br /> Your percentage score is: ";
datas += "<br />You answered " + event.data.answeredRight + " out of " + event.data.examQuestions.length + " correctly.<br /> Your percentage score is: ";
var percent = Math.round((window.exam.answeredRight / window.exam.examQuestions.length) * 100);
var percent = Math.round((event.data.answeredRight / event.data.examQuestions.length) * 100);
testlength=window.exam.examQuestions.length;
testlength=event.data.examQuestions.length;
var question_probs=[];
var question_probs=[];
for (var j = 0; j < testlength; j+=1){
for (var j = 0; j < testlength; j+=1){
Line 1,217: Line 1,220:
var myTotal = 0;  //Variable to hold your total
var myTotal = 0;  //Variable to hold your total


for(var i=0, len=window.exam.answeredRight+1; i<len; i++){
for(var i=0, len=event.data.answeredRight+1; i<len; i++){
     myTotal += qdist[i];  //Iterate over your first array and then grab the second element add the values up
     myTotal += qdist[i];  //Iterate over your first array and then grab the second element add the values up
}
}
Line 1,233: Line 1,236:
action : 'wbrinsertexam',
action : 'wbrinsertexam',
username : mw.user.getName(),
username : mw.user.getName(),
size : window.exam.examQuestions.length,
size : event.data.examQuestions.length,
score : percent,
score : percent,
format : 'json'
format : 'json'
Line 1,240: Line 1,243:
console.log('API result:', data);
console.log('API result:', data);
});
});
}
           
 
 
// Here's some code to create the labels for the graph (recall that qdist is the distribution of points).
// Here's some code to create the labels for the graph (recall that qdist is the distribution of points).


Line 1,297: Line 1,302:


$(".navPaneButton").unbind('click');
$(".navPaneButton").unbind('click');
$(".navPaneButton").click(window.exam, questionReviewNavigation);
$(".navPaneButton").click(event.data, questionReviewNavigation);
}
}
function submitRating(ratingType, score, page) {
function submitRating(ratingType, score, page) {
Line 1,454: Line 1,459:
}
}
function countCats(event) {
function countCats(event) {
window.exam.timeAmt = parseInt($(this).attr("id"), 10) * 6000;
event.data.timeAmt = parseInt($(this).attr("id"), 10) * 6000;
var temp = window.exam.examtype.replace(/ /g, "_");
var temp = event.data.examtype.replace(/ /g, "_");
var api = new mw.Api();
var api = new mw.Api();
api.get({
api.get({
Line 1,464: Line 1,469:
}, {
}, {
ok : function (data) {
ok : function (data) {
window.exam.arrCounts = data;
event.data.arrCounts = data;
selectCats(window.exam);
selectCats(event.data);
}
}
});
});

Latest revision as of 00:56, 10 August 2014