1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
##############################################################################
# The Faq-O-Matic is Copyright 1997 by Jon Howell, all rights reserved. #
# #
# This program is free software; you can redistribute it and/or #
# modify it under the terms of the GNU General Public License #
# as published by the Free Software Foundation; either version 2 #
# of the License, or (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the Free Software #
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.#
# #
# Jon Howell can be contacted at: #
# 6211 Sudikoff Lab, Dartmouth College #
# Hanover, NH 03755-3510 #
# jonh@cs.dartmouth.edu #
# #
# An electronic copy of the GPL is available at: #
# http://www.gnu.org/copyleft/gpl.html #
# #
##############################################################################
use strict;
package FAQ::OMatic::stats;
use CGI;
use FAQ::OMatic::Item;
use FAQ::OMatic;
use FAQ::OMatic::Log;
use FAQ::OMatic::I18N;
sub main {
my $cgi = FAQ::OMatic::dispatch::cgi();
my $rt = '';
my $params = FAQ::OMatic::getParams($cgi);
$params->{'duration'} = '' if (not defined($params->{'duration'}));
my $simpleHTML = $params->{'simpleHTML'};
# make sure today is summarized in a .smry file
FAQ::OMatic::Log::summarizeDay(FAQ::OMatic::Log::numericToday());
# check history now that today is summarized (so there's at least 1 .smry)
if ($params->{'duration'} eq 'history') {
# tickle the earliestLogHint file so all 8 graph CGIs
# don't try to do so simultaneously.
FAQ::OMatic::Log::earliestSmry();
}
# get today's stats for the text part of the display
my $today = $params->{'today'} || '';
$today =~ m/([\d-]*)/; # sanitize user input before treating it as a path
$today = $1;
if (not -e "$FAQ::OMatic::Config::metaDir/$today.smry") {
$today = FAQ::OMatic::Log::numericToday();
}
my $todayItem = new FAQ::OMatic::Item("$today.smry", $FAQ::OMatic::Config::metaDir);
# The list of properties and corresponding titles
my @props = ('Hits', 'CumHits');
my @titles = (gettext("Hits Per Day"),
gettext("Cumulative Hits"));
if ($FAQ::OMatic::Config::statUniqueHosts) {
push @props, ('UniqueHosts', 'CumUniqueHosts');
push @titles, (gettext("New Hosts Per Day"),
gettext("Total Hosts"));
}
push @props, ('HitsPerHost', 'CumOperation-search');
push @titles, (gettext("Hits Per Host"),
gettext("Cumulative Searches"));
push @props, ('Operation-submitPart', 'CumOperation-submitPart');
push @titles, (gettext("Submissions Per Day"),
gettext("Cumulative Submissions"));
$rt.= FAQ::OMatic::pageHeader($params);
$rt.= gettext("Please be patient ... the image files are generated dynamically, and can take from 20 to 50 seconds to create.\n");
$rt.="<table>" if (!$simpleHTML);
my $i;
for ($i=0; $i<@props; $i++) {
my $url = FAQ::OMatic::makeAref('statgraph',
{'property'=>$props[$i],
'title'=>$titles[$i],
'duration'=>$params->{'duration'},
'resolution'=>$params->{'resolution'},
'today'=>$params->{'today'}}, 'url');
if ($i & 0x01) {
# before the second graph of a pair
$rt .= $simpleHTML ?
"" :
"<td align=center>\n";
} else {
# before a pair
$rt .= $simpleHTML ?
"" :
"<tr><td align=center>\n";
}
$rt .= "<img src=\"$url\" "
."width=$FAQ::OMatic::Appearance::graphWidth "
."height=$FAQ::OMatic::Appearance::graphHeight>";
my $value = niceValue($todayItem->{$props[$i]});
$rt .= "<br>".$titles[$i].": ".$value."\n";
if ($i & 0x01) {
# after a pair
$rt .= $simpleHTML ?
"<p>" :
"</td></tr>\n";
} else {
# after the first graph of a pair
$rt .= $simpleHTML ?
"<p>" :
"</td>\n";
}
}
$rt.="</table>" if (!$simpleHTML);
$rt.=FAQ::OMatic::button(FAQ::OMatic::makeAref('faq',
{'duration'=>'','resolution'=>'','today'=>''}),
gettext("Return to the FAQ"));
# let the user change the view
$rt.=" "
. gettext("Change View Duration")
. ": ";
$rt.=FAQ::OMatic::button(FAQ::OMatic::makeAref('stats',
{'duration'=>'30'}), gettext("One Month"));
$rt.=FAQ::OMatic::button(FAQ::OMatic::makeAref('stats',
{'duration'=>'60'}), gettext("Two Months"));
$rt.=FAQ::OMatic::button(FAQ::OMatic::makeAref('stats',
{'duration'=>'90'}), gettext("Three Months"));
$rt.=FAQ::OMatic::button(FAQ::OMatic::makeAref('stats',
{'duration'=>'history'}), gettext("History"));
$rt .= FAQ::OMatic::pageFooter($params);
print $rt;
}
sub niceValue {
my $value = shift || '';
$value = 0 if ($value eq '');
if (not $value =~ m/\./) {
# for big numbers
$value =~ s/(?!^|,)(\d\d\d)$/,$1/; # add commas for readability
$value =~ s/(?!^|,)(\d\d\d),/,$1,/; # of big numbers. This'll keep you
$value =~ s/(?!^|,)(\d\d\d),/,$1,/; # til your trillionth hit. :v)
} else {
# for little numbers
$value = sprintf "%.2f", $value;
}
return $value;
}
1;
|