Statistics
body<=
Statistics h1?>
here.
p?>
prepare("SELECT statcat, statkey, statval FROM stats WHERE statcat IN ('userinfo', 'client', 'age', 'gender', 'account', 'size')");
$sth->execute;
while ($_ = $sth->fetchrow_hashref) {
$stat{$_->{'statcat'}}->{$_->{'statkey'}} = $_->{'statval'};
}
unless (%stat) {
return "ljmaint.pl genstats, or ideally, put it in cron to run nightly. p?>";
}
$sth = $dbr->prepare("SELECT c.item, s.statval FROM stats s, codes c WHERE c.type='country' AND s.statcat='country' AND s.statkey=c.code ORDER BY s.statval DESC LIMIT 15");
$sth->execute;
while ($_ = $sth->fetchrow_hashref) {
$stat{'country'}->{$_->{'item'}} = $_->{'statval'};
}
$sth = $dbr->prepare("SELECT c.item, s.statval FROM stats s, codes c WHERE c.type='state' AND s.statcat='stateus' AND s.statkey=c.code ORDER BY s.statval DESC LIMIT 15");
$sth->execute;
while ($_ = $sth->fetchrow_hashref) {
$stat{'state'}->{$_->{'item'}} = $_->{'statval'};
}
my $total = $stat{'userinfo'}->{'total'}+0;
my $usedever = $stat{'userinfo'}->{'updated'}+0;
my $used30 = $stat{'userinfo'}->{'updated_last30'}+0;
my $used7 = $stat{'userinfo'}->{'updated_last7'}+0;
my $usedlastday = $stat{'userinfo'}->{'updated_last1'}+0;
my $allow_getljnews = $stat{'userinfo'}->{'allow_getljnews'}+0;
my $active = $stat{'size'}->{'accounts_active'}+0;
my $ret = "";
$ret .= "\n";
$ret .= "
";
$ret .= "- Total accounts: $total
\n";
$ret .= "- ... active in some way: $active
\n" if $active;
$ret .= "- ... that have ever updated: $usedever
\n";
$ret .= "- ... updating in last 30 days: $used30
\n";
$ret .= "- ... updating in last 7 days: $used7
\n";
$ret .= "- ... updating in past 24 hours: $usedlastday
\n";
$ret .= "
\n";
$ret .= "\n";
$ret .= "";
{
my $male = $stat{'gender'}->{'M'}+0;
my $female = $stat{'gender'}->{'F'}+0;
my $tot = $male+$female;
$tot ||= 1;
$ret .= "- Male: $male (" . sprintf("%0.1f", $male*100/($tot||1)) . "%)
";
$ret .= "- Female: $female (" . sprintf("%0.1f", $female*100/($tot||1)) . "%)
";
}
$ret .= "- Unspecified: " . ($stat{'gender'}->{'U'}+0) . "
";
$ret .= "
\n";
LJ::run_hook('statspage', {
stat => \%stat,
ret => \$ret,
});
unless ($LJ::DISABLED{'stats-recentupdates'})
{
$ret .= "\n";
$ret .= "";
$sth = $dbr->prepare("SELECT u.user, u.name, uu.timeupdate FROM user u, userusage uu WHERE u.userid=uu.userid AND uu.timeupdate > DATE_SUB(NOW(), INTERVAL 30 DAY) ORDER BY uu.timeupdate DESC LIMIT 10");
$sth->execute;
my $ct;
while (my ($iuser, $iname, $itime) = $sth->fetchrow_array) {
$ret .= "- , $itime
\n";
$ct++;
}
$ret .= "- stat not available
" unless $ct;
$ret .= "
\n";
}
unless ($LJ::DISABLED{'stats-newjournals'})
{
$ret .= "\n";
$ret .= "";
$sth = $dbr->prepare("SELECT u.user, u.name, uu.timeupdate FROM user u, userusage uu WHERE u.userid=uu.userid AND uu.timeupdate IS NOT NULL ORDER BY uu.timecreate DESC LIMIT 10");
$sth->execute;
my $ct;
while (my ($iuser, $iname, $itime) = $sth->fetchrow_array) {
$ret .= "- , $itime
\n";
$ct++;
}
$ret .= "- stat not available
" unless $ct;
$ret .= "
\n";
}
$ret .= "\n";
{
$ret .= "";
my $ct;
foreach my $key (sort { $stat{'country'}->{$b} <=> $stat{'country'}->{$a} }
keys %{$stat{'country'}})
{
$ret .= "- $key - $stat{'country'}->{$key}
\n";
$ct++;
}
$ret .= "- stat not available
" unless $ct;
$ret .= "
\n";
}
{
$ret .= "The following are the 15 most popular U.S. states $LJ::SITENAMESHORT is used in: ";
my $ct;
foreach my $key (sort { $stat{'state'}->{$b} <=> $stat{'state'}->{$a} } keys %{$stat{'state'}})
{
$ret .= "- $key - $stat{'state'}->{$key}
\n";
$ct++;
}
$ret .= "- stat not available
" unless $ct;
$ret .= "
\n";
}
# ages
my %age = ();
my $maxage = 1;
foreach my $key (keys %{$stat{'age'}}) {
$age{$key} = $stat{'age'}->{$key};
if ($stat{'age'}->{$key} > $maxage) { $maxage = $stat{'age'}->{$key}; }
}
my @ages = grep { $_ >= 13 && $_ <= 55 } sort { $a <=> $b } sort keys %age;
if (@ages) {
$ret .= "\n";
$ret .= "\n";
my $lastage = 0;
foreach my $age (@ages) {
my $width = int(400 * $age{$age}/$maxage);
$ret .= "$age | $age{$age} | |
\n";
$lastage = $_;
}
$ret .= "
\n";
}
# clients (if enabled)
unless ($LJ::DISABLED{'clientversionlog'}) {
### sum up clients over different versions
foreach my $c (keys %{$stat{'client'}}) {
next unless ($c =~ /^(.+?)\//);
$stat{'clientname'}->{$1} += $stat{'client'}->{$c};
}
my $out;
foreach my $cn (sort { $stat{'clientname'}->{$b} <=> $stat{'clientname'}->{$a} }
keys %{$stat{'clientname'}})
{
last unless $stat{'clientname'}->{$cn} >= 50;
$out .= "$stat{'clientname'}->{$cn} | ".
"" . LJ::ehtml($cn) . " \n";
$out .= "\n";
foreach my $c (sort grep { /^\Q$cn\E\// } keys %{$stat{'client'}}) {
my $count = $stat{'client'}->{$c};
$c =~ s/^\Q$cn\E\///;
$out .= LJ::ehtml($c) . " ($count), ";
}
chop $ret; chop $ret; # remove trailing ", "
$out .= "\n";
$out .= " |
\n";
}
if ($out) {
$ret .= "\n";
$ret .= "\n";
$ret .= $out;
$ret .= "
\n";
}
}
# return early, since the graphs below are pretty much broken now
# with index changes. FIXME: make alternate means to generate stats
return $ret;
### graphs!
$ret .= "";
$ret .= "";
$ret .= "";
$ret .= "";
$ret .= "";
$ret .= "";
$ret .= "";
return $ret;
_code?>
<=body
page?>
link: htdocs/stats/, htdocs/support/faqbrowse.bml
img: htdocs/img/bluedot.gif, htdocs/stats/postsbyday.png, htdocs/stats/postsbyweek.png, htdocs/stats/newbyday.png
_c?>