diff options
author | Andrew Lewis <nerf@judo.za.org> | 2017-06-02 16:11:31 +0200 |
---|---|---|
committer | Andrew Lewis <nerf@judo.za.org> | 2017-06-02 16:11:31 +0200 |
commit | 865633cdcbbc3e3cba52b38dc6562bb40a909c87 (patch) | |
tree | 39f810b9291ab472a1378101371ff8bc6744f02d | |
parent | c1184c7823b41ee51750d7551403bbd9499a71ff (diff) | |
download | rspamd-865633cdcbbc3e3cba52b38dc6562bb40a909c87.tar.gz rspamd-865633cdcbbc3e3cba52b38dc6562bb40a909c87.zip |
[Minor] Metadata exporter: score should be number
-rw-r--r-- | lualib/lua_util.lua | 6 | ||||
-rw-r--r-- | src/plugins/lua/metadata_exporter.lua | 3 |
2 files changed, 8 insertions, 1 deletions
diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua index 2ae4e69b1..81e4cb606 100644 --- a/lualib/lua_util.lua +++ b/lualib/lua_util.lua @@ -24,4 +24,10 @@ exports.rspamd_str_trim = function(s) return match(ptrim, s) end +-- Robert Jay Gould http://lua-users.org/wiki/SimpleRound +exports.round = function(num, numDecimalPlaces) + local mult = 10^(numDecimalPlaces or 0) + return math.floor(num * mult + 0.5) / mult +end + return exports diff --git a/src/plugins/lua/metadata_exporter.lua b/src/plugins/lua/metadata_exporter.lua index c4fb5fd03..416f03cab 100644 --- a/src/plugins/lua/metadata_exporter.lua +++ b/src/plugins/lua/metadata_exporter.lua @@ -26,6 +26,7 @@ local rspamd_http = require "rspamd_http" local rspamd_tcp = require "rspamd_tcp" local rspamd_util = require "rspamd_util" local rspamd_logger = require "rspamd_logger" +local lutil = require "lua_util" local ucl = require "ucl" local E = {} local N = 'metadata_exporter' @@ -69,7 +70,7 @@ local function get_general_metadata(task, flatten, no_content) r.user = task:get_user() or 'unknown' r.qid = task:get_queue_id() or 'unknown' r.action = task:get_metric_action('default') - r.score = string.format('%.2f', task:get_metric_score('default')[1]) + r.score = lutil.round(task:get_metric_score('default')[1], 2) local rcpt = task:get_recipients('smtp') if rcpt then local l = {} |