window.states = {}; window.cstats = { numGames: {}, numCompetitors: {}, maxDeviation: {} }; window.yAxisMax = [0, 0]; function formatNum(n) { return n.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,'); } function uniq(a) { var prims = {"boolean":{}, "number":{}, "string":{}}, objs = []; return a.filter(function(item) { var type = typeof item; if(type in prims) return prims[type].hasOwnProperty(item) ? false : (prims[type][item] = true); else return objs.indexOf(item) >= 0 ? false : objs.push(item); }); } function options(start, end, step) { var indVars = []; for(var i=end; i>start; i-=step) { indVars.push(i); } indVars.push(start); indVars = uniq(indVars.reverse()); return indVars; } function nextChart() { var minChart = false; var minFinished = 100000; for(var chart in window.states) { if(window.states.hasOwnProperty(chart)) { if(window.states[chart]['finished'].length < minFinished && window.states[chart]['queue'].length > 0) { minFinished = window.states[chart]['finished'].length; minChart = chart; } } } return minChart; } function finish(chart, indVar, suffix) { if(window.cstats[chart][indVar][3] < window.numCompetitions) { setTimeout(function() { finish(chart, indVar, suffix); }, 1000); } else { var indVar = window.states[chart]['running'].shift(); window.states[chart]['finished'].push(indVar); updateGraph(chart, indVar, suffix); recursiveTraverseQueues(suffix); } } function dequeue(chart) { var indVar = window.states[chart]['queue'].shift(); window.states[chart]['running'].push(indVar); return indVar; } function nextInQueue(chart) { if(window.states[chart]['queue'].length > 0) { return window.states[chart]['queue'][0]; } else { return false; } } function setupCharts(suffix) { var chartOpts = { chart: { backgroundColor: null }, xAxis: [{ title: { text: '', }, //allowDecimals: false, //lineWidth: 0, //lineColor: 'transparent', //gridLineColor: 'transparent', //gridLineWidth: 0, //minorGridLineWidth: 0, //minorGridLineColor: 'transparent', //minorTickLength: 0, //tickLength: 0, //plotLines: [{ // value: 0, // width: 0, // color: '#808080' //}] }], yAxis: [{ //lineWidth: 0, //lineColor: 'transparent', //gridLineColor: 'transparent', //gridLineWidth: 0, //minorGridLineWidth: 0, //minorGridLineColor: 'transparent', //minorTickLength: 0, //tickLength: 0, min: 0, max: 1, maxPadding: 0, minPadding: 0, title: { text: 'Number of Competitions' }, labels: { enabled: true }, //plotLines: [{ // value: 0, // width: 0, // color: '#808080' //}] }, { min: 0, max: 25, maxPadding: 0, minPadding: 0, opposite: true, title: { text: 'Average Rank Percentile' }, labels: { enabled: true }, }], plotOptions: { series: { stickyTracking: false }, line: { marker: { radius: 3, symbol: 'circle' } } }, legend: { enabled: false }, credits: { enabled: false }, exporting: { enabled: false }, series: [{ name: 'Number of First Place Finishes', yAxis: 0, xAxis: 0, data: [], color: '#00b712', },{ name: 'Number of Last Place Finishes', yAxis: 0, xAxis: 0, data: [], color: '#a50008', },{ name: 'Average Percentile', yAxis: 1, xAxis: 0, data: [], color: '#ffaa00', }], title: { style: { fontSize: '14px' } } }; var ngOpts = JSON.parse(JSON.stringify(chartOpts)); ngOpts['title']['text'] = 'Number of Games per Competition'; ngOpts['xAxis'][0]['title']['text'] = 'Number of Games per Competition'; ngOpts['yAxis'][1]['labels']['enabled'] = false; ngOpts['yAxis'][1]['title']['text'] = null; $('#ng-results-container-' + suffix).highcharts(ngOpts); var ncOpts = JSON.parse(JSON.stringify(chartOpts)); ncOpts['title']['text'] = 'Number of Competitors'; ncOpts['xAxis'][0]['title']['text'] = 'Number of Competitors'; ncOpts['yAxis'][0]['labels']['enabled'] = false; ncOpts['yAxis'][1]['labels']['enabled'] = false; ncOpts['yAxis'][0]['title']['text'] = null; ncOpts['yAxis'][1]['title']['text'] = null; $('#nc-results-container-' + suffix).highcharts(ncOpts); var mdOpts = JSON.parse(JSON.stringify(chartOpts)); mdOpts['title']['text'] = 'Max Deviation (Uniform)'; mdOpts['xAxis'][0]['title']['text'] = 'Max Deviation (Uniform)'; mdOpts['yAxis'][0]['labels']['enabled'] = false; mdOpts['yAxis'][0]['title']['text'] = null; $('#md-results-container-' + suffix).highcharts(mdOpts); } function nothingRunning() { for(var chart in window.states) { if(window.states.hasOwnProperty(chart)) { if(window.states[chart]['running'].length > 0) { return false; } } } return true; } function singleCompetition(chart, numGames, numCompetitors, maxDeviation, gameProbs, numLeft) { var competitionStats = [0, 0, 0]; var outcomes = []; for(var j=0; j competitorScores[j]) { rank++; } } competitionStats[0] = rank == 1 ? 1 : 0; competitionStats[1] = rank == numCompetitors ? 1 : 0; competitionStats[2] = (numCompetitors - rank) / numCompetitors; var indVar; switch(chart) { case 'numGames': indVar = numGames; break; case 'numCompetitors': indVar = numCompetitors; break; case 'maxDeviation': indVar = maxDeviation; break; } window.cstats[chart][indVar][0] += competitionStats[0]; window.cstats[chart][indVar][1] += competitionStats[1]; window.cstats[chart][indVar][2] += competitionStats[2]; window.cstats[chart][indVar][3]++; if(numLeft - 1 > 0) { setTimeout(function() { singleCompetition(chart, numGames, numCompetitors, maxDeviation, gameProbs, numLeft-1); }, 1); } } function getGameProbs(numGames) { var gameProbs = []; for(var i=0; i= 0 ? false : objs.push(item); // }); //} // //function singleCompetition(numGames, numCompetitors, maxDeviation, gameProbs) { // var competitionStats = [0, 0, 0]; // // var outcomes = []; // for(var j=0; j competitorScores[j]) { // rank++; // } // } // // competitionStats[0] = rank == 1 ? 1 : 0; // competitionStats[1] = rank == numCompetitors ? 1 : 0; // competitionStats[2] = rank; // // return competitionStats; //} // //function recursiveCompetitions(prefix, numCompetitions, numGames, numCompetitors, maxDeviation, gameProbs, numLeft) { // if(numLeft > 0) { // setTimeout(function() { // var singleStats = singleCompetition(numGames, numCompetitors, gameProbs, maxDeviation); // recursiveCompetitions(prefix, numCompetitions, numGames, numCompetitors, maxDeviation, gameProbs, numLeft-1); // window.cstats[prefix][numCompetitions][numGames][numCompetitors][maxDeviation][0] += singleStats[0]; // window.cstats[prefix][numCompetitions][numGames][numCompetitors][maxDeviation][1] += singleStats[1]; // window.cstats[prefix][numCompetitions][numGames][numCompetitors][maxDeviation][2] += singleStats[2]; // window.cstats[prefix][numCompetitions][numGames][numCompetitors][maxDeviation][3]++; // }, 100); // } //} // //function simulation(numCompetitions, numGames, numCompetitors, maxDeviation, prefix) { // var gameProbs = []; // var competitionStats = [0, 0, 0]; // // for(var i=0; i= idx; // if(previousChartFinished && previousIterationFinished) { // console.log('start'); // console.log(prefix); // console.log(idx); // if(!window.cstats[prefix].hasOwnProperty(numCompetitions)) // window.cstats[prefix][numCompetitions] = {}; // if(!window.cstats[prefix][numCompetitions].hasOwnProperty(numGames)) // window.cstats[prefix][numCompetitions][numGames] = {}; // if(!window.cstats[prefix][numCompetitions][numGames].hasOwnProperty(numCompetitors)) // window.cstats[prefix][numCompetitions][numGames][numCompetitors] = {}; // if(!window.cstats[prefix][numCompetitions][numGames][numCompetitors].hasOwnProperty(maxDeviation)) // window.cstats[prefix][numCompetitions][numGames][numCompetitors][maxDeviation] = [0, 0, 0, 0]; // // simulation(numCompetitions, numGames, numCompetitors, maxDeviation, prefix); // // checkFinished(numCompetitions, numGames, numCompetitors, maxDeviation, prefix, suffix); // } else { // setTimeout(function() { // recursiveSimulation(numCompetitions, numGames, numCompetitors, maxDeviation, prefix, suffix, idx); // }, 10000); // } //} // //function numGamesVaried(suffix, numCompetitions, start, end, step) { // var numCompetitors = 10; // TODO // var maxDeviation = 1; // // var indVars = []; // for(var i=end; i>start; i-=step) { // indVars.push(i); // } // indVars.push(start); // indVars = uniq(indVars.reverse()); // // window.counts['ng'] = 0; // window.iters['ng'] = indVars.length; // // for(var idx=0; idxstart; i-=step) { // indVars.push(i); // } // indVars.push(start); // indVars = uniq(indVars.reverse()); // // window.counts['nc'] = 0; // window.iters['nc'] = indVars.length; // // for(var idx=0; idxstart; i-=step) { // indVars.push(i); // } // indVars.push(start); // indVars = uniq(indVars.reverse()); // // window.counts['md'] = 0; // window.iters['md'] = indVars.length; // // for(var idx=0; idx\u25CF ' + this.series.name + ': ' + this.y + '
'; // } // }, // legend: { // enabled: false // }, // credits: { // enabled: false // }, // exporting: { // enabled: false // }, // series: [{ // name: 'Percent Competitions Won (First Place)', // yAxis: 0, // xAxis: 0, // data: [], // color: '#ff3300', // marker: { // enabled: false // } // },{ // name: 'Percent Competitions Lost (Last Place)', // yAxis: 0, // xAxis: 0, // data: [], // color: '#555', // marker: { // enabled: false // } // },{ // name: 'Average Percentile', // yAxis: 0, // xAxis: 0, // data: [], // color: '#ab1900', // marker: { // enabled: false // } // }] // }; // // chartOpts['title'] = { text: 'Number of Games per Competition' }; // $('#ng-results-container-' + suffix).highcharts(chartOpts); // chartOpts['title'] = { text: 'Number of Competitors' }; // $('#nc-results-container-' + suffix).highcharts(chartOpts); // chartOpts['title'] = { text: 'Max Deviation (Uniform)' }; // $('#md-results-container-' + suffix).highcharts(chartOpts); // // setTimeout(function() { // numGamesVaried(suffix, numCompetitions, numGamesStart, numGamesEnd, numGamesStep); // setTimeout(function() { // numCompetitorsVaried(suffix, numCompetitions, numCompetitorsStart, numCompetitorsEnd, numCompetitorsStep); // setTimeout(function() { // maxDeviationVaried(suffix, numCompetitions, maxDeviationStart, maxDeviationEnd, maxDeviationStep); // }, 3000); // }, 3000); // }, 3000); //}