commit 0cee6cd3d76a63d25bf8243734022e742a5262f3
parent 5d42544c2b3e1034f7034bb282667cd80b379b14
Author: Juan F. Meleiro <juan@juanmeleiro.mat.br>
Date: Mon, 9 Dec 2024 12:51:36 -0300
Start revamping the whole thing
So much changed in such an unordered way that I had to simply package
it all up into a commit and leave it here to rot.
Diffstat:
4 files changed, 99 insertions(+), 30 deletions(-)
diff --git a/NOTES.md b/NOTES.md
@@ -0,0 +1,26 @@
+# Notes
+
+## Todo
+
+Refactor `fmt_event` to use a function per event type.
+
+## Achievements
+
+The Boulder Achievements
+
+**Records**
+By height (1, 10, 100, 1000)
+By speed (1, 2, 3, 4, 5, …)
+By latest single push
+By latest push
+By earliest push
+
+**Edge cases**
+Two pushes less than 5 minutes appart by two different players
+Two pushes less than 5 minutes appart by a single player
+A push during a leap second
+A push as the first action a new player took
+A push right before deregistering
+Every registered player pushed this week
+Only one player pushed this week
+No players pushed this week
diff --git a/absurdor b/absurdor
@@ -6,6 +6,7 @@ local path = require "path"
local fs = require "path.fs"
local record = require "lib.record"
local pprint = require("pprint").pprint
+local date = require "date"
require "lib.util"
require "lib.log"
@@ -63,15 +64,19 @@ if args.command == "report" then
history = {},
namewidth = 0
}
+ local last = 0
if #log > 0 then
start = sec2week(log[1].when)
+ max = start
end
for i,e in ipairs(log) do
if e.what == "push" then
- local w = sec2week(e.when) - start
- if pushed[w-1] or pushed[w] or week2sec(sec2week(e.when)) < 1693159683 then
+ local w = sec2week(e.when)
+ if pushed[prevweek(w)] or
+ pushed[w] or
+ w < 1693159683 then
-- At 1693159683 seconds from Unix epoch, the governing
-- rule was changed so that the Boulder falls to zero
-- if it was not pushed the previous week. However, the
@@ -108,6 +113,8 @@ if args.command == "report" then
veblen.cost = e.value
elseif e.what == "report" then
veblen.cost = e.cost or veblen.cost
+ height = e.height or e.height
+ last = e.when
end
end
@@ -120,8 +127,8 @@ if args.command == "report" then
table.insert(veblen.history, veblen.current)
- local w = sec2week(os.time()) - start
- if (not (w == 0)) and (not pushed[w-1]) then
+ local w = sec2week(os.time())
+ if (not (w == 0)) and (not pushed[prevweek(w)]) then
failed = true
if not pushed[w] then
height = 0
@@ -129,15 +136,6 @@ if args.command == "report" then
end
end
- local cur = 0
- for i = 1, max do
- if plot[i] then
- cur = plot[i]
- else
- plot[i] = (args.d and 0 or cur)
- end
- end
-
vars = {
YYYY = os.date("!%Y"),
MM = os.date("!%m"),
@@ -176,21 +174,6 @@ if args.command == "report" then
end
f:write("\n")
- local max_msg = args.d and " <- the furthest we've ever pushed in a week!" or " <- the heighest we've ever reached!"
- -- Height graph
- f:write("THE ROAD SO FAR\n")
- for i = #plot, 1, -1 do
- f:write("|", string.rep("#", math.floor((math.min(30,plot[max]))*(plot[i] or 0)/plot[max])))
- if i == max then
- f:write(max_msg)
- elseif i == #plot then
- f:write(" <- where we are now.")
- end
- f:write(" ")
- f:write(table.concat(who[i] or {}, ", "))
- f:write("\n")
- end
-
f:write("\n----------------------------------------------------------------------\nTHE VEBLEN\n\n")
f:write(" The Veblen\n")
f:write(string.format(" is owned by %s\n", veblen.current.who))
diff --git a/lib/report.lua b/lib/report.lua
@@ -0,0 +1,53 @@
+local banner = {
+ filter = function(self, e) return e.what == "push" end
+ digest = function(self, e)
+ local w = nil -- calculate week of timestamp e.when
+ if self.pushed[w-1] or self.pushed[w] or week2sec(sec2week(e.when)) < 1693159683 then
+ -- At 1693159683 seconds from Unix epoch, the governing
+ -- rule was changed so that the Boulder falls to zero
+ -- if it was not pushed the previous week. However, the
+ -- change is not retroactive; hence the magic number.
+ height = (height + 1)
+ else
+ height = 1
+ end
+ self.pushed[w] = true
+ end,
+ render = function(self, out)
+ vars = {
+ YYYY = os.date("!%Y"),
+ MM = os.date("!%m"),
+ DD = os.date("!%d"),
+ N = height
+ }
+
+ defs = ""
+
+ for k, v in pairs(vars) do
+ defs = defs .. string.format(" --define=%s=%s", k, v)
+ end
+
+ tmpname = ".tmp"
+ -- Height banner
+ os.execute(string.format("m4 %s templates/banner.m4 >> %s", defs, tmpname))
+ end,
+ height = 0,
+ pushed = {}
+}
+
+function report(modules, log, out)
+
+ -- Precompute data
+ for _,e in ipairs(log) do
+ for _,m in ipairs(modules) do
+ if m:filter(e) then
+ m:digest(e)
+ end
+ end
+ end
+
+ -- Render data
+ for _,m in ipairs(modules) do
+ m:render(out)
+ end
+end
diff --git a/lib/util.lua b/lib/util.lua
@@ -69,9 +69,16 @@ function format(fmt, dict, sett)
end
function sec2week(s)
- return math.floor(s/(24 * 60 * 60 * 7))
+ local d = date(s)
+ d:adddays(-d:getisoweekday()+1)
+ d:sethours(0,0,0,0)
+ return date.diff(d, date.epoch()):spanseconds()
end
function week2sec(w)
- return w*24*60*60*7
+ return w
+end
+
+function prevweek(w)
+ return date.diff(date(w):adddays(-7), date.epoch()):spanseconds()
end