Rewrite points in lua

This commit is contained in:
Neale Pickett 2016-09-21 07:48:05 -06:00
parent 2815423e19
commit e51f237b97
5 changed files with 45 additions and 57 deletions

View File

@ -35,6 +35,6 @@ if www/cgi-bin/puzzles.cgi > www/puzzles.new; then
fi
# Generate new points.json
if bin/points state/points.log > www/points.new; then
if bin/points state > www/points.new; then
mv www/points.new www/points.json
fi

View File

@ -1,46 +1,48 @@
#! /usr/bin/awk -f
#! /usr/bin/lua5.3
BEGIN {
nteams = 0;
print "{";
print " \"points\": [";
}
io.write('{\n "points": [\n')
local teams = {}
local teamnames = {}
local nteams = 0
local NR = 0
{
ts = $1;
hash = $2;
cat = $3;
points = $4;
local statedir = arg[1]
teamno = teams[hash];
if (! teamno) {
teamno = ++nteams;
teams[hash] = teamno;
local f = io.open(statedir .. "/points.log")
for line in f:lines() do
ts, hash, cat, points = line:match("(%d+) (%g+) (%g+) (%d+)")
teamno = teams[hash]
if not teamno then
teamno = nteams
teams[hash] = teamno
nteams = nteams + 1
getline teamnames[hash] < ("state/teams/" hash)
}
tf = io.open(statedir .. "/teams/" .. hash)
teamname = tf:read()
tf:close()
if (NR > 1) {
# JSON sucks.
print ",";
}
printf("[%d, \"%s\", \"%s\", %d]", ts, hash, cat, points);
}
teamnames[hash] = teamname
end
END {
print "";
print " ],";
print " \"teams\": {";
if NR > 0 then
-- JSON sucks, barfs if you have a comma with nothing after it
io.write(",\n")
end
NR = NR + 1
i = 0
for (hash in teamnames) {
if (i++) {
print ",";
}
printf("\"%s\": \"%s\"", hash, teamnames[hash]);
}
io.write(' [' .. ts .. ', "' .. teamno .. '", "' .. cat .. '", ' .. points .. ']')
end
print "";
print " }";
print "}";
}
io.write('\n],\n "teams": {\n')
NR = 0
for hash,teamname in pairs(teamnames) do
if NR > 0 then
io.write(",\n")
end
NR = NR + 1
teamno = teams[hash]
io.write(' "' .. teamno .. '": "' .. teamname .. '"')
end
io.write('\n }\n}\n')

14
kothd
View File

@ -1,14 +0,0 @@
#! /bin/sh
cd ${1:-$(dirname $0)}
KOTH_BASE=$(pwd)
echo "Running koth instances in $KOTH_BASE"
while true; do
for i in $KOTH_BASE/*/assigned.txt; do
dir=${i%/*}
$dir/bin/once
done
sleep 5
done

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 KiB

After

Width:  |  Height:  |  Size: 144 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.8 KiB

After

Width:  |  Height:  |  Size: 64 KiB