Widget:WJG Sandbox: Difference between revisions
Jump to navigation
Jump to search
Undo revision 1008024 by William J Gibson (talk) |
No edit summary |
||
Line 411: | Line 411: | ||
} | } | ||
function chooseQBank(event) { | function chooseQBank(event) { | ||
window.exam.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>" + | 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 />"; | ||
$("#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'><div class='round-button-circle | "<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>" | "</div>" | ||
$("#optionScreenHeader").after(tutorOrExam); | $("#optionScreenHeader").after(tutorOrExam); | ||
Line 451: | Line 451: | ||
$("#tutorOrExamContainer").after(examOptionButtons); | $("#tutorOrExamContainer").after(examOptionButtons); | ||
recordResponses() | recordResponses() | ||
$('.stepTwo').click( | countCats(window.exam) | ||
$('.stepTwo').click(window.exam, tutorOrExam); | |||
Line 486: | Line 487: | ||
//$("#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'); | |||
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( | $('.ToE').click(window.exam, categoryOrKeyword); | ||
} | } | ||
function categoryOrKeyword(event) { | function categoryOrKeyword(event) { | ||
window.exam.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( | $('.CoK').click(window.exam, timerToggle); | ||
} | } | ||
function timerToggle(event) { | function timerToggle(event) { | ||
window.exam.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 523: | Line 519: | ||
$("#exam").append(form); | $("#exam").append(form); | ||
} | } | ||
$('#yes').click( | $('#yes').click(window.exam, timerDuration); | ||
if ( | if (window.exam.searchMethod === "Category") { | ||
$('#nop').click( | $('#nop').click(window.exam, countCats); | ||
} else { | } else { | ||
$('#nop').click( | $('#nop').click(window.exam, Keywords); | ||
} | } | ||
} | } | ||
function timerDuration(event) { | function timerDuration(event) { | ||
window.exam.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 538: | Line 534: | ||
$("#exam").append(form); | $("#exam").append(form); | ||
} | } | ||
if ( | if (window.exam.searchMethod === "Category") { | ||
$('.stepFour').click( | $('.stepFour').click(window.exam, countCats); | ||
} else { | } else { | ||
$('.stepFour').click( | $('.stepFour').click(window.exam, Keywords); | ||
} | } | ||
} | } | ||
Line 587: | Line 583: | ||
}); | }); | ||
$("#showQueries").click( | $("#showQueries").click(window.exam, showQueries); | ||
function showQueries(event) { | function showQueries(event) { | ||
$("#removeNum").remove(); | $("#removeNum").remove(); | ||
window.exam.queries = []; | |||
window.exam.questionListAll = []; | |||
window.exam.keyword = {}; | |||
window.exam.keyword.iterator = 0; | |||
$.each($(".query"), function (index, value) { | $.each($(".query"), function (index, value) { | ||
window.exam.queries[index] = "[[ExamType::" + window.exam.examtype + "]]"; | |||
$.each($(this).children(), function (ind, val) { | $.each($(this).children(), function (ind, val) { | ||
window.exam.queries[index] += "[[WBRKeyword::" + $(this).val() + "]]"; | |||
}); | }); | ||
}); | }); | ||
runQueries( | runQueries(window.exam); | ||
} | } | ||
function runQueries(obj) { | function runQueries(obj) { | ||
Line 639: | Line 635: | ||
} | } | ||
function TNG(event) { | function TNG(event) { | ||
window.exam.numQuestion = $("#numQues").val(); | |||
if( | if(window.exam.numQuestion > 0 && window.exam.numQuestion <= 45){ | ||
loadNextQuestion( | loadNextQuestion(window.exam); | ||
} else { | } else { | ||
alert('Invalid number of questions entered.'); | alert('Invalid number of questions entered.'); | ||
Line 742: | Line 738: | ||
Sub.push($(this).val()); | Sub.push($(this).val()); | ||
}); | }); | ||
window.exam.mainCat = Main; | |||
window.exam.subCat = Sub; | |||
var api = new mw.Api(event, Main, Sub); | var api = new mw.Api(event, Main, Sub); | ||
api.get({ | api.get({ | ||
Line 749: | Line 745: | ||
main : JSON.stringify(Main), | main : JSON.stringify(Main), | ||
sub : JSON.stringify(Sub), | sub : JSON.stringify(Sub), | ||
exam : | exam : window.exam.examtype, | ||
format : 'json' | format : 'json' | ||
}, { | }, { | ||
ok : function (res) { | ok : function (res) { | ||
if( res.Count > 45){ | if( res.Count > 45){ | ||
window.exam.maxQ = 45; | |||
} else { | } else { | ||
window.exam.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'>" + | 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>"; | ||
if ($("#exam").find('#numQues').length == 0) { | if ($("#exam").find('#numQues').length == 0) { | ||
$("#exam").append(output); | $("#exam").append(output); | ||
} | } | ||
$("#Go").click( | $("#Go").click(window.exam, inputValidation); | ||
} | } | ||
}); | }); | ||
Line 772: | Line 768: | ||
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(); | |||
$("#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 ( | if (window.exam.timer) { | ||
window.exam.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(); | |||
$("#content").click( | $("#content").click(window.exam, endExam); | ||
} else { | } else { | ||
var temp = rem - 7; | var temp = rem - 7; | ||
Line 791: | Line 787: | ||
}, 70, false); | }, 70, false); | ||
window.exam.examTimer.toggle(); | |||
} | } | ||
loadNextQuestion( | loadNextQuestion(window.exam); | ||
} else { | } else { | ||
alert('Invalid entry in number of questions input'); | alert('Invalid entry in number of questions input'); | ||
Line 1,052: | Line 1,048: | ||
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( | $("#submit").click(window.exam, answerSubmitted); | ||
} | } | ||
} | } | ||
Line 1,094: | Line 1,090: | ||
function answerSubmitted(event) { | function answerSubmitted(event) { | ||
$("#submit").remove(); | $("#submit").remove(); | ||
window.exam.examQuestions[window.exam.currentQuestion].selectedAnswer = $(".answer.boxed").attr("id"); | |||
if (! | if (!window.exam.examQuestions[window.exam.currentQuestion].creditRecieved && window.exam.examQuestions[window.exam.currentQuestion].selectedAnswer === window.exam.examQuestions[window.exam.currentQuestion].RightAnswer) { | ||
window.exam.answeredRight += 1; | |||
window.exam.examQuestions[window.exam.currentQuestion].creditRecieved = true; | |||
} | } | ||
if ( | if (window.exam.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') === | if($(this).attr('id') === window.exam.examQuestions[window.exam.currentQuestion].RightAnswer+"e"){ | ||
$(this).prepend(" <b>Correct:</b> "); | $(this).prepend(" <b>Correct:</b> "); | ||
} else { | } else { | ||
Line 1,117: | Line 1,113: | ||
action : 'wbrinsertmetric', | action : 'wbrinsertmetric', | ||
username : mw.user.getName(), | username : mw.user.getName(), | ||
question : | question : window.exam.examQuestions[window.exam.currentQuestion].PageName, | ||
selectedAnswer : | selectedAnswer : window.exam.examQuestions[window.exam.currentQuestion].selectedAnswer, | ||
format : 'json' | format : 'json' | ||
}) | }) | ||
Line 1,124: | Line 1,120: | ||
console.log('API result:', data); | console.log('API result:', data); | ||
}); | }); | ||
if ( | if (window.exam.examType === "Exam") { | ||
$("#" + | $("#" + window.exam.examQuestions[window.exam.currentQuestion].selectedAnswer).addClass("boxed"); | ||
} else if ( | } else if (window.exam.examType === "Tutor") { | ||
$("#examSpace").append("<br /><br />The correct answer is: " + | $("#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("<b>Author:</b> " + | $("#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>"); | ||
$("#" + | $("#" + window.exam.examQuestions[window.exam.currentQuestion].selectedAnswer).addClass("boxed"); | ||
$("#" + | $("#" + window.exam.examQuestions[window.exam.currentQuestion].RightAnswer).addClass("redBoxed"); | ||
addRatyRating( | addRatyRating(window.exam); | ||
} | } | ||
} | } | ||
function questionNavigation(event) { | function questionNavigation(event) { | ||
$("#" + | $("#" + window.exam.currentQuestion).removeClass("boxed"); | ||
if ($(this).attr("id") === "back") { | if ($(this).attr("id") === "back") { | ||
window.exam.currentQuestion--; | |||
} else if ($(this).attr("id") === "next") { | } else if ($(this).attr("id") === "next") { | ||
window.exam.currentQuestion++; | |||
} else if ($(this).attr("class") === "navPaneButton") { | } else if ($(this).attr("class") === "navPaneButton") { | ||
window.exam.currentQuestion = $(this).attr("id"); | |||
} | } | ||
$("#" + | $("#" + window.exam.currentQuestion).addClass("boxed"); | ||
questionDisplay( | questionDisplay(window.exam); | ||
} | } | ||
function questionReviewNavigation(event) { | function questionReviewNavigation(event) { | ||
$("#" + | $("#" + window.exam.currentQuestion).removeClass("boxed"); | ||
if ($(this).attr("id") === "back") { | if ($(this).attr("id") === "back") { | ||
window.exam.currentQuestion--; | |||
} else if ($(this).attr("id") === "next") { | } else if ($(this).attr("id") === "next") { | ||
window.exam.currentQuestion++; | |||
} else if ($(this).attr("class") === "navPaneButton") { | } else if ($(this).attr("class") === "navPaneButton") { | ||
window.exam.currentQuestion = $(this).attr("id"); | |||
} | } | ||
$("#" + | $("#" + window.exam.currentQuestion).addClass("boxed"); | ||
questionReview( | questionReview(window.exam); | ||
} | } | ||
Line 1,163: | Line 1,159: | ||
//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'); | ||
//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"); | ||
} | } | ||
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,201: | Line 1,198: | ||
function endExam(event) { | function endExam(event) { | ||
if ( | if (window.exam.timer) { | ||
$('#timerBox').html(""); | $('#timerBox').html(""); | ||
$('#timerBox').css("visibility", "hidden"); | $('#timerBox').css("visibility", "hidden"); | ||
window.exam.examTimer.stop(); | |||
} | } | ||
$("#examSpace").html(""); | $("#examSpace").html(""); | ||
var datas; | var datas; | ||
datas = ""; | datas = ""; | ||
datas += "<br />You answered " + | datas += "<br />You answered " + window.exam.answeredRight + " out of " + window.exam.examQuestions.length + " correctly.<br /> Your percentage score is: "; | ||
var percent = Math.round(( | var percent = Math.round((window.exam.answeredRight / window.exam.examQuestions.length) * 100); | ||
testlength= | testlength=window.exam.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,220: | Line 1,217: | ||
var myTotal = 0; //Variable to hold your total | var myTotal = 0; //Variable to hold your total | ||
for(var i=0, len= | for(var i=0, len=window.exam.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,236: | Line 1,233: | ||
action : 'wbrinsertexam', | action : 'wbrinsertexam', | ||
username : mw.user.getName(), | username : mw.user.getName(), | ||
size : | size : window.exam.examQuestions.length, | ||
score : percent, | score : percent, | ||
format : 'json' | format : 'json' | ||
Line 1,243: | Line 1,240: | ||
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,302: | Line 1,297: | ||
$(".navPaneButton").unbind('click'); | $(".navPaneButton").unbind('click'); | ||
$(".navPaneButton").click( | $(".navPaneButton").click(window.exam, questionReviewNavigation); | ||
} | } | ||
function submitRating(ratingType, score, page) { | function submitRating(ratingType, score, page) { | ||
Line 1,459: | Line 1,454: | ||
} | } | ||
function countCats(event) { | function countCats(event) { | ||
window.exam.timeAmt = parseInt($(this).attr("id"), 10) * 6000; | |||
var temp = | var temp = window.exam.examtype.replace(/ /g, "_"); | ||
var api = new mw.Api(); | var api = new mw.Api(); | ||
api.get({ | api.get({ | ||
Line 1,469: | Line 1,464: | ||
}, { | }, { | ||
ok : function (data) { | ok : function (data) { | ||
window.exam.arrCounts = data; | |||
selectCats( | selectCats(window.exam); | ||
} | } | ||
}); | }); |