Skip to content

Commit

Permalink
Add compare script
Browse files Browse the repository at this point in the history
  • Loading branch information
EFHIII committed May 21, 2021
1 parent e7c12fd commit ad57ea7
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 3 deletions.
80 changes: 80 additions & 0 deletions code/compare.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
const names = ['random', 'titForTat'];
const COLSIZE = 30;

const data = require('./results.json');

for (let i in data) {
data[i].nameA = data[i].nameA.replace(/[a-zA-Z0-9]+\./, '');
data[i].nameB = data[i].nameB.replace(/[a-zA-Z0-9]+\./, '');
}

function standardDeviation(a) {
let mean = 0;
a.map(a => mean += a);
mean /= a.length;

let sum = 0;
for (let val of a) {
sum += (val - mean) * (val - mean);
}
return Math.sqrt(1 / a.length * sum);
}

function compare(data, names) {
let relevant = [];
let participants = [];
let participantStuff = {};
for (let i in data) {
if (names.indexOf(data[i].nameA) >= 0) {
relevant.push(data[i]);
if (participants.indexOf(data[i].nameB) < 0) {
participants.push(data[i].nameB);
participantStuff[data[i].nameB] = {};
}
participantStuff[data[i].nameB][data[i].nameA]=data[i].avgScoreA;
}
if (names.indexOf(data[i].nameB) >= 0) {
relevant.push(data[i]);
if (participants.indexOf(data[i].nameA) < 0) {
participants.push(data[i].nameA);
participantStuff[data[i].nameA] = {};
}
participantStuff[data[i].nameA][data[i].nameB]=data[i].avgScoreB;
}
}

for(let i in names){
//participants.splice(participants.indexOf(names[i]),1);
}

function mapParticipants(a) {
let ar = [];
for(let v in participantStuff[a]){
ar.push(participantStuff[a][v]);
}
return [a, standardDeviation(ar)];
}

participants = participants.map(mapParticipants).sort((a, b) => b[1] - a[1]).map(a => a[0]);

console.log(participantStuff);

let t1 = "Opponent ".padStart(COLSIZE);
let t2 = "---------".padStart(COLSIZE,'-');

for(let n in names){
t1 += "|"+names[n].padEnd(COLSIZE);
t2 += "+"+"".padEnd(COLSIZE,"-");
}

console.log(`${t1}\n${t2}`);
for(let i in participants){
let t = '';
for(let n in names){
t += ("| "+Math.round(participantStuff[participants[i]][names[n]]*1000)/1000).padEnd(COLSIZE+1);
}
console.log(`${(''+participants[i]).padEnd(COLSIZE)}${t}`);
}
}

compare(data, names)
6 changes: 3 additions & 3 deletions code/print.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require("fs");

let view = ['edward'];
let view = ['jed'];

fs.readFile('./results.txt', 'utf8', (err, data) => {
if (err) throw err;
Expand All @@ -12,7 +12,7 @@ function run(txt){
let ans = txt.split('\n');
for(let i=0;i<ans.length;i++){
if(ans[i].indexOf('SCORES')>0){scores=true;}
ans[i]=ans[i].replace(/(?!VS\.|\S\.)[a-zA-Z]+\./g,'');
ans[i]=ans[i].replace(/(?!VS\.|\S\.)[a-zA-Z0-9]+\./g,'');
if(ans[i][0] === 'C' || ans[i][0] === 'D'){
let t = ans[i].split(' ');
let tt='';
Expand Down Expand Up @@ -52,7 +52,7 @@ function run(txt){
if(scores && ans[i].indexOf(':')>0){
q=ans[i].slice(0,4);
ans[i]=ans[i].slice(4).replace(/ /g,'');
ans[i]=q+ans[i].replace(':',''.padEnd(20-ans[i].indexOf(':'),' '));
ans[i]=q+ans[i].replace(':',''.padEnd(26-ans[i].indexOf(':'),' '));
ans[i]=ans[i].replace('average',' average');
ans[i]=ans[i].replace('(',' (');
}
Expand Down

0 comments on commit ad57ea7

Please sign in to comment.