From 9b9e41ca9c8a3d86b9bee9ef7929c131caeaa530 Mon Sep 17 00:00:00 2001 From: BuGi Date: Wed, 16 Oct 2019 11:59:49 +0200 Subject: [PATCH] [Fix] Correct EMA time calculations --- src/plugins/lua/reputation.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/lua/reputation.lua b/src/plugins/lua/reputation.lua index 4276f23cc..6b43c7fb4 100644 --- a/src/plugins/lua/reputation.lua +++ b/src/plugins/lua/reputation.lua @@ -865,8 +865,8 @@ local function reputation_redis_init(rule, cfg, ev_base, worker) local last_value = tonumber(redis.call('HGET', KEYS[1], 'v' .. '{= w.name =}')) local window = {= w.time =} -- Adjust alpha - local time_diff = now - last_value - if time_diff > 0 then + local time_diff = now - last + if time_diff < 0 then time_diff = 0 end local alpha = 1.0 - math.exp((-time_diff) / (1000 * window)) -- 2.39.5