From: Andrew Lewis Date: Fri, 2 Jun 2017 14:11:31 +0000 (+0200) Subject: [Minor] Metadata exporter: score should be number X-Git-Tag: 1.6.0~75 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=865633cdcbbc3e3cba52b38dc6562bb40a909c87;p=rspamd.git [Minor] Metadata exporter: score should be number --- 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 = {}