From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 164FA91C19 for ; Mon, 27 Mar 2023 16:53:57 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E7143C60F for ; Mon, 27 Mar 2023 16:53:56 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Mon, 27 Mar 2023 16:53:56 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 4568846FDC for ; Mon, 27 Mar 2023 16:53:56 +0200 (CEST) From: Dominik Csapak To: pmg-devel@lists.proxmox.com Date: Mon, 27 Mar 2023 16:53:54 +0200 Message-Id: <20230327145355.444827-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.010 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pmg-devel] [PATCH pmg-api 1/2] statistics: spamscores: fix total count when there is outgoing spam X-BeenThere: pmg-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Mail Gateway development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Mar 2023 14:53:57 -0000 We used 'count_in' as total value, but the spamlevel counts also counted outgoing mails, so we could have weird stats with negative mails. To fix that, we simply count all mails, incoming and outgoing. Signed-off-by: Dominik Csapak --- src/PMG/API2/Statistics.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/PMG/API2/Statistics.pm b/src/PMG/API2/Statistics.pm index 38c8d0c..051265b 100644 --- a/src/PMG/API2/Statistics.pm +++ b/src/PMG/API2/Statistics.pm @@ -1057,7 +1057,7 @@ __PACKAGE__->register_method ({ my $res = []; - my $count_in = $totalstat->{count_in}; + my $total = $totalstat->{count_in} + $totalstat->{count_out}; my $levelcount = {}; my $spamcount = 0; @@ -1070,11 +1070,11 @@ __PACKAGE__->register_method ({ } } - $levelcount->{0} = $count_in - $spamcount; + $levelcount->{0} = $total - $spamcount; for (my $i = 0; $i <= 10; $i++) { my $count = $levelcount->{$i} // 0; - my $ratio = $count_in ? $count/$count_in : 0; + my $ratio = $total ? $count/$total : 0; push @$res, { level => $i, count => $count, ratio => $ratio }; } -- 2.30.2