moth/bin/points

46 lines
981 B
Plaintext
Executable File

#! /usr/bin/lua5.3
local basedir = arg[1]
local statedir = basedir .. "/state"
io.write('{\n "points": [\n')
local teams = {}
local teamnames = {}
local nteams = 0
local NR = 0
for line in io.lines(statedir .. "/points.log") do
local ts, hash, cat, points = line:match("(%d+) (%g+) (%g+) (%d+)")
local teamno = teams[hash]
if not teamno then
teamno = nteams
teams[hash] = teamno
nteams = nteams + 1
teamnames[hash] = io.lines(statedir .. "/teams/" .. hash)()
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')