This commit is contained in:
Thomas Forgione 2019-03-20 17:13:06 +01:00
parent 28d28433f8
commit d09036e66c
No known key found for this signature in database
GPG Key ID: 203DAEA747F48F41
3 changed files with 53 additions and 10 deletions

View File

@ -4,6 +4,45 @@ const pug = require('pug');
const app = express(); const app = express();
const port = 8000; const port = 8000;
function parse(data) {
let content = JSON.parse(data);
let parsed = {ais: [], battles: {}};
for (let ai of content.ais) {
parsed.ais.push({
name: ai,
victories: 0,
defeats: 0,
});
}
for (let key in content.battles) {
let battlers = key.split('/');
let ai1 = battlers[0];
let ai2 = battlers[1];
parsed.battles[ai1 + '/' + ai2] = Math.floor(100 * content.battles[key]);
parsed.battles[ai2 + '/' + ai1] = 100 - parsed.battles[ai1 + '/' + ai2];
}
parsed.sortedAis = parsed.ais.slice(0);
parsed.sortedAis.sort((a, b) => {
if (a.victories < b.victories) {
return -1;
} else if (a.victories > b.victories) {
return 1;
} else {
if (a.defeats > b.defeats) {
return -1;
} else if (a.defeats < b.defeats) {
return 1;
} else {
return 0;
}
}
});
return parsed;
}
app.set('view engine', 'pug'); app.set('view engine', 'pug');
app.get('/', (req, res) => { app.get('/', (req, res) => {
@ -11,7 +50,7 @@ app.get('/', (req, res) => {
if (err != null) { if (err != null) {
console.log("Error: " + e); console.log("Error: " + e);
} }
let parsed = JSON.parse(data); let parsed = parse(data);
res.render('index', parsed); res.render('index', parsed);
}); });
}); });

View File

@ -18,8 +18,8 @@ html(lang='en')
span(aria-hidden='true') span(aria-hidden='true')
#navbarBasicExample.navbar-menu #navbarBasicExample.navbar-menu
.navbar-end .navbar-end
a.navbar-item.is-size-6(href='/button') a.navbar-item.is-size-6(href='/upload')
strong Button strong Upload your AI
block content block content
script. script.
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {

View File

@ -9,17 +9,21 @@ block content
tr tr
th th
for ai in ais for ai in ais
th.has-text-centered= ai th.has-text-centered= ai.name
th.has-text-centered.has-text-success ✓ th.has-text-centered.has-text-success ✓
th.has-text-centered.has-text-danger ✗ th.has-text-centered.has-text-danger ✗
for ai1 in ais for ai1 in ais
tr tr
th.has-text-centered= ai1 th.has-text-centered= ai1.name
for ai2 in ais for ai2 in ais
if ai1 == ai2 if ai1.name == ai2.name
td td
else if battles[ai1.name + "/" + ai2.name] > 50
td.has-text-success= battles[ai1.name + "/" + ai2.name]
else if battles[ai1.name + "/" + ai2.name] < 50
td.has-text-danger= battles[ai1.name + "/" + ai2.name]
else else
td.has-text-success= battles[ai1 + "/" + ai2] td= battles[ai1.name + "/" + ai2.name]
td.has-text-centered td.has-text-centered
strong= 0 strong= 0
td.has-text-centered td.has-text-centered
@ -29,12 +33,12 @@ block content
tr tr
th.has-text-centered AI th.has-text-centered AI
th.has-text-centered Score th.has-text-centered Score
for ai in ais for ai in sortedAis
tr tr
td.has-text-centered td.has-text-centered
strong= ai strong= ai.name
td.has-text-centered td.has-text-centered
strong 0 strong= ai.victories - ai.defeats