@@ -37,7 +37,6 @@ threshold_cap = 10 -- Threshold will be calculated average + (calculated average
37
37
require " string"
38
38
require " table"
39
39
40
- local c = require " cms.cms"
41
40
local ostime = require " os" .time
42
41
43
42
local sample_min_id = read_config (" sample_min_id" ) or error (" sample_min_id must be configured" )
@@ -51,7 +50,7 @@ local id_fieldc = read_config("id_field_capture")
51
50
local cms_epsilon = read_config (" cms_epsilon" ) or 1 / 10000
52
51
local cms_delta = read_config (" cms_delta" ) or 0.0001
53
52
54
- local cms = c .new (cms_epsilon , cms_delta )
53
+ local cms = require " streaming_algorithms.cm_sketch " .new (cms_epsilon , cms_delta )
55
54
56
55
local alist = {}
57
56
@@ -84,7 +83,7 @@ function sampler:reset()
84
83
end
85
84
86
85
function sampler :calc ()
87
- if not cms or self .n < sample_min_id or self .evcount < sample_min_ev then
86
+ if self .n < sample_min_id or self .evcount < sample_min_ev then
88
87
return
89
88
end
90
89
if self .validtick < sample_ticks then
@@ -94,7 +93,7 @@ function sampler:calc()
94
93
local cnt = 0
95
94
local t = 0
96
95
for k ,v in pairs (self .s ) do
97
- t = t + cms . check (k )
96
+ t = t + cms : point_query (k )
98
97
cnt = cnt + 1
99
98
end
100
99
self .threshold = t / cnt
@@ -108,7 +107,7 @@ function sampler:add(x)
108
107
if self .start_time + sample_window < ostime () then
109
108
self :reset ()
110
109
alist :reset ()
111
- cms = c . new ( cms_epsilon , cms_delta )
110
+ cms : clear ( )
112
111
end
113
112
self .evcount = self .evcount + 1
114
113
self .validtick = self .validtick + 1
@@ -129,12 +128,12 @@ function process_message()
129
128
if not id then return - 1 , " no id_field" end
130
129
if id_fieldc then
131
130
id = string.match (id , id_fieldc )
132
- if not id then return 1 end -- no error as the capture may intentionally reject entries
131
+ if not id then return 0 end -- no error as the capture may intentionally reject entries
133
132
end
134
133
135
134
sampler :add (id )
136
135
sampler :calc ()
137
- local q = cms . add (id )
136
+ local q = cms : update (id )
138
137
if sampler .threshold ~= 0 and q > sampler .threshold then
139
138
alist :add (id , q )
140
139
end
0 commit comments