Rewrite points in lua

This commit is contained in:
Neale Pickett 2016-09-21 07:48:05 -06:00
parent 1484b20ac3
commit f1a8ef623e
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;
teamno = teams[hash];
if (! teamno) {
teamno = ++nteams;
teams[hash] = teamno;
getline teamnames[hash] < ("state/teams/" hash)
}
if (NR > 1) {
# JSON sucks.
print ",";
}
printf("[%d, \"%s\", \"%s\", %d]", ts, hash, cat, points);
}
local statedir = arg[1]
END {
print "";
print " ],";
print " \"teams\": {";
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
i = 0
for (hash in teamnames) {
if (i++) {
print ",";
}
printf("\"%s\": \"%s\"", hash, teamnames[hash]);
}
print "";
print " }";
print "}";
}
tf = io.open(statedir .. "/teams/" .. hash)
teamname = tf:read()
tf:close()
teamnames[hash] = teamname
end
if NR > 0 then
-- JSON sucks, barfs if you have a comma with nothing after it
io.write(",\n")
end
NR = NR + 1
io.write(' [' .. ts .. ', "' .. teamno .. '", "' .. cat .. '", ' .. points .. ']')
end
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