From: Vsevolod Stakhov Date: Mon, 20 Mar 2017 14:11:58 +0000 (+0000) Subject: [WebUI] Try to normalize frequencies X-Git-Tag: 1.5.4~74 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3f72bccd49234103b6ed4adee6f26f9c1d12d8d0;p=thirdparty%2Frspamd.git [WebUI] Try to normalize frequencies --- diff --git a/interface/js/app/symbols.js b/interface/js/app/symbols.js index 6e9d016349..0d68c137f0 100644 --- a/interface/js/app/symbols.js +++ b/interface/js/app/symbols.js @@ -97,6 +97,8 @@ function($) { success: function (data) { var distinct_groups = []; var lookup = {}; + var freqs = []; + $.each(data, function (i, group) { $.each(group.rules, function (i, item) { var max = 20; @@ -127,6 +129,7 @@ function($) { if (!item.frequency) { item.frequency = 0; } + freqs.push(item.frequency); item.frequency = Number(item.frequency).toFixed(2) if (!(item.group in lookup)) { lookup[item.group] = 1; @@ -137,6 +140,31 @@ function($) { items.push(item) }); }); + // For better mean calculations + var avg_freq = freqs.sort(function(a, b) { + return Number(a) < Number(b); + }).reduce(function(f1, acc) { + return f1 + acc; + }) / (freqs.length != 0 ? freqs.length : 1.0); + var mult = 1.0; + var exp = 0.0; + + if (avg_freq > 0.0) { + while (mult * avg_freq < 1.0) { + mult *= 10; + exp ++; + } + } + $.each(items, function (i, item) { + item.frequency = Number(item.frequency) * mult; + + if (exp > 0) { + item.frequency = item.frequency.toFixed(2) + 'e-' + exp; + } + else { + item.frequency = item.frequency.toFixed(2); + } + }); FooTable.groupFilter = FooTable.Filtering.extend({ construct : function(instance) { this._super(instance);