moth/bin/puzzles

54 lines
1.1 KiB
Plaintext
Raw Normal View History

#! /usr/bin/lua5.3
local basedir = arg[1]
local statedir = basedir .. "/state"
local max_by_cat = {}
for cat in io.lines(statedir .. "/categories.txt") do
max_by_cat[cat] = 0
end
for line in io.lines(statedir .. "/points.log") do
local ts, team, cat, points = line:match("^(%d+) (%g+) (%g+) (%d+)")
points = tonumber(points) or 0
-- Skip scores for removed categories
if (max_by_cat[cat] ~= nil) then
max_by_cat[cat] = math.max(max_by_cat[cat], points)
end
end
local i = 0
io.write('{\n')
for cat, biggest in pairs(max_by_cat) do
local points, dirname
local j = 0
if i > 0 then
io.write(',\n')
end
i = i + 1
io.write(' "' .. cat .. '": [\n')
for line in io.lines(basedir .. "/packages/" .. cat .. "/map.txt") do
points, dirname = line:match("^(%d+) (.*)")
points = tonumber(points)
if j > 0 then
io.write(',\n')
end
j = j + 1
io.write(' [' .. points .. ', "' .. dirname .. '"]')
if (points > biggest) then
break
end
end
if (points == biggest) then
io.write(',\n')
2016-09-21 16:10:29 -06:00
io.write(' [0, ""]')
end
io.write('\n ]')
end
io.write('\n}\n')