-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.lua
51 lines (43 loc) · 1.22 KB
/
log.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
local utils = require 'cpml/utils'
function Log(name,ty)
local self={}
self.Name = name or 'Log'
self.Value = (ty == 'number' and 0) or {}
self.Type = ty or 'mean'
function self.Update(v)
if self.Type == 'number' then
self.Value = v
else
self.Value[#self.Value] = v
end
end
function self.getString()
if self.Type == 'number' then
return tostring(self.Value)
elseif self.Type == 'time' then
return utils.round(self.getMean()*1000,0.0001) .. 'ms'
elseif self.Type == 'mean' then
return tostring(utils.round(self.getMean(),0.01));
end
end
function self.getValue()
if self.Type == 'number' then
return self.value
else
return self.getMean()
end
end
function self.addValue(v)
if self.Type == 'number' then return end
table.insert(self.Value,1,v)
if #self.Value > 200 then self.Value[201] = nil end
end
function self.getMean()
local m = 0;
for i=1,#self.Value do
m = m + self.Value[i]
end
return m/#self.Value;
end
return self
end