absurdor

Files related to my duties are Absurdor of Agora Nomic
Log | Files | Refs

report.lua (1193B)


      1 local banner = {
      2 	filter = function(self, e) return e.what == "push" end
      3 	digest = function(self, e)
      4 		local w = nil -- calculate week of timestamp e.when
      5 		if self.pushed[w-1] or self.pushed[w] or week2sec(sec2week(e.when)) < 1693159683 then
      6 			-- At 1693159683 seconds from Unix epoch, the governing
      7 			-- rule was changed so that the Boulder falls to zero
      8 			-- if it was not pushed the previous week. However, the
      9 			-- change is not retroactive; hence the magic number.
     10 			height = (height + 1)
     11 		else
     12 			height = 1
     13 		end
     14 		self.pushed[w] = true
     15 	end,
     16 	render = function(self, out)
     17 		vars = {
     18 			YYYY = os.date("!%Y"),
     19 			MM = os.date("!%m"),
     20 			DD = os.date("!%d"),
     21 			N = height
     22 		}
     23 
     24 		defs = ""
     25 
     26 		for k, v in pairs(vars) do
     27 			defs = defs .. string.format(" --define=%s=%s", k, v)
     28 		end
     29 
     30 		tmpname = ".tmp"
     31 		-- Height banner
     32 		os.execute(string.format("m4 %s templates/banner.m4 >> %s", defs, tmpname))
     33 	end,
     34 	height = 0,
     35 	pushed = {}
     36 }
     37 
     38 function report(modules, log, out)
     39 
     40 	-- Precompute data
     41 	for _,e in ipairs(log) do
     42 		for _,m in ipairs(modules) do
     43 			if m:filter(e) then
     44 				m:digest(e)
     45 			end
     46 		end
     47 	end
     48 
     49 	-- Render data
     50 	for _,m in ipairs(modules) do
     51 		m:render(out)
     52 	end
     53 end