2015-05-26 10:16:22 -06:00
|
|
|
#! /usr/bin/env lua
|
2015-04-19 22:57:35 -06:00
|
|
|
|
2015-05-26 10:14:30 -06:00
|
|
|
package.path = "?.lua;cgi-bin/?.lua;www/cgi-bin/?.lua"
|
2015-04-21 07:57:11 -06:00
|
|
|
|
2015-04-19 22:57:35 -06:00
|
|
|
local koth = require "koth"
|
|
|
|
|
|
|
|
local max_by_cat = {}
|
|
|
|
|
2015-04-21 07:57:11 -06:00
|
|
|
local f = io.popen("ls " .. koth.path("packages"))
|
2015-04-19 22:57:35 -06:00
|
|
|
for cat in f:lines() do
|
|
|
|
max_by_cat[cat] = 0
|
|
|
|
end
|
|
|
|
f:close()
|
|
|
|
|
|
|
|
|
2015-04-21 07:57:11 -06:00
|
|
|
for line in io.lines(koth.path("state/points.log")) do
|
2015-04-21 09:02:25 -06:00
|
|
|
local ts, team, cat, points, comment = line:match("^(%d+) (%w+) ([%w-]+) (%d+) ?(.*)")
|
2015-04-19 22:57:35 -06:00
|
|
|
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 body = "<dl>\n"
|
|
|
|
for cat, biggest in pairs(max_by_cat) do
|
|
|
|
local points, dirname
|
|
|
|
|
|
|
|
body = body .. "<dt>" .. cat .. "</dt>"
|
|
|
|
body = body .. "<dd>"
|
2015-04-21 07:57:11 -06:00
|
|
|
for line in io.lines(koth.path("packages/" .. cat .. "/map.txt")) do
|
2015-04-19 22:57:35 -06:00
|
|
|
points, dirname = line:match("^(%d+) (.*)")
|
|
|
|
points = tonumber(points)
|
|
|
|
|
2015-04-21 07:57:11 -06:00
|
|
|
body = body .. "<a href=\"../" .. cat .. "/" .. dirname .. "/index.html\">" .. points .. "</a> "
|
2015-04-19 22:57:35 -06:00
|
|
|
if (points > biggest) then
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if (points == biggest) then
|
|
|
|
body = body .. "<span title=\"Category Complete\">⁂</span>"
|
|
|
|
end
|
|
|
|
body = body .. "</dd>\n"
|
|
|
|
end
|
|
|
|
body = body .. "</dl>\n"
|
2015-06-03 15:31:26 -06:00
|
|
|
body = body .. "<fieldset><legend>Sandia Token:</legend>"
|
|
|
|
body = body .. "<p>Example: <samp>sandia:5:xylep-radar-nanox</samp></p>"
|
|
|
|
body = body .. "<form action='cgi-bin/token.cgi'>"
|
|
|
|
body = body .. "Team Hash: <input name='t'><br>"
|
|
|
|
body = body .. "Token: <input name='k'>"
|
|
|
|
body = body .. "<input type='submit'>"
|
|
|
|
body = body .. "</form>"
|
|
|
|
body = body .. "</fieldset>"
|
2015-04-20 10:11:38 -06:00
|
|
|
body = body .. "<p>Reloading this page periodically may yield updated puzzle lists.</p>"
|
2015-04-19 22:57:35 -06:00
|
|
|
|
2015-05-26 10:14:30 -06:00
|
|
|
koth.page("Open Puzzles", body)
|