mirror of https://github.com/dirtbags/moth.git
49 lines
1013 B
Plaintext
Executable File
49 lines
1013 B
Plaintext
Executable File
#! /usr/bin/lua5.3
|
|
|
|
io.write('{\n "points": [\n')
|
|
local teams = {}
|
|
local teamnames = {}
|
|
local nteams = 0
|
|
local NR = 0
|
|
|
|
local statedir = arg[1]
|
|
|
|
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
|
|
|
|
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')
|