]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Store more information about symbols added
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 15 Oct 2018 14:22:33 +0000 (15:22 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 15 Oct 2018 15:24:15 +0000 (16:24 +0100)
src/libmime/filter.c
src/libmime/filter.h

index 7d7836d6ff773277ed585aa7067e51660aa9cd44..d2b5492519e78779524fdbd1e2fdfa651496d33b 100644 (file)
@@ -54,13 +54,10 @@ rspamd_create_metric_result (struct rspamd_task *task)
                return metric_res;
        }
 
-       metric_res = rspamd_mempool_alloc (task->task_pool,
+       metric_res = rspamd_mempool_alloc0 (task->task_pool,
                        sizeof (struct rspamd_metric_result));
        metric_res->symbols = kh_init (rspamd_symbols_hash);
        metric_res->sym_groups = kh_init (rspamd_symbols_group_hash);
-       metric_res->grow_factor = 0;
-       metric_res->score = 0;
-       metric_res->passthrough_result = NULL;
 
        /* Optimize allocation */
        kh_resize (rspamd_symbols_group_hash, metric_res->sym_groups, 4);
@@ -364,9 +361,24 @@ insert_metric_result (struct rspamd_task *task,
                }
 
                if (!isnan (final_score)) {
+#ifndef DBL_EPSILON
+#define DBL_EPSILON 2.2204460492503131e-16
+#endif
+                       const double epsilon = DBL_EPSILON;
+
                        metric_res->score += final_score;
                        metric_res->grow_factor = next_gf;
                        s->score = final_score;
+
+                       /* We ignore zero scored symbols */
+                       if (final_score > epsilon) {
+                               metric_res->npositive ++;
+                               metric_res->positive_score += final_score;
+                       }
+                       else if (final_score < epsilon) {
+                               metric_res->nnegative ++;
+                               metric_res->negative_score += fabs (final_score);
+                       }
                }
                else {
                        s->score = 0;
index fdd0f8dc94c14557b2fc366a9d392d831333f0dd..78d67e77cc8dbe01ed43b9c76c1c6e2b8294d38c 100644 (file)
@@ -77,6 +77,10 @@ struct rspamd_metric_result {
        double score;                                                                   /**< total score                                                        */
        double grow_factor;                                                             /**< current grow factor                                        */
        struct rspamd_passthrough_result *passthrough_result;
+       guint npositive;
+       guint nnegative;
+       double positive_score;
+       double negative_score;
        khash_t(rspamd_symbols_hash) *symbols;                  /**< symbols of metric                                          */
        khash_t(rspamd_symbols_group_hash) *sym_groups; /**< groups of symbols                                          */
        gdouble actions_limits[METRIC_ACTION_MAX];              /**< set of actions for this metric                     */