mirror of https://github.com/dirtbags/moth.git
Rewrite points in lua
This commit is contained in:
parent
2815423e19
commit
e51f237b97
2
bin/once
2
bin/once
|
@ -35,6 +35,6 @@ if www/cgi-bin/puzzles.cgi > www/puzzles.new; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Generate new points.json
|
# 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
|
mv www/points.new www/points.json
|
||||||
fi
|
fi
|
||||||
|
|
78
bin/points
78
bin/points
|
@ -1,46 +1,48 @@
|
||||||
#! /usr/bin/awk -f
|
#! /usr/bin/lua5.3
|
||||||
|
|
||||||
BEGIN {
|
io.write('{\n "points": [\n')
|
||||||
nteams = 0;
|
local teams = {}
|
||||||
print "{";
|
local teamnames = {}
|
||||||
print " \"points\": [";
|
local nteams = 0
|
||||||
}
|
local NR = 0
|
||||||
|
|
||||||
{
|
local statedir = arg[1]
|
||||||
ts = $1;
|
|
||||||
hash = $2;
|
|
||||||
cat = $3;
|
|
||||||
points = $4;
|
|
||||||
|
|
||||||
teamno = teams[hash];
|
local f = io.open(statedir .. "/points.log")
|
||||||
if (! teamno) {
|
for line in f:lines() do
|
||||||
teamno = ++nteams;
|
ts, hash, cat, points = line:match("(%d+) (%g+) (%g+) (%d+)")
|
||||||
teams[hash] = teamno;
|
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) {
|
teamnames[hash] = teamname
|
||||||
# JSON sucks.
|
end
|
||||||
print ",";
|
|
||||||
}
|
|
||||||
printf("[%d, \"%s\", \"%s\", %d]", ts, hash, cat, points);
|
|
||||||
}
|
|
||||||
|
|
||||||
END {
|
if NR > 0 then
|
||||||
print "";
|
-- JSON sucks, barfs if you have a comma with nothing after it
|
||||||
print " ],";
|
io.write(",\n")
|
||||||
print " \"teams\": {";
|
end
|
||||||
|
NR = NR + 1
|
||||||
|
|
||||||
i = 0
|
io.write(' [' .. ts .. ', "' .. teamno .. '", "' .. cat .. '", ' .. points .. ']')
|
||||||
for (hash in teamnames) {
|
end
|
||||||
if (i++) {
|
|
||||||
print ",";
|
|
||||||
}
|
|
||||||
printf("\"%s\": \"%s\"", hash, teamnames[hash]);
|
|
||||||
}
|
|
||||||
|
|
||||||
print "";
|
io.write('\n],\n "teams": {\n')
|
||||||
print " }";
|
|
||||||
print "}";
|
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
14
kothd
|
@ -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 |
Loading…
Reference in New Issue