n@1223: /* n@1223: * Analysis script for WAET n@1223: */ n@1223: n@1223: var chartContext; n@1223: window.onload = function() { n@1223: // Load the Visualization API and the corechart package. n@1223: google.charts.load('current', {'packages':['corechart']}); n@1223: chartContext = new Chart(); n@1223: } n@1223: n@1227: function arrayMean(values) { n@1227: var mean = 0; n@1227: for (var value of values) { n@1227: mean += value; n@1227: } n@1227: mean /= values.length; n@1227: return mean; n@1227: } n@1227: n@1227: function percentile(values, n) { n@1227: values.sort( function(a,b) {return a - b;} ); n@1227: // get ordinal rank n@1227: var rank = Math.min(Math.floor(values.length*n/100), values.length-1); n@1227: return values[rank]; n@1227: } n@1227: n@1227: function arrayMin(array) { n@1227: // Return the minimum value of an array n@1227: var min = array[0]; n@1227: for (var value of array) { n@1227: if (value < min) { n@1227: min = value; n@1227: } n@1227: } n@1227: return min; n@1227: } n@1227: n@1227: function arrayMax(array) { n@1227: // Return the minimum value of an array n@1227: var max = array[0]; n@1227: for (var value of array) { n@1227: if (value > max) { n@1227: max = value; n@1227: } n@1227: } n@1227: return max; n@1227: } n@1227: n@1227: function arrayHistogram(values,steps,min,max) { n@1227: if (steps == undefined) { n@1227: steps = 0.25; n@1227: console.log("Warning: arrayHistogram called without steps size set, default to 0.25"); n@1227: } n@1227: if (min == undefined) {min = arrayMin(values);} n@1227: if (max == undefined) {max = arrayMax(values);} n@1227: var histogram = []; n@1227: var index = min; n@1227: while(index < max) { n@1227: histogram.push({ n@1227: marker: index, n@1227: lt: index, n@1227: rt: index+steps, n@1227: count: 0 n@1227: }); n@1227: index += steps; n@1227: } n@1227: for (var value of values) { n@1227: for (var entry of histogram) { n@1227: if (value >= entry.lt && value <= entry.rt) { n@1227: entry.count++; n@1227: break; n@1227: } n@1227: } n@1227: } n@1227: return histogram; n@1227: } n@1227: n@1223: function Chart() { n@1226: this.valueData = null; n@1226: this.commentData = null; n@1226: this.loadStatus = 0; n@1227: this.charts = []; n@1223: n@1226: var XMLHttp = new XMLHttpRequest(); n@1226: XMLHttp.parent = this; n@1226: XMLHttp.open("GET","../scripts/score_parser.php?format=JSON",true); n@1226: XMLHttp.onload = function() { n@1226: // Now we have the JSON data, extract n@1226: this.parent.valueData = JSON.parse(this.responseText); n@1226: this.parent.loadStatus++; n@1223: } n@1226: XMLHttp.send(); n@1226: var XMLHttp2 = new XMLHttpRequest(); n@1226: XMLHttp2.parent = this; n@1226: XMLHttp2.open("GET","../scripts/comment_parser.php?format=JSON",true); n@1226: XMLHttp2.onload = function() { n@1226: // Now we have the JSON data, extract n@1226: this.parent.commentData = JSON.parse(this.responseText); n@1226: this.parent.loadStatus++; n@1226: } n@1226: XMLHttp2.send(); n@1223: n@1227: this.chartObject = function(name) { n@1227: // Create the charting object n@1227: this.name = name; n@1227: this.root = document.createElement("div"); n@1227: this.root.className = "chart-holder"; n@1227: this.root.setAttribute("name",name); n@1227: this.chartDOM = document.createElement("div"); n@1227: this.tableDOM = document.createElement("div"); n@1227: this.latexDOM = document.createElement("div"); n@1227: this.downloadDOM = document.createElement("div"); n@1227: this.chart = undefined; n@1227: this.data = new google.visualization.DataTable(); n@1227: this.options = {}; n@1227: this.print = document.createElement("button"); n@1228: this.sortDataButton = document.createElement("button"); n@1228: this.sortDataButton.textContent = "Sort by Data"; n@1228: this.sortDataButton.addEventListener("click",this); n@1228: this.sortDataButton.setAttribute("name","sort-data"); n@1228: this.sortNameButton = document.createElement("button"); n@1228: this.sortNameButton.textContent = "Sort by Name"; n@1228: this.sortNameButton.addEventListener("click",this); n@1228: this.sortNameButton.setAttribute("name","sort-name"); n@1228: this.draw = function() { n@1228: if (this.chart == undefined) {return;} n@1228: this.tableDOM.innerHTML = null; n@1228: this.latexDOM.innerHTML = null; n@1228: this.buildTable(); n@1228: this.writeLatex(); n@1228: this.chart.draw(this.data,this.options); n@1228: } n@1228: this.sortData = function() { n@1228: n@1228: var map = this.data.Jf.map(function(el,i){ n@1228: return {index: i, value: el.c[1].v}; n@1228: }); n@1228: n@1228: map.sort(function(a,b){ n@1228: if (a.value > b.value) {return -1;} n@1228: if (a.value < b.value) {return 1;} n@1228: return 0; n@1228: }) n@1228: n@1228: var Jf = []; n@1228: var cc = []; n@1228: for (var i=0; i b.value) {return 1;} n@1228: return 0; n@1228: }) n@1228: n@1228: var Jf = []; n@1228: var cc = []; n@1228: for (var i=0; i