Skip to content

Commit

Permalink
Add messaging stats
Browse files Browse the repository at this point in the history
  • Loading branch information
pudge committed Feb 11, 2003
1 parent 845ac84 commit 64f288a
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
46 changes: 46 additions & 0 deletions plugins/Messages/populate_message_log_stats.plx
@@ -0,0 +1,46 @@
#!/usr/bin/perl -w
# run this to generate stats for existing log entries
#
# perl populate_message_log_stats.plx VIRTUAL_USER
#
# you probably only want to run it once, but running it multiple times
# shouldn't hurt anything

use strict;
use Slash::Test shift;
my $messages = getObject('Slash::Messages');
my $x = shift || 60;

for (my $n = 0; $n < $x; $n++) {
my @time1 = localtime( time() - (86400 * (1 + $n)) );
my $date1 = sprintf "%4d%02d%02d000000", $time1[5] + 1900, $time1[4] + 1, $time1[3];

my @time2 = localtime( time() - (86400 * $n) );
my $date2 = sprintf "%4d%02d%02d000000", $time2[5] + 1900, $time2[4] + 1, $time2[3];

my $table = $messages->{_log_table};
my $msg_log = $messages->sqlSelectAll(
'code, mode, count(*) as count',
$table,
"date >= '$date1' AND date < '$date2'",
"GROUP BY code, mode"
);


my $statsSave = getObject('Slash::Stats::Writer', { nocache => 1 }, {
day => sprintf("%4d-%02d-%02d", $time1[5] + 1900, $time1[4] + 1, $time1[3])
});

my %msg_codes;
for my $type (@$msg_log) {
my($code, $mode, $count) = @$type;
$msg_codes{$code} += $count;
$statsSave->createStatDaily("msg_${code}_${mode}", $count);
}

for my $code (keys %msg_codes) {
$statsSave->createStatDaily("msg_${code}", $msg_codes{$code});
}

printf "%s : %s : %d\n", $date1, $date2, scalar @$msg_log;
}
20 changes: 19 additions & 1 deletion plugins/Stats/adminmail.pl
Expand Up @@ -486,8 +486,26 @@
Return => 1, Page => 'modmail', Nocomm => 1
}) if $constants->{mod_stats};

# Send a message to the site admin.
my $messages = getObject('Slash::Messages');

# do message log stuff
if ($messages) {
my $msg_log = $messages->getDailyLog( $statsSave->{_day} );
my %msg_codes;

# msg_12_1 -> code 12, mode 1 (relationship change, web)
for my $type (@$msg_log) {
my($code, $mode, $count) = @$type;
$msg_codes{$code} += $count;
$statsSave->createStatDaily("msg_${code}_${mode}", $count);
}

for my $code (keys %msg_codes) {
$statsSave->createStatDaily("msg_${code}", $msg_codes{$code});
}
}

# Send a message to the site admin.
if ($messages) {
$data{template_name} = 'display';
$data{subject} = getData('email subject', {
Expand Down

0 comments on commit 64f288a

Please sign in to comment.