Fix some bugs

This commit is contained in:
Pytron 2019-03-26 14:07:36 +00:00
parent 85ddb7b80f
commit 01001d94f2
5 changed files with 61 additions and 26 deletions

21
package-lock.json generated
View File

@ -17,6 +17,11 @@
"@types/babel-types": "*" "@types/babel-types": "*"
} }
}, },
"abbrev": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
"integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q=="
},
"accepts": { "accepts": {
"version": "1.3.5", "version": "1.3.5",
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.5.tgz", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.5.tgz",
@ -630,6 +635,14 @@
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz",
"integrity": "sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk=" "integrity": "sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk="
}, },
"nopt": {
"version": "1.0.10",
"resolved": "https://registry.npmjs.org/nopt/-/nopt-1.0.10.tgz",
"integrity": "sha1-bd0hvSoxQXuScn3Vhfim83YI6+4=",
"requires": {
"abbrev": "1"
}
},
"object-assign": { "object-assign": {
"version": "4.1.1", "version": "4.1.1",
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
@ -999,6 +1012,14 @@
"resolved": "https://registry.npmjs.org/token-stream/-/token-stream-0.0.1.tgz", "resolved": "https://registry.npmjs.org/token-stream/-/token-stream-0.0.1.tgz",
"integrity": "sha1-zu78cXp2xDFvEm0LnbqlXX598Bo=" "integrity": "sha1-zu78cXp2xDFvEm0LnbqlXX598Bo="
}, },
"touch": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/touch/-/touch-3.1.0.tgz",
"integrity": "sha512-WBx8Uy5TLtOSRtIq+M03/sKDrXCLHxwDcquSP2c43Le03/9serjQBIztjRz6FkJez9D/hleyAXTBGLwwZUw9lA==",
"requires": {
"nopt": "~1.0.10"
}
},
"traverse": { "traverse": {
"version": "0.3.9", "version": "0.3.9",
"resolved": "https://registry.npmjs.org/traverse/-/traverse-0.3.9.tgz", "resolved": "https://registry.npmjs.org/traverse/-/traverse-0.3.9.tgz",

View File

@ -9,6 +9,7 @@
"express": "^4.16.4", "express": "^4.16.4",
"express-fileupload": "^1.1.3-alpha.1", "express-fileupload": "^1.1.3-alpha.1",
"pug": "^2.0.3", "pug": "^2.0.3",
"touch": "^3.1.0",
"unzip": "^0.1.11" "unzip": "^0.1.11"
} }
} }

View File

@ -32,8 +32,8 @@ for real_ai in ai_manager.__all__:
# It is made to be fast and not to be used by humans. It especially doesn't # It is made to be fast and not to be used by humans. It especially doesn't
# display and window and doesn't listen to any keystrokes. # display and window and doesn't listen to any keystrokes.
width = 40 width = 10
height = 40 height = 10
def run_battle(ai1, ai2): def run_battle(ai1, ai2):
games = 50 games = 50

View File

