CJP/Sandbox 1

#wjgContainer { font-family:Arial, Helvetica, Sans-Serif; font-size:0.8em;}
        #report { border-collapse:collapse;
width:90%}
        #report h4 { margin:0px; padding:0px;}
        #report img { float:right;}
        #report ul { margin:10px 0 10px 40px; padding:0px;}
        #report th { background:#7CB8E2 url() repeat-x scroll center left; color:#fff; padding:7px 15px; text-align:left;}
        #report td { background:#C7DDEE none repeat-x scroll center left; color:#000; padding:7px 15px; }
        #report tr.odd td { background:#fff url() repeat-x scroll center left; cursor:pointer; }
        #report div.arrow { background:transparent url() no-repeat scroll 0px -16px; width:16px; height:16px; display:block;}
        #report div.up { background-position:0px 0px;}

#tableContainer { 
    overflow-y: scroll; 
 height: 300px;}

#metrics{
width:80%;
text-align: center;

#tableContainer .cell{
width:20%;
text-align: center;
display: inline-block;

#tableContainer span{
width:100%;
var testScores=;
// I define a function here that takes in an array of values, calculates the exponential moving average based on a certain half-life
// and returns an array with the exponential moving average at each point.
function calc_exp_moving_average(values,half_life){
var	exp_avg_vals=new Array(values.length); //Initialize new array in which we'll put our calculated values
	for (var i = values.length; i >(-1); i=i-1) {
		exp_weights=;
		for (var j=0; j<i; j+=1){
			var weight=Math.pow(half_life, i-j-1);
			exp_weights=weight;
		};//Ends the calculation of the exponential weights for each timepoint.
		var score_sum = 0;
		var subvalues=values.slice(0,i+1);
		var exp_weight_sum=0;
		for(var i=0; i< exp_weights.length; i++) {
			score_sum += exp_weights*subvalues;
			exp_weight_sum+=exp_weights;
		}//Ends the multiplication of the weights by the scores.
		var average_score=score_sum/exp_weight_sum;
		if (i==0){average_score=values;}
	exp_avg_vals=average_score;
} //Ends the iteration through values.length
return exp_avg_vals.slice(1,exp_avg_vals.length+1);
}//Ends the function
exp_vals=calc_exp_moving_average(testScores,2/3);
function ensureLoggedIn() {
	mw.loader.using('mediawiki.user', function() {
        mw.loader.using('jquery.makeCollapsible', function() {
	if ($.isEmptyObject(wgUserName)) {
		alert("Please Log In To Continue.");
		window.location.replace(":UserLogin&returnto=UserExamQuery");
	} else {
console.log('running query');
		runQuery().done(addToggle);
console.log('finished running query');
console.log('adding class odd to the odd numbered trs');
$("tr:odd").addClass("odd");
            $("tr:not(.odd)").hide();
            $("tr:first-child").show();
            $("tr.odd").click(function(){
                $(this).next("tr").toggle();
                $(this).find(".arrow").toggleClass("up");
var addToggle = function(){
console.log('Now running function 2');
$("tr:odd").addClass("odd");
$("tr:not(.odd)").hide();
$("tr:first-child").show();
$("tr.odd").click(function(){
$(this).next("tr").toggle();
$(this).find(".arrow").toggleClass("up");
var plotNewGraph = function(){
console.log('Now plotting a graph of the user test information');
$("tr:odd").addClass("odd");
$("tr:not(.odd)").hide();
$("tr:first-child").show();
$("tr.odd").click(function(){
$(this).next("tr").toggle();
$(this).find(".arrow").toggleClass("up");
var runQuery= function() {
	var r = $.Deferred();
	var api = new mw.Api();
	api.get({
		action : 'userExamQuery',
		username : wgUserName,
		format : 'json'
	.always(function (data) {
        $.each(data.userExamQuery, function(index, value){
               var outstring = "";
                var timeBegin = "";
                var timeEnd = "";
                var scoreString = "";
                if(value.begin != null){
                      timeBegin = new Date(value.begin - 1000).toDateString();
                if(value.end != null){
                      timeEnd = new Date (value.end - 1000).toDateString();
                      scoreString = value.score + "%";
                } else {
                      timeEnd = "Unfinished";
                      scoreString = "N/A";
                if($(value.questions).length > 0){
var wjg_string=""+
            ""+value.id +"" +
            "" + timeBegin + "" +
            "" + scoreString + "" +
            "" + timeEnd + "" +
            "" + value.type + "" +
                "Additional information" +
                    "Categories selected: Cardiology, Oncology" +
                    "Subcategories selected: Pharmacology" +
                    "Resume exam!" +
$( "tbody" ).append( wjg_string );            
                outstring += ""+value.id+""+timeBegin+""+scoreString+""+timeEnd+""+value.type+"";
                outstring += "";
               // $.each(value.questions, function(ind, val){
               // outstring += val.title+"";
               // outstring += ""
               // outstring += "";
               // $("#metrics").append(outstring);
               //  $("#"+value.id).makeCollapsible();
setTimeout(function (){ // and call `resolve` on the deferred object, once you're done 
	r.resolve();
 return r 
 $("tr:odd").addClass("odd");
 $("tr:not(.odd)").hide();
 $("tr:first-child").show();
 $("tr.odd").click(function(){
                 $(this).next("tr").toggle();
                 $(this).find(".arrow").toggleClass("up");
//$(document).ready(ensureLoggedIn);
$(document).ready(function(){
	  // we call the function
console.log('about to run ensureLoggedIn');
	  ensureLoggedIn();
console.log('finished running ensureLoggedIn');            
$(document).ready(function(){
$("tr.odd").click(function(){
                $(this).next("tr").toggle();
                $(this).find(".arrow").toggleClass("up");