3 local tool_re = "^([%w%.]+)"
4 local test_re = "([%w%./_]+)"
5 local rc_re = string.char(27).."%[%d+;%d+m([%a]+)"..string.char(27).."%[0m"
6 local time_re = "(%d+m%d+%.%d+s)"
7 local mark_re = "(%d+)"
8 local opt_re = "(gc%-%a+)$"
11 local fmt = "INSERT bench "..
12 "(result, compilation, test, time, timeuser, mark, options) "..
13 "VALUES ('%s', '%s', '%s', %d, %d, '%s', '%s');\n"
15 -- build the huge regex
16 local re = tool_re .. sep .. test_re .. sep .. rc_re .. sep ..
17 time_re .. sep ..time_re .. sep ..time_re .. sep ..
18 mark_re .. sep .. opt_re
20 -- the string to cents of seconds function
22 local _,_,min,sec,cents = string.find(s,"(%d+)m(%d+)%.(%d+)s")
23 return min * 6000 + sec * 100 + cents
29 min = math.floor(s / 6000)
30 sec = math.floor((s - min * 6000 - cents) / 100)
31 return string.format("%dm%02d.%02ds",min,sec,cents)
34 -- logfile to sql conversion
35 function log2sql(file)
42 local x,_,tool,test,rc,real,user,_,mark,opt = string.find(l,re)
45 error("regex failed on '"..l.."'")
48 -- check the result is valid
49 if tool ~= "matitac" and tool ~= "matitac.opt" then
50 error("unknown tool " .. tool)
52 if tool == "matitac" then tool = "byte" else tool = "opt" end
54 if rc ~= "OK" and rc ~= "FAIL" then
55 error("unknown result " .. rc)
59 if opt ~= "gc-on" and opt ~= "gc-off" then
60 error("unknown option "..opt)
65 -- print the sql statement
66 table.insert(t,string.format(fmt,rc,tool,test,real,user,mark,opt))
68 return table.concat(t)
72 function proportion(x,y,a,b)
83 return string.format("%d",rc)
86 -- conversion from the old db to the new one
87 function convertsql(file)
88 local f = io.open(file)
89 return string.gsub(f:read("*a"),time_re,
95 -- call the desired function and print the result
98 f = _G[fun] or error("no " .. fun .. " defined")
99 print(f(unpack(arg)) or "")