}
sub traffic_stat_day_dist {
- my ($self, $rdb, $dir) = @_;
+ my ($self, $rdb) = @_;
my $res;
my ($from, $to) = $self->localhourspan();
- my $p = $dir ? "In" : "Out";
-
- my $spam = $dir ? "sum (SpamIn) + sum (GreylistCount) + sum (SPFCount) + sum (RBLCount)" : "sum (SpamOut)";
- my $cmd = "SELECT sum(Count$p) as count, ((time - $from) / 3600) % 24 AS index, " .
- "sum (Virus$p) as viruscount, $spam as spamcount, sum (Bounces$p) as bounces " .
+ my $cmd = "SELECT " .
+ "((time - $from) / 3600) % 24 AS index, " .
+ "sum(CountIn) as count_in, sum(CountOut) as count_out, " .
+ "sum(VirusIn) as viruscount_in, sum (VirusOut) as viruscount_out, " .
+ "sum(SpamIn) + sum (GreylistCount) + sum (SPFCount) + sum (RBLCount) as spamcount_in, " .
+ "sum(SpamOut) as spamcount_out, " .
+ "sum(BouncesIn) as bounces_in, sum(BouncesOut) as bounces_out " .
"FROM DailyStat WHERE time >= $from AND time < $to " .
"GROUP BY index ORDER BY index";
}
for (my $i = 0; $i < 24; $i++) {
- my $eref = {count => 0, index => $i, spamcount => 0, viruscount => 0, bounces => 0};
- @$res[$i] = $eref if !@$res[$i];
+ @$res[$i] //= {
+ index => $i,
+ count => 0, count_in => 0, count_out => 0,
+ spamcount_in => 0, spamcount_out => 0,
+ viruscount_in => 0, viruscount_out => 0,
+ bounces_in => 0, bounces_out => 0 };
+
+ my $d = @$res[$i];
+ $d->{count} = $d->{count_in} + $d->{count_out};
}
$sth->finish();