#! /usr/bin/lua5.1 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+) ([^%s]+) ([^%s]+) (%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') io.write(' [0, ""]') end io.write('\n ]') end io.write('\n}\n')