]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[WebUI] Try to normalize frequencies
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 20 Mar 2017 14:11:58 +0000 (14:11 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 20 Mar 2017 14:11:58 +0000 (14:11 +0000)
interface/js/app/symbols.js

index 6e9d0163495cac7ae3753f621d415cb385981274..0d68c137f0a59223a1041c0db2d8d00014795afd 100644 (file)
@@ -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);