Skip to content

Instantly share code, notes, and snippets.

@mstan
Created Nov 25, 2017
Embed
What would you like to do?
var _heroes = {
"Doomfist": 0,
"Genji": 0,
"McCree": 0,
"Pharah": 0,
"Reaper": 0,
"Soldier 76": 0,
"Tracer": 0,
"Sombra": 0,
"Bastion": 0,
"Hanzo": 0,
"Junkrat": 0,
"Mei": 0,
"Torbjorn": 0,
"Widowmaker": 0,
"Dva": 0,
"Reinhardt": 0,
"Roadhog": 0,
"Winston": 0,
"Orisa": 0,
"Zarya": 0,
"Ana": 0,
"Mercy": 0,
"Symmetra": 0,
"Moira": 0,
"Zenyatta": 0,
"Lucio": 0
}
var _maps = {
"Anubis" : 0,
"Dorado": 0,
"Eichenwalde": 0,
"Gibraltr": 0,
"Hanamura": 0,
"Hollywood": 0,
"Ilios": 0,
"Lijiang": 0,
"Horizon": 0,
"Junkertown": 0,
"King's Row": 0,
"Nepal": 0,
"Numbani": 0,
"Oasis": 0,
"Route 66": 0,
"Volskaya": 0
}
var _modes = {
"2CP": 0,
"Hybrid": 0,
"KOTH": 0,
"Payload": 0
}
var _mapModes = {
"Anubis" : "2CP",
"Dorado": "Payload",
"Eichenwalde": "Hybrid",
"Gibraltr": "Payload",
"Hanamura": "2CP",
"Hollywood": "2CP",
"Horizon": "2CP",
"Ilios": "KOTH",
"Lijiang": "KOTH",
"Junkertown": "Payload",
"King's Row": "Hybrid",
"Nepal": "KOTH",
"Numbani": "Hybrid",
"Oasis": "KOTH",
"Route 66": "Payload",
"Volskaya": "2CP"
}
/**************************************************************
STAT AND SR VALUES
***************************************************************/
function GETSR(scores) {
var gained = 0;
var lost = 0;
var wins = 0;
var losses = 0;
var draws = 0;
for(var i = 0; i < scores.length; i++) {
if(scores[i] > 0) {
gained += parseInt(scores[i]);
wins +=1
} else if(scores[i] < 0) {
lost += parseInt(scores[i]);
losses +=1;
} else if(parseInt(scores[i]) === 0) {
draws += 1;
}
}
var total = wins + losses + draws;
response = [];
response.push(['Total', 'Wins', 'Losses', 'Draws', 'Winrate']);
var _winrate = ( ( wins / (total - draws) ) * 100 ).toFixed(2) + "%" ;
response.push([total, wins, losses, draws, _winrate]);
response.push(['SR Gain', 'SR Loss', 'Net SR Gain', 'Net Avg SR Gain'])
var _netSR = gained + lost;
var _avgNetSR = ((gained + lost) / total).toFixed(2);
response.push([gained, lost, _netSR, _avgNetSR]);
response.push(['Avg Gain', 'Avg Loss']);
var _avgGain = (gained / wins).toFixed(2);
var _avgLoss = (lost / losses).toFixed(2);
response.push([_avgGain, _avgLoss]);
return response;
}
/**************************************************************
END STAT AND SR VALUES
***************************************************************/
/**************************************************************
BY HERO
***************************************************************/
function GETHEROSTATS(names,scores) {
var heroesTotal = JSON.parse(JSON.stringify(_heroes));
var heroesTotalAdj = JSON.parse(JSON.stringify(_heroes));
var heroesWins = JSON.parse(JSON.stringify(_heroes));
var heroesWinsAdj = JSON.parse(JSON.stringify(_heroes));
var heroesLosses = JSON.parse(JSON.stringify(_heroes));
var heroesLossesAdj = JSON.parse(JSON.stringify(_heroes));
var heroesTotalGain = JSON.parse(JSON.stringify(_heroes));
var heroesTotalGainAdj= JSON.parse(JSON.stringify(_heroes));
var heroesTotalLoss = JSON.parse(JSON.stringify(_heroes));
var heroesTotalLossAdj= JSON.parse(JSON.stringify(_heroes));
var heroesHighestGain = JSON.parse(JSON.stringify(_heroes));
var heroesHighestGainAdj = JSON.parse(JSON.stringify(_heroes));
var heroesHighestLoss = JSON.parse(JSON.stringify(_heroes));
var heroesHighestLossAdj = JSON.parse(JSON.stringify(_heroes));
for(var i = 0; i < names.length; i++) {
names[i].toString().split(',').forEach(function(name) {
heroesTotal[name] += 1;
heroesTotalAdj[name] += (1 / names[i].toString().split(',').length);
if(parseInt(scores[i]) > 0) {
heroesWins[name] += 1;
heroesWinsAdj[name] += ( 1 / names[i].toString().split(',').length);
heroesTotalGain[name] += parseInt(scores[i]);
heroesTotalGainAdj[name] += parseInt(scores[i]) * ( 1 / names[i].toString().split(',').length);
if(parseInt(scores[i]) > heroesHighestGain[name]) {
heroesHighestGain[name] = parseInt(scores[i]);
}
} else if(parseInt(scores[i]) < 0) {
heroesLosses[name] += 1;
heroesLossesAdj[name] += ( 1 / names[i].toString().split(',').length);
heroesTotalLoss[name] += parseInt(scores[i]);
heroesTotalLossAdj[name] += parseInt(scores[i]) * ( 1 / names[i].toString().split(',').length);
if(parseInt(scores[i]) < heroesHighestGain[name]) {
heroesHighestLoss[name] = parseInt(scores[i]);
}
}
});
}
var response = [];
response.push([
'Heroes',
'Games','Games Adj.',
'Winrate', 'Winrate Adj.', 'Break-Even Winrate',
'Total Wins', 'Total Wins Adj',
'Total Losses', 'Total Losses Adj',
'Net Gain', 'Net GainAdj', 'Avg Net Gain Per Game', 'Avg Net Gain Per Game Adj',
'Total Point Gain',
'Total Point Loss', 'Total Point Loss Adj',
'Highest Point Gain', 'Avg Point Gain Per Win',
'Highest Point Loss', 'Avg Point Loss Per Loss',
'Avg Gain Per Match Adj']);
for(hero in _heroes) {
var tempArr = []
tempArr.push(hero);
var _heroesTotal = heroesTotal[hero];
var _heroesTotalAdj = heroesTotalAdj[hero].toFixed(2);
var _winrate = ( ( heroesWins[hero] / heroesTotal[hero]) * 100).toFixed(2) + '%';
var _winrateAdj = ( ( heroesWinsAdj[hero] / heroesTotalAdj[hero]) * 100).toFixed(2) + '%';
var _breakEvenWinrateAdj = ( ( ( ( (heroesTotalLoss[hero] / heroesLosses[hero] ) * -1) / (heroesTotalGain[hero] / heroesWins[hero]) ) * .5) * 100 ).toFixed(2) + '%' ;
var _heroWins = heroesWins[hero]
var _heroWinsAdj = heroesWinsAdj[hero].toFixed(2);
var _heroLosses = heroesLosses[hero];
var _heroLossesAdj = heroesLossesAdj[hero].toFixed(2);
var _heroNetGain = heroesTotalGain[hero] + heroesTotalLoss[hero];
var _heroNetGainAdj = (heroesTotalGainAdj[hero] + heroesTotalLossAdj[hero]).toFixed(2);
var _heroAvgNetGain = (_heroNetGain / _heroesTotal).toFixed(2);
var _heroAvgNetGainAdj = (_heroNetGain / _heroesTotalAdj).toFixed(2);
//Total Games
tempArr.push(_heroesTotal);
tempArr.push(_heroesTotalAdj);
// Winrates
tempArr.push(_winrate);
tempArr.push(_winrateAdj);
tempArr.push(_breakEvenWinrateAdj);
//Total Wins
tempArr.push(_heroWins);
tempArr.push(_heroWinsAdj);
// Losses
tempArr.push(_heroLosses);
tempArr.push(_heroLossesAdj);
tempArr.push(_heroNetGain); // Net Gain
tempArr.push(_heroNetGainAdj); //Net Adj Gain
tempArr.push(_heroAvgNetGain); // Avg Net Gain Per Game
tempArr.push(_heroAvgNetGainAdj); // Avg Adj Net Gain Per Game
tempArr.push(heroesTotalGain[hero]); //Total Gain
tempArr.push(heroesTotalLoss[hero]); //Total Loss
tempArr.push( (heroesTotalLoss[hero] / heroesTotalAdj[hero]).toFixed(2) ); //Total Adj Loss
tempArr.push(heroesHighestGain[hero]); //Highest Gain
tempArr.push( (heroesTotalGain[hero] / heroesWins[hero]).toFixed(2) ); //Avg Gain Per Win
tempArr.push(heroesHighestLoss[hero]); // Highest Loss
tempArr.push( (heroesTotalLoss[hero] / heroesLosses[hero]).toFixed(2) ); //Avg Loss Per Loss
tempArr.push( ( ( ( (heroesTotalGain[hero] + heroesTotalLoss[hero]) / heroesTotal[hero] ) / heroesTotal[hero] ) / heroesTotalAdj[hero] ).toFixed(2) ); // Avg Adj Net Gain Per Game
response.push(tempArr);
}
return response;
}
/**************************************************************
END BY HERO
***************************************************************/
/**************************************************************
BY GAME MODE
***************************************************************/
function GETGAMEMODESTATS(maps,scores,heroes) {
var totalGames = JSON.parse(JSON.stringify(_modes));
var totalWins = JSON.parse(JSON.stringify(_modes));
var totalLosses = JSON.parse(JSON.stringify(_modes));
var totalPointGains = JSON.parse(JSON.stringify(_modes));
var totalPointLosses = JSON.parse(JSON.stringify(_modes));
var highestGains = JSON.parse(JSON.stringify(_modes));
var highestLosses = JSON.parse(JSON.stringify(_modes));
for(var i = 0; i < maps.length; i++) {
totalGames[_mapModes[maps[i]]] += 1;
if(scores[i] > 0) {
totalWins[_mapModes[maps[i]]] += 1;
totalPointGains[_mapModes[maps[i]]] += parseInt(scores[i]);
if(parseInt(scores[i]) > highestGains[_mapModes[maps[i]]]) {
highestGains[_mapModes[maps[i]]] = parseInt(scores[i]);
}
} else if(parseInt(scores[i]) < 0) {
totalLosses[_mapModes[maps[i]]] += 1;
totalPointLosses[_mapModes[maps[i]]] += parseInt(scores[i]);
if(parseInt(scores[i]) < highestLosses[_mapModes[maps[i]]]) {
highestLosses[_mapModes[maps[i]]] = parseInt(scores[i]);
}
}
}
var response = [];
response.push([
'Mode', 'Games',
'Wins', 'Losses',
'Winrate',
'Net Gain', 'Avg Net Gain',
'Total Gains', 'Total Losses',
'Highest Gain', 'Highest Loss'
]);
for(mode in _modes) {
var tempArr = [];
var _winrate = ( ( totalWins[mode] / totalGames[mode]) * 100 ).toFixed(2) + '%';
var _netGain = totalPointGains[mode] + totalPointLosses[mode];
var _avgNetGain = ( (totalPointGains[mode] + totalPointLosses[mode]) / totalGames[mode]).toFixed(2);
tempArr.push(mode);
tempArr.push(totalGames[mode]);
tempArr.push(totalWins[mode]);
tempArr.push(totalLosses[mode]);
tempArr.push(_winrate);
tempArr.push(_netGain);
tempArr.push(_avgNetGain);
tempArr.push(totalPointGains[mode]);
tempArr.push(totalPointLosses[mode]);
tempArr.push(highestGains[mode]);
tempArr.push(highestLosses[mode]);
response.push(tempArr);
}
return response;
}
/**************************************************************
END GAME MODE
***************************************************************/
/**************************************************************
BY MAP
***************************************************************/
function GETMAPSTATS(maps,scores,heroes) {
var mapsPlayed = JSON.parse(JSON.stringify(_maps));
var mapsWon = JSON.parse(JSON.stringify(_maps));
var mapsLost = JSON.parse(JSON.stringify(_maps));
var mapsTotalGain = JSON.parse(JSON.stringify(_maps));
var mapsTotalLoss = JSON.parse(JSON.stringify(_maps));
var mapsHighestGain = JSON.parse(JSON.stringify(_maps));
var mapsHighestLoss = JSON.parse(JSON.stringify(_maps));
var mapsBestHero = JSON.parse(JSON.stringify(_maps));
for(map in mapsBestHero) {
mapsBestHero[map] = JSON.parse(JSON.stringify(_heroes));;
}
for(var i = 0; i < maps.length; i++) {
mapsPlayed[maps[i]] += 1;
if(scores[i] > 0) {
mapsWon[maps[i]] += 1;
mapsTotalGain[maps[i]] += parseInt(scores[i]);
heroes[i].toString().split(',').forEach(function(hero) {
mapsBestHero[maps[i]][hero] += 1;
});
if(scores[i] > mapsHighestGain[maps[i]]) {
mapsHighestGain[maps[i]] += parseInt(scores[i]);
}
} else if(scores[i] < 0) {
mapsLost[maps[i]] += 1;
mapsTotalLoss[maps[i]] += parseInt(scores[i]);
heroes[i].toString().split(',').forEach(function(hero) {
mapsBestHero[maps[i]][hero] -= 1;
});
if(scores[i] < parseInt(mapsHighestLoss[maps[i]])) {
mapsHighestLoss[maps[i]] = parseInt(scores[i]);
}
}
}
var response = [];
response.push([
'Maps', 'Mode',
'Times Played', 'Times Won', 'Times Lost',
'Winrate', 'Total Net Gain', 'Avg Net Gain',
'Total Gain', 'Total Loss',
'Avg Gain', 'Avg Loss',
'Highest Gain', 'Highest Loss',
'Best Heroes', 'Worst Heroes'
]);
for(map in _maps) {
var tempArr = [];
tempArr.push(map);
tempArr.push(_mapModes[map]);
var _winrate = ( (mapsWon[map] / mapsPlayed[map]) * 100).toFixed(2) + '%' ;
var _netGain = mapsTotalGain[map] + mapsTotalLoss[map];
var _avgNetGain = ((mapsTotalGain[map] + mapsTotalLoss[map]) / mapsPlayed[map]).toFixed(2);
var _avgGain = (mapsTotalGain[map] / mapsPlayed[map]).toFixed(2);
var _avgLoss = (mapsTotalLoss[map] / mapsPlayed[map]).toFixed(2);
tempArr.push(mapsPlayed[map]);
tempArr.push(mapsWon[map]);
tempArr.push(mapsLost[map]);
tempArr.push(_winrate);
tempArr.push(_netGain);
tempArr.push(_avgNetGain);
tempArr.push(mapsTotalGain[map]);
tempArr.push(mapsTotalLoss[map]);
tempArr.push(_avgGain);
tempArr.push(_avgLoss);
tempArr.push(mapsHighestGain[map]);
tempArr.push(mapsHighestLoss[map]);
//Determing the best heroes and worst heroes
var bestHeroes = '';
var worstHeroes = '';
var highest = 0;
var lowest = 0;
for(hero in mapsBestHero[map]) {
if (mapsBestHero[map][hero] > highest) {
highest = mapsBestHero[map][hero];
bestHeroes = hero;
} else if (mapsBestHero[map][hero] == highest && highest != 0) {
bestHeroes += ',' + hero;
} else if (mapsBestHero[map][hero] < lowest) {
lowest = mapsBestHero[map][hero];
worstHeroes = hero;
} else if (mapsBestHero[map][hero] == lowest && lowest != 0) {
worstHeroes += ',' + hero;
}
}
tempArr.push(bestHeroes);
tempArr.push(worstHeroes);
response.push(tempArr);
}
return response;
}
/**************************************************************
END BY MAP
***************************************************************/
/**************************************************************
BY HERO BY MAP
***************************************************************/
function GETMAPSTATSBYHERO(maps,scores,heroes) {
var totalGames = JSON.parse(JSON.stringify(_maps));
for(map in totalGames) {
totalGames[map] = JSON.parse(JSON.stringify(_heroes));
}
var totalGamesAdj = JSON.parse(JSON.stringify(_maps));
for(map in totalGamesAdj) {
totalGamesAdj[map] = JSON.parse(JSON.stringify(_heroes));;
}
var totalWins = JSON.parse(JSON.stringify(_maps));
for(map in totalWins) {
totalWins[map] = JSON.parse(JSON.stringify(_heroes));;
}
var totalWinsAdj = JSON.parse(JSON.stringify(_maps));
for(map in totalWinsAdj) {
totalWinsAdj[map] = JSON.parse(JSON.stringify(_heroes));;
}
var totalGains = JSON.parse(JSON.stringify(_maps));
for(map in totalGains) {
totalGains[map] = JSON.parse(JSON.stringify(_heroes));;
}
var totalGainsAdj = JSON.parse(JSON.stringify(_maps));
for(map in totalGainsAdj) {
totalGainsAdj[map] = JSON.parse(JSON.stringify(_heroes));;
}
var totalLosses = JSON.parse(JSON.stringify(_maps));
for(map in totalLosses) {
totalLosses[map] = JSON.parse(JSON.stringify(_heroes));;
}
var totalLossesAdj = JSON.parse(JSON.stringify(_maps));
for(map in totalLossesAdj) {
totalLossesAdj[map] = JSON.parse(JSON.stringify(_heroes));;
}
var totalPointGains = JSON.parse(JSON.stringify(_maps));
for(map in totalPointGains) {
totalPointGains[map] = JSON.parse(JSON.stringify(_heroes));;
}
var totalPointGainsAdj = JSON.parse(JSON.stringify(_maps));
for(map in totalPointGainsAdj) {
totalPointGainsAdj[map] = JSON.parse(JSON.stringify(_heroes));;
}
var totalPointLosses = JSON.parse(JSON.stringify(_maps));
for(map in totalPointLosses) {
totalPointLosses[map] = JSON.parse(JSON.stringify(_heroes));;
}
var totalPointLossesAdj = JSON.parse(JSON.stringify(_maps));
for(map in totalPointLossesAdj) {
totalPointLossesAdj[map] = JSON.parse(JSON.stringify(_heroes));;
}
var highestGain = JSON.parse(JSON.stringify(_maps));
for(map in highestGain) {
highestGain[map] = JSON.parse(JSON.stringify(_heroes));;
}
var highestLoss = JSON.parse(JSON.stringify(_maps));
for(map in highestLoss) {
highestLoss[map] = JSON.parse(JSON.stringify(_heroes));;
}
for(var i = 0; i < maps.length; i++) {
heroes[i].toString().split(',').forEach(function(hero) {
if(!!hero && hero.length > 0) {
totalGames[maps[i]][hero] += 1;
totalGamesAdj[maps[i]][hero] += (1 / heroes[i].toString().split(',').length );
if(scores[i] > 0) {
totalWins[maps[i]][hero] += 1;
totalWinsAdj[maps[i]][hero] += (1 / heroes[i].toString().split(',').length );
totalPointGains[maps[i]][hero] += parseInt(scores[i]);
totalPointGainsAdj[maps[i]][hero] += parseInt(scores[i]) * (1 / heroes[i].toString().split(',').length);
if(scores[i] > highestGain[maps[i]][hero]) {
highestGain[maps[i]][hero] = parseInt(scores[i]);
}
} else if(parseInt(scores[i]) < 0) {
totalLosses[maps[i]][hero] +=1;
totalLossesAdj[maps[i]][hero] += (1 / heroes[i].toString().split(',').length );
totalPointLosses[maps[i]][hero] += parseInt(scores[i]);
totalPointLossesAdj[maps[i]][hero] += (parseInt(scores[i]) * (1 / heroes[i].toString().split(',').length) );
if(scores[i] < highestLoss[maps[i]][hero]) {
highestLoss[maps[i]][hero] = parseInt(scores[i]);
}
}
}
});
}
var response = [];
response.push([
'Maps', 'Hero',
'Matches', 'Times Played Adj',
'Wins', 'Wins Adj',
'Losses', 'Losses Adj',
'Winrate', 'Adj Winrate',
'B/E Winrate','Net Gain', 'Net Gain Adj',
'Total Point Gain', 'Total Point Gain Adj', 'Total Point Losses', 'Total Point Losses Adj',
'Highest Gain', 'Highest Loss'
]);
for(map in _maps) {
response.push([map]);
for(hero in _heroes) {
var tempArr = [];
tempArr.push('',hero); //push empty string for first element to "indent"
var _winrate = ( (totalWins[map][hero] / totalGames[map][hero]) * 100).toFixed(2) + '%';
var _winrateAdj = ( (totalWinsAdj[map][hero] / totalGamesAdj[map][hero]) * 100).toFixed(2) + '%';
var _breakEvenWinrate = ( ( ( ( ( totalPointLosses[map][hero] / totalLosses[map][hero] ) * -1) / (totalPointGains[map][hero] / totalWins[map][hero]) ) * .5) * 100 ).toFixed(2) + '%' ;
var _netGain = totalPointGains[map][hero] + totalPointLosses[map][hero];
var _netGainAdj = (totalPointGainsAdj[map][hero] + totalPointLossesAdj[map][hero]).toFixed(2);
var _totalGain = totalPointGains[map][hero];
var _totalGainAdj = (totalPointGainsAdj[map][hero]).toFixed(2);
var _totalLoss = totalPointLosses[map][hero];
var _totalLossAdj = (totalPointLossesAdj[map][hero]).toFixed(2);
var _highestGain = highestGain[map][hero];
var _highestLoss = highestLoss[map][hero];
tempArr.push(totalGames[map][hero]);
tempArr.push((totalGamesAdj[map][hero]).toFixed(2));
tempArr.push(totalWins[map][hero]);
tempArr.push((totalWinsAdj[map][hero]).toFixed(2));
tempArr.push(totalLosses[map][hero]);
tempArr.push((totalLossesAdj[map][hero]).toFixed(2));
tempArr.push(_winrate);
tempArr.push(_winrateAdj);
tempArr.push(_breakEvenWinrate);
tempArr.push(_netGain);
tempArr.push(_netGainAdj);
tempArr.push(_totalGain);
tempArr.push(_totalGainAdj)
tempArr.push(_totalLoss);
tempArr.push(_totalLossAdj);
tempArr.push(_highestGain);
tempArr.push(_highestLoss);
response.push(tempArr);
}
response.push([]); // line break
}
return response;
}
/**************************************************************
END BY HERO BY MAP
***************************************************************/
/**************************************************************
MISCELLANEOUS
***************************************************************/
function GETCURRENTSR(input) {
var arr = input;
var value = 0;
arr.forEach(function(item) {
if(item > 0) {
value = item;
}
});
return value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment