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