From: BuGi Date: Wed, 16 Oct 2019 09:59:49 +0000 (+0200) Subject: [Fix] Correct EMA time calculations X-Git-Tag: 2.1~86^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9b9e41ca9c8a3d86b9bee9ef7929c131caeaa530;p=rspamd.git [Fix] Correct EMA time calculations --- 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))