@ -3,16 +3,17 @@ const fs = require('fs');
const process = require('process'); const process = require('process');
const pathtools = require('path'); const pathtools = require('path');
const express = require('express'); const express = require('express');
const fileUpload = require("express-fileupload"); const fileUpload = require('express-fileupload');
const { spawn } = require('child_process'); const { spawn } = require('child_process');
const pug = require('pug'); const pug = require('pug');
const unzip = require('unzip'); const unzip = require('unzip');
const touch = require('touch');
// Consts // Consts
const port = 8000; const port = 8000;
const pythonPath = "/home/pytron/miniconda3/envs/pytron/bin/python" const pythonPath = '/home/pytron/miniconda3/envs/pytron/bin/python'
const aisPath = "pytron_run/ai_manager/" const aisPath = 'pytron_run/ai_manager/'
const aisPathOld = "pytron_run/ai_manager_old" const aisPathOld = 'pytron_run/ai_manager_old'
// Create the directories to store the files // Create the directories to store the files
try { fs.mkdirSync(aisPath); } catch { } try { fs.mkdirSync(aisPath); } catch { }
@ -35,19 +36,19 @@ function runPython() {
p.stdout.on('data', (data) => { p.stdout.on('data', (data) => {
let content = data.toString().split('\n'); let content = data.toString().split('\n');
for (let line of content) { for (let line of content) {
console.log("run.py: " + line); console.log('run.py: ' + line);
} }
}); });
p.stderr.on('data', (data) => { p.stderr.on('data', (data) => {
let content = data.toString().split('\n'); let content = data.toString().split('\n');
for (let line of content) { for (let line of content) {
console.log("run.py: " + line); console.log('run.py: ' + line);
} }
}); });
p.on('close', (code) => { p.on('close', (code) => {
process.stdout.write("Python finished executing"); process.stdout.write('Python finished executing');
if (pythonShouldRun) { if (pythonShouldRun) {
process.stdout.write(' but another request arrive, so we will relaunch it\n'); process.stdout.write(' but another request arrive, so we will relaunch it\n');
pythonShouldRun = false; pythonShouldRun = false;
@ -111,7 +112,10 @@ function startServer() {
console.log(err); console.log(err);
} }
let parsed = parse(data); let parsed = parse(data);
res.render('index', parsed); res.render('index', {
data: parsed,
running: pythonRunning,
});
}); });
}); });
@ -147,15 +151,20 @@ function startServer() {
fs.mkdirSync(path); fs.mkdirSync(path);
let zipfile = pathtools.join(path, "archive.zip"); let zipfile = pathtools.join(path, 'archive.zip');
req.files.archive.mv(zipfile, (err) => { req.files.archive.mv(zipfile, (err) => {
if (err !== null) {
console.log(err); console.log(err);
}
fs.createReadStream(zipfile) fs.createReadStream(zipfile)
.pipe(unzip.Extract({path})) .pipe(unzip.Extract({path}))
.on('close', () => { .on('close', () => {
// Touch __init__.py
touch(pathtools.join(path, '__init__.py'), () => {
// Trigger python_run // Trigger python_run
runPython(); runPython();
res.send('yo'); res.redirect('/');
});
}) })
.on('error', () => { .on('error', () => {
res.send('an error occured while extracting the archive') res.send('an error occured while extracting the archive')
@ -179,8 +188,8 @@ function main() {
runPython(); runPython();
break; break;
default: default:
console.log("Unknown option: " + process.argv[2]); console.log('Unknown option: ' + process.argv[2]);
console.log("Usage: node server.js start|python") console.log('Usage: node server.js start|python')
process.exit(1); process.exit(1);
break; break;
} }

View File

@ -3,25 +3,29 @@ extends base
block content block content
section.section section.section
.container .container
if running
.columns.is-centered
.column.is-narrow.is-desktop
h5.title.is-5 Some battles are running...
.columns.is-centered .columns.is-centered
.column.is-narrow.is-desktop .column.is-narrow.is-desktop
table.table.is-bordered.is-striped.is-narrow.is-hoverable table.table.is-bordered.is-striped.is-narrow.is-hoverable
tr tr
th th
for ai in ais for ai in data.ais
th.has-text-centered= ai.name th.has-text-centered= ai.name
for ai1 in ais for ai1 in data.ais
tr tr
th.has-text-centered= ai1.name th.has-text-centered= ai1.name
for ai2 in ais for ai2 in data.ais
if ai1.name == ai2.name if ai1.name == ai2.name
td td
else if battles[ai1.name + "/" + ai2.name] > battles[ai2.name + "/" + ai1.name] else if data.battles[ai1.name + "/" + ai2.name] > data.battles[ai2.name + "/" + ai1.name]
td.has-text-success= battles[ai1.name + "/" + ai2.name] td.has-text-success= data.battles[ai1.name + "/" + ai2.name]
else if battles[ai1.name + "/" + ai2.name] < battles[ai2.name + "/" + ai1.name] else if data.battles[ai1.name + "/" + ai2.name] < data.battles[ai2.name + "/" + ai1.name]
td.has-text-danger= battles[ai1.name + "/" + ai2.name] td.has-text-danger= data.battles[ai1.name + "/" + ai2.name]
else else
td= battles[ai1.name + "/" + ai2.name] td= data.battles[ai1.name + "/" + ai2.name]
.column.is-narrow.is-desktop .column.is-narrow.is-desktop
table.table.is-bordered.is-striped.is-hoverable table.table.is-bordered.is-striped.is-hoverable
tr tr
@ -30,7 +34,7 @@ block content
th.has-text-centered Nulls th.has-text-centered Nulls
th.has-text-centered Defeats th.has-text-centered Defeats
th.has-text-centered Score th.has-text-centered Score
for ai in sortedAis for ai in data.sortedAis
tr tr
td.has-text-centered td.has-text-centered
strong= ai.name strong= ai.name