Skip to content

Commit

Permalink
Fix: Align the periods of the graphs in stats, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
ikedas committed Apr 30, 2023
1 parent b0bd991 commit 86dcce2
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 27 deletions.
2 changes: 2 additions & 0 deletions default/web_tt2/serveradmin.tt2
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,9 @@
[% IF subaction == 'stats' ~%]
<h2>[%|loc(domain)%]Virtual domain %1 statistics[%END%]</h2>
<p>[%|loc%]This page displays overall information regarding the activity on this virtual domain.[%END%]</p>
<div class="columns">
[% PROCESS stats.tt2 %]
</div>
[%~ END %]

[% IF subaction == 'translation' %]
Expand Down
20 changes: 6 additions & 14 deletions src/cgi/wwsympa.fcgi.in
Original file line number Diff line number Diff line change
Expand Up @@ -15088,24 +15088,16 @@ sub do_decl_del {
sub do_stats {
wwslog('info', '');

$param->{'shared_size'} =
int((Sympa::WWW::SharedDocument->new($list)->get_size + 512) / 1024);
$param->{'arc_size'} =
int((Sympa::Archive->new(context => $list)->get_size + 512) / 1024);

return _get_stats();
}

sub _get_stats {
my $that;

if (ref $list eq 'Sympa::List') {
$that = $list;

$param->{'shared_size'} =
int(
(Sympa::WWW::SharedDocument->new($that)->get_size + 512) / 1024);
$param->{'arc_size'} =
int(
(Sympa::Archive->new(context => $that)->get_size + 512) / 1024);
} else {
$that = $robot;
}
my $that = (ref $list eq 'Sympa::List') ? $list : $robot;

my $stats = {
send_mail => {title => $language->gettext("Mail sending")},
Expand Down
51 changes: 38 additions & 13 deletions src/lib/Sympa/Log.pm
Original file line number Diff line number Diff line change
Expand Up @@ -625,11 +625,11 @@ sub aggregate_stat {
unless (@res) {
return 0;
}
my $date_deb = $res[0] - ($res[0] % 3600);
my $date_deb = $res[0] - ($res[0] % 900);

# Hour to hour
# By each 15 minutes (some time zones have this time difference).
my @slots;
for (my $i = $date_deb; $i <= $date_end; $i = $i + 3600) {
for (my $i = $date_deb; $i <= $date_end; $i += 900) {
push @slots, $i;
}

Expand Down Expand Up @@ -769,7 +769,7 @@ sub aggregate_daily_data {
return;
}

my $result;
my $result = {};

my $cond;
my @vars;
Expand All @@ -782,6 +782,7 @@ sub aggregate_daily_data {
}

my $sth;

unless (
$sth = $sdm->do_prepared_query(
sprintf(
Expand All @@ -799,22 +800,46 @@ sub aggregate_daily_data {
return;
}
while (my $row = $sth->fetchrow_hashref('NAME_lc')) {
my $midnight = Sympa::Tools::Time::get_midnight_time($row->{'date'});
$result->{$midnight} = 0 unless defined $result->{$midnight};
$result->{$midnight} += $row->{'count'};
_add_count($result, $row->{date}, $row->{count});
}
$sth->finish;

my @dates = sort { $a <=> $b } keys %$result;
return {} unless @dates;

for (my $date = $dates[0]; $date < $dates[-1]; $date += 86400) {
my $midnight = Sympa::Tools::Time::get_midnight_time($date);
$result->{$midnight} = 0 unless defined $result->{$midnight};
if (%{$result || {}}) {
# Fill in zeroes for missing days.
unless (
$sth = $sdm->do_prepared_query(
sprintf(
q{SELECT MIN(beginning_date_counter),
MAX(beginning_date_counter)
FROM stat_counter_table
WHERE %s}, $cond
),
@vars
)
) {
$self->syslog('err', 'Unable to get stat data %s for list %s',
$operation, $that);
return;
}
my ($min, $max) = $sth->fetchrow_array;
for (my $d = $min; $d <= $max; $d += 900) {
_add_count($result, $d, 0);
}
$sth->finish;
}

return $result;
}

sub _add_count {
my $result = shift;
my $date = shift;
my $count = shift;

my $midnight = Sympa::Tools::Time::get_midnight_time($date);
$result->{$midnight} //= 0;
$result->{$midnight} += $count;
}
1;
__END__
Expand Down

0 comments on commit 86dcce2

Please sign in to comment.