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@1227: this.handleEvent = function() {
n@1227: // Only used to handle the chart.event.addListener(this,'ready') callback
n@1227: this.downloadDOM.innerHTML = 'Download';
n@1227: }
n@1227:
n@1227: this.root.appendChild(this.chartDOM);
n@1227: this.root.appendChild(this.tableDOM);
n@1227: this.root.appendChild(this.latexDOM);
n@1227: this.root.appendChild(this.print);
n@1227: this.print.textContent = "Download";
n@1227: this.print.addEventListener("click",this);
n@1227: this.root.appendChild(this.downloadDOM);
n@1227: this.buildTable = function() {
n@1227: var table = document.createElement("table");
n@1227: table.border = "1";
n@1227: for (var rowIndex=0; rowIndex