absurdor

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 6ff0d364a47b87c1a748408044a7e305ec0f02cc
parent 5b1616fbfb5620c898dc22f4999d84a40a249982
Author: Juan F. Meleiro <juan@juanmeleiro.mat.br>
Date:   Mon, 31 Jul 2023 11:42:16 -0300

report: Add graph for height evolution

Diffstat:
Mabsurdor | 70++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------
1 file changed, 56 insertions(+), 14 deletions(-)

diff --git a/absurdor b/absurdor @@ -87,6 +87,7 @@ end local parser = argparse("absurdor", "Manage Absurdor duties") :command_target("command") parser:command("report", "Generate and send absurdor report") + :flag("-p") local cmd_record = parser:command("record", "Record events") :command_target("what") local cmd_press = cmd_record:command("push", "A push of The Boulder") @@ -100,17 +101,37 @@ local args = parser:parse() fn = "log.json" log = decodewith(json.decode, fn) +function sec2week(s) + return math.floor(s/(24 * 60 * 60 * 7)) +end + if args.command == "report" then height = 0 + local plot = {} + local max = 0 + + if #log > 0 then + start = sec2week(log[1].when) + end for i,e in ipairs(log) do if e.what == "push" then - height = height + 1 + height = (height + 1) % 100 + local day = sec2week(e.when) - start + plot[day] = height + max = day end end - height = height % 100 + local cur = 0 + for i = 1, max do + if plot[i] then + cur = plot[i] + else + plot[i] = cur + end + end vars = { YYYY = os.date("%Y"), @@ -129,21 +150,42 @@ if args.command == "report" then os.execute(string.format("m4 %s template.m4 >> %s", defs, tmpname)) f = io.open(tmpname, "a") - f:write("There is no log, for there is no point.\n") - f:write("There is no log, for there is no hope.\n") - f:write("There is no log. But do not despair;\n\n rebel\n\n") + + -- local lines = {} + -- for i = math.max(1, #plot - 70), #plot do + -- for h = 1, plot[i] do + -- lines[h] = (lines[h] or "") .. "#" + -- end + -- for h = plot[i]+1, 100 do + -- lines[h] = (lines[h] or "") .. " " + -- end + -- end + -- for i = #lines, 1, -1 do + -- f:write(lines[i] .. "\n") + -- end + + for i = #plot, 1, -1 do + f:write(string.rep("#", plot[i]) .. "\n") + end + + f:write("======================================================================") f:close() - os.execute(string.format("neomutt -H %s -E", tmpname)) - - if yn("Archive report? [Yn] ") then - table.insert(log, { - when = os.time(), - what = "report", - height = height, - }) - os.rename(tmpname, string.format("archive/%s", os.date("%F"))) + if args.p then + os.execute(string.format("cat %s", tmpname)) + os.remove(tmpname) + else + os.execute(string.format("neomutt -H %s -E", tmpname)) + + if yn("Archive report? [Yn] ") then + table.insert(log, { + when = os.time(), + what = "report", + height = height, + }) + os.rename(tmpname, string.format("archive/%s", os.date("%F"))) + end end elseif args.command == "record" then if args.what == "push" then