Skip to content

Commit

Permalink
removed non-working line graph from /stats pages and cleaned up the g…
Browse files Browse the repository at this point in the history
…et data script
  • Loading branch information
cozuya committed Jul 5, 2020
1 parent cdfbc40 commit 42c7503
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 106 deletions.
104 changes: 39 additions & 65 deletions public/scripts/charts-season.js
Expand Up @@ -13,120 +13,94 @@ document.addEventListener('DOMContentLoaded', function(event) {

$.ajax({
url: 'data',
success: function(data) {
new Chartist.Line('#chart-completed-games', {
labels: data.completedGames.labels,
series: [data.completedGames.series]
success: function(d) {
new Chartist.Pie('#chart-allplayer-games-winrate', processWinrateData(data.allPlayerGameData.fascistWinCount, data.allPlayerGameData.totalGameCount), {
width: '400px',
height: '400px'
});

setTimeout(() => {
const { labels } = data.completedGames;
const $labels = $('#chart-completed-games .ct-label.ct-horizontal');
const showingLabelIndexes = [0, Math.round(labels.length / 4), Math.round(labels.length / 2), Math.round(labels.length / 1.5), labels.length - 1];
const $shownlabels = $labels.filter(index => showingLabelIndexes.includes(index));

$shownlabels.show(); // barf
}, 500);

new Chartist.Pie(
'#chart-allplayer-games-winrate',
processWinrateData(data.allPlayerGameData.fascistWinCountSeason, data.allPlayerGameData.totalGameCountSeason),
{
width: '400px',
height: '400px'
}
$('#chart-allplayer-games-winrate').after(
`<p style="text-align: center">Total games played: ${data.allPlayerGameData.totalGameCount.toLocaleString()}</p>`
);

$('#chart-allplayer-games-winrate').after(`<p style="text-align: center">Total games played: ${data.allPlayerGameData.totalGameCountSeason}</p>`);

new Chartist.Pie(
'#chart-fiveplayer-games-winrate',
processWinrateData(data.fivePlayerGameData.fascistWinCountSeason, data.fivePlayerGameData.totalGameCountSeason),
{
width: '400px',
height: '400px'
}
);
new Chartist.Pie('#chart-fiveplayer-games-winrate', processWinrateData(data.fivePlayerGameData.fascistWinCount, data.fivePlayerGameData.totalGameCount), {
width: '400px',
height: '400px'
});

$('#chart-fiveplayer-games-winrate').after(
`<p style="text-align: center">Total 5 player games played: ${data.fivePlayerGameData.totalGameCountSeason} | Percentage of Fascists in game: <span style="color: red; font-weight: bold">40%</span></p>`
`<p style="text-align: center">Total 5 player games played: ${data.fivePlayerGameData.totalGameCount.toLocaleString()} | Percentage of Fascists in game: <span style="color: red; font-weight: bold">40%</span></p>`
);

new Chartist.Pie(
'#chart-sixplayer-games-winrate',
processWinrateData(data.sixPlayerGameData.fascistWinCountSeason, data.sixPlayerGameData.totalGameCountSeason),
{
width: '400px',
height: '400px'
}
);
new Chartist.Pie('#chart-sixplayer-games-winrate', processWinrateData(data.sixPlayerGameData.fascistWinCount, data.sixPlayerGameData.totalGameCount), {
width: '400px',
height: '400px'
});

$('#chart-sixplayer-games-winrate').after(
`<p style="text-align: center">Total 6 player games played: ${data.sixPlayerGameData.totalGameCountSeason} | Percentage of Fascists in game: <span style="color: red; font-weight: bold">33%</span></p><h2 class="ui header centered">Winrate for 6 player games (rebalanced)</h2><div class="chart" id="chart-sixplayer-rebalanced-games-winrate"></div><p style="text-align: center">Total 6 player rebalanced games played: ${data.sixPlayerGameData.rebalancedTotalGameCountSeason} | Percentage of Fascists in game: <span style="color: red; font-weight: bold">33%</span></p>`
`<p style="text-align: center">Total 6 player games played: ${data.sixPlayerGameData.totalGameCount.toLocaleString()} | Percentage of Fascists in game: <span style="color: red; font-weight: bold">33%</span></p><h2 class="ui header centered">Winrate for 6 player games (rebalanced)</h2><div class="chart" id="chart-sixplayer-rebalanced-games-winrate"></div><p style="text-align: center">Total 6 player rebalanced games played: ${
data.sixPlayerGameData.rebalancedTotalGameCount
} | Percentage of Fascists in game: <span style="color: red; font-weight: bold">33%</span></p>`
);

new Chartist.Pie(
'#chart-sixplayer-rebalanced-games-winrate',
processWinrateData(data.sixPlayerGameData.rebalancedFascistWinCountSeason, data.sixPlayerGameData.rebalancedTotalGameCountSeason),
processWinrateData(data.sixPlayerGameData.rebalancedFascistWinCount, data.sixPlayerGameData.rebalancedTotalGameCount),
{ width: '400px', height: '400px' }
);

new Chartist.Pie(
'#chart-sevenplayer-games-winrate',
processWinrateData(data.sevenPlayerGameData.fascistWinCountSeason, data.sevenPlayerGameData.totalGameCountSeason),
processWinrateData(data.sevenPlayerGameData.fascistWinCount, data.sevenPlayerGameData.totalGameCount),
{ width: '400px', height: '400px' }
);

$('#chart-sevenplayer-games-winrate').after(
`<p style="text-align: center">Total 7 player games played: ${data.sevenPlayerGameData.totalGameCountSeason} | Percentage of Fascists in game: <span style="color: red; font-weight: bold">43%</span></p><h2 class="ui header centered">Winrate for 7 player games (rebalanced)</h2><div class="chart" id="chart-sevenplayer-rebalanced-games-winrate"></div><p style="text-align: center">Total 7 player rebalanced games played: ${data.sevenPlayerGameData.rebalancedTotalGameCountSeason} | Percentage of Fascists in game: <span style="color: red; font-weight: bold">43%</span></p>`
`<p style="text-align: center">Total 7 player games played: ${data.sevenPlayerGameData.totalGameCount.toLocaleString()} | Percentage of Fascists in game: <span style="color: red; font-weight: bold">43%</span></p><h2 class="ui header centered">Winrate for 7 player games (rebalanced)</h2><div class="chart" id="chart-sevenplayer-rebalanced-games-winrate"></div><p style="text-align: center">Total 7 player rebalanced games played: ${
data.sevenPlayerGameData.rebalancedTotalGameCount
} | Percentage of Fascists in game: <span style="color: red; font-weight: bold">43%</span></p>`
);

new Chartist.Pie(
'#chart-sevenplayer-rebalanced-games-winrate',
processWinrateData(data.sevenPlayerGameData.rebalancedFascistWinCountSeason, data.sevenPlayerGameData.rebalancedTotalGameCountSeason),
processWinrateData(data.sevenPlayerGameData.rebalancedFascistWinCount, data.sevenPlayerGameData.rebalancedTotalGameCount),
{ width: '400px', height: '400px' }
);

new Chartist.Pie(
'#chart-eightplayer-games-winrate',
processWinrateData(data.eightPlayerGameData.fascistWinCountSeason, data.eightPlayerGameData.totalGameCountSeason),
processWinrateData(data.eightPlayerGameData.fascistWinCount, data.eightPlayerGameData.totalGameCount),
{ width: '400px', height: '400px' }
);

$('#chart-eightplayer-games-winrate').after(
`<p style="text-align: center">Total 8 player games played: ${data.eightPlayerGameData.totalGameCountSeason} | Percentage of Fascists in game: <span style="color: red; font-weight: bold">38%</span></p>`
`<p style="text-align: center">Total 8 player games played: ${data.eightPlayerGameData.totalGameCount.toLocaleString()} | Percentage of Fascists in game: <span style="color: red; font-weight: bold">38%</span></p>`
);

new Chartist.Pie(
'#chart-nineplayer-games-winrate',
processWinrateData(data.ninePlayerGameData.fascistWinCountSeason, data.ninePlayerGameData.totalGameCountSeason),
{
width: '400px',
height: '400px'
}
);
new Chartist.Pie('#chart-nineplayer-games-winrate', processWinrateData(data.ninePlayerGameData.fascistWinCount, data.ninePlayerGameData.totalGameCount), {
width: '400px',
height: '400px'
});

$('#chart-nineplayer-games-winrate').after(
`<p style="text-align: center">Total 9 player games played: ${data.ninePlayerGameData.totalGameCountSeason} | Percentage of Fascists in game: <span style="color: red; font-weight: bold">44%</span></p><h2 class="ui header centered">Winrate for 9 player games (rebalanced)</h2><div class="chart" id="chart-nineplayer-rebalanced-games-winrate"></div><p style="text-align: center">Total 9 player rebalanced games played: ${data.ninePlayerGameData.rebalanced2fFascistWinCountSeason} | Percentage of Fascists in game: <span style="color: red; font-weight: bold">44%</span></p>`
`<p style="text-align: center">Total 9 player games played: ${data.ninePlayerGameData.totalGameCount.toLocaleString()} | Percentage of Fascists in game: <span style="color: red; font-weight: bold">44%</span></p><h2 class="ui header centered">Winrate for 9 player games (rebalanced)</h2><div class="chart" id="chart-nineplayer-rebalanced-games-winrate"></div><p style="text-align: center">Total 9 player rebalanced games played: ${
data.ninePlayerGameData.rebalanced2fFascistWinCount
} | Percentage of Fascists in game: <span style="color: red; font-weight: bold">44%</span></p>`
);

new Chartist.Pie(
'#chart-nineplayer-rebalanced-games-winrate',
processWinrateData(data.ninePlayerGameData.rebalanced2fFascistWinCountSeason, data.ninePlayerGameData.rebalanced2fTotalGameCountSeason),
processWinrateData(data.ninePlayerGameData.rebalanced2fFascistWinCount, data.ninePlayerGameData.rebalanced2fTotalGameCount),
{ width: '400px', height: '400px' }
);

new Chartist.Pie(
'#chart-tenplayer-games-winrate',
processWinrateData(data.tenPlayerGameData.fascistWinCountSeason, data.tenPlayerGameData.totalGameCountSeason),
{
width: '400px',
height: '400px'
}
);
new Chartist.Pie('#chart-tenplayer-games-winrate', processWinrateData(data.tenPlayerGameData.fascistWinCount, data.tenPlayerGameData.totalGameCount), {
width: '400px',
height: '400px'
});

$('#chart-tenplayer-games-winrate').after(
`<p style="text-align: center">Total 10 player games played: ${data.tenPlayerGameData.totalGameCountSeason} | Percentage of Fascists in game: <span style="color: red; font-weight: bold">40%</span></p>`
`<p style="text-align: center">Total 10 player games played: ${data.tenPlayerGameData.totalGameCount.toLocaleString()} | Percentage of Fascists in game: <span style="color: red; font-weight: bold">40%</span></p>`
);
}
});
Expand Down
38 changes: 16 additions & 22 deletions public/scripts/charts.js
Expand Up @@ -13,35 +13,23 @@ document.addEventListener('DOMContentLoaded', function(event) {

$.ajax({
url: 'data',
success: function(data) {
new Chartist.Line('#chart-completed-games', {
labels: data.completedGames.labels,
series: [data.completedGames.series]
});

setTimeout(() => {
const { labels } = data.completedGames;
const $labels = $('#chart-completed-games .ct-label.ct-horizontal');
const showingLabelIndexes = [0, Math.round(labels.length / 4), Math.round(labels.length / 2), Math.round(labels.length / 1.5), labels.length - 1];
const $shownlabels = $labels.filter(index => showingLabelIndexes.includes(index));

$shownlabels.show(); // barf
}, 500);

success: function(d) {
new Chartist.Pie('#chart-allplayer-games-winrate', processWinrateData(data.allPlayerGameData.fascistWinCount, data.allPlayerGameData.totalGameCount), {
width: '400px',
height: '400px'
});

$('#chart-allplayer-games-winrate').after(`<p style="text-align: center">Total games played: ${data.allPlayerGameData.totalGameCount}</p>`);
$('#chart-allplayer-games-winrate').after(
`<p style="text-align: center">Total games played: ${data.allPlayerGameData.totalGameCount.toLocaleString()}</p>`
);

new Chartist.Pie('#chart-fiveplayer-games-winrate', processWinrateData(data.fivePlayerGameData.fascistWinCount, data.fivePlayerGameData.totalGameCount), {
width: '400px',
height: '400px'
});

$('#chart-fiveplayer-games-winrate').after(
`<p style="text-align: center">Total 5 player games played: ${data.fivePlayerGameData.totalGameCount} | Percentage of Fascists in game: <span style="color: red; font-weight: bold">40%</span></p>`
`<p style="text-align: center">Total 5 player games played: ${data.fivePlayerGameData.totalGameCount.toLocaleString()} | Percentage of Fascists in game: <span style="color: red; font-weight: bold">40%</span></p>`
);

new Chartist.Pie('#chart-sixplayer-games-winrate', processWinrateData(data.sixPlayerGameData.fascistWinCount, data.sixPlayerGameData.totalGameCount), {
Expand All @@ -50,7 +38,9 @@ document.addEventListener('DOMContentLoaded', function(event) {
});

$('#chart-sixplayer-games-winrate').after(
`<p style="text-align: center">Total 6 player games played: ${data.sixPlayerGameData.totalGameCount} | Percentage of Fascists in game: <span style="color: red; font-weight: bold">33%</span></p><h2 class="ui header centered">Winrate for 6 player games (rebalanced)</h2><div class="chart" id="chart-sixplayer-rebalanced-games-winrate"></div><p style="text-align: center">Total 6 player rebalanced games played: ${data.sixPlayerGameData.rebalancedTotalGameCount} | Percentage of Fascists in game: <span style="color: red; font-weight: bold">33%</span></p>`
`<p style="text-align: center">Total 6 player games played: ${data.sixPlayerGameData.totalGameCount.toLocaleString()} | Percentage of Fascists in game: <span style="color: red; font-weight: bold">33%</span></p><h2 class="ui header centered">Winrate for 6 player games (rebalanced)</h2><div class="chart" id="chart-sixplayer-rebalanced-games-winrate"></div><p style="text-align: center">Total 6 player rebalanced games played: ${
data.sixPlayerGameData.rebalancedTotalGameCount
} | Percentage of Fascists in game: <span style="color: red; font-weight: bold">33%</span></p>`
);

new Chartist.Pie(
Expand All @@ -66,7 +56,9 @@ document.addEventListener('DOMContentLoaded', function(event) {
);

$('#chart-sevenplayer-games-winrate').after(
`<p style="text-align: center">Total 7 player games played: ${data.sevenPlayerGameData.totalGameCount} | Percentage of Fascists in game: <span style="color: red; font-weight: bold">43%</span></p><h2 class="ui header centered">Winrate for 7 player games (rebalanced)</h2><div class="chart" id="chart-sevenplayer-rebalanced-games-winrate"></div><p style="text-align: center">Total 7 player rebalanced games played: ${data.sevenPlayerGameData.rebalancedTotalGameCount} | Percentage of Fascists in game: <span style="color: red; font-weight: bold">43%</span></p>`
`<p style="text-align: center">Total 7 player games played: ${data.sevenPlayerGameData.totalGameCount.toLocaleString()} | Percentage of Fascists in game: <span style="color: red; font-weight: bold">43%</span></p><h2 class="ui header centered">Winrate for 7 player games (rebalanced)</h2><div class="chart" id="chart-sevenplayer-rebalanced-games-winrate"></div><p style="text-align: center">Total 7 player rebalanced games played: ${
data.sevenPlayerGameData.rebalancedTotalGameCount
} | Percentage of Fascists in game: <span style="color: red; font-weight: bold">43%</span></p>`
);

new Chartist.Pie(
Expand All @@ -82,7 +74,7 @@ document.addEventListener('DOMContentLoaded', function(event) {
);

$('#chart-eightplayer-games-winrate').after(
`<p style="text-align: center">Total 8 player games played: ${data.eightPlayerGameData.totalGameCount} | Percentage of Fascists in game: <span style="color: red; font-weight: bold">38%</span></p>`
`<p style="text-align: center">Total 8 player games played: ${data.eightPlayerGameData.totalGameCount.toLocaleString()} | Percentage of Fascists in game: <span style="color: red; font-weight: bold">38%</span></p>`
);

new Chartist.Pie('#chart-nineplayer-games-winrate', processWinrateData(data.ninePlayerGameData.fascistWinCount, data.ninePlayerGameData.totalGameCount), {
Expand All @@ -91,7 +83,9 @@ document.addEventListener('DOMContentLoaded', function(event) {
});

$('#chart-nineplayer-games-winrate').after(
`<p style="text-align: center">Total 9 player games played: ${data.ninePlayerGameData.totalGameCount} | Percentage of Fascists in game: <span style="color: red; font-weight: bold">44%</span></p><h2 class="ui header centered">Winrate for 9 player games (rebalanced)</h2><div class="chart" id="chart-nineplayer-rebalanced-games-winrate"></div><p style="text-align: center">Total 9 player rebalanced games played: ${data.ninePlayerGameData.rebalanced2fFascistWinCount} | Percentage of Fascists in game: <span style="color: red; font-weight: bold">44%</span></p>`
`<p style="text-align: center">Total 9 player games played: ${data.ninePlayerGameData.totalGameCount.toLocaleString()} | Percentage of Fascists in game: <span style="color: red; font-weight: bold">44%</span></p><h2 class="ui header centered">Winrate for 9 player games (rebalanced)</h2><div class="chart" id="chart-nineplayer-rebalanced-games-winrate"></div><p style="text-align: center">Total 9 player rebalanced games played: ${
data.ninePlayerGameData.rebalanced2fFascistWinCount
} | Percentage of Fascists in game: <span style="color: red; font-weight: bold">44%</span></p>`
);

new Chartist.Pie(
Expand All @@ -106,7 +100,7 @@ document.addEventListener('DOMContentLoaded', function(event) {
});

$('#chart-tenplayer-games-winrate').after(
`<p style="text-align: center">Total 10 player games played: ${data.tenPlayerGameData.totalGameCount} | Percentage of Fascists in game: <span style="color: red; font-weight: bold">40%</span></p>`
`<p style="text-align: center">Total 10 player games played: ${data.tenPlayerGameData.totalGameCount.toLocaleString()} | Percentage of Fascists in game: <span style="color: red; font-weight: bold">40%</span></p>`
);
}
});
Expand Down
15 changes: 0 additions & 15 deletions scripts/retrieveGameData.js
@@ -1,9 +1,7 @@
const mongoose = require('mongoose');
const Game = require('../models/game');
const moment = require('moment');
const _ = require('lodash');
const fs = require('fs');
const labels = [];
const data = {};
const { CURRENTSEASONNUMBER } = require('../src/frontend-scripts/node-constants');

Expand Down Expand Up @@ -218,21 +216,8 @@ Game.find({})
allPlayerGameData.fascistWinCountSeason++;
}
}
labels.push(moment(new Date(game.date)).format('l'));
})
.then(() => {
const uLabels = _.uniq(labels),
series = new Array(uLabels.length).fill(0);

labels.forEach(date => {
series[uLabels.indexOf(date)]++;
});

data.completedGames = {
labels: uLabels,
series
};

data.allPlayerGameData = allPlayerGameData;
data.fivePlayerGameData = fivePlayerGameData;
data.sixPlayerGameData = sixPlayerGameData;
Expand Down
2 changes: 0 additions & 2 deletions views/page-stats-season.pug
Expand Up @@ -4,8 +4,6 @@ block content
.ui.text.container
h1.ui.header.centered Stats
.ui.text.container
h2.ui.header.centered(style="text-decoration: none;") Completed games per day
div#chart-completed-games.chart
h2.ui.header.centered(style="text-decoration: none;") Winrate for all games
h3(style="text-align: center;") Showing current season's stats,
a(href="/stats") click here to see overall stats
Expand Down
2 changes: 0 additions & 2 deletions views/page-stats.pug
Expand Up @@ -4,8 +4,6 @@ block content
.ui.text.container
h1.ui.header.centered Stats
.ui.text.container
h2.ui.header.centered(style="text-decoration: none;") Completed games per day
div#chart-completed-games.chart
h2.ui.header.centered(style="text-decoration: none;") Winrate for all games
h3(style="text-align: center;") Showing overall stats,
a(href="/stats-season") click here to see current season's stats
Expand Down

0 comments on commit 42c7503

Please sign in to comment.