3
function mycmp($v1,$v2)
6
if ($v1[$sortfield] == $v2[$sortfield]) return 0;
7
return ($v1[$sortfield] > $v2[$sortfield]) ? -1 : 1;
10
function sortmydata(&$data, $field)
14
uasort(&$data, "mycmp");
19
$channel = "#ctrlproxy";
21
$fd = popen("../printstats /home/jelmer/.ctrlproxy-stats.tdb", "r");
25
preg_match("'([^/]*)\/([^/]*)\/([^/]*)\\/([^/]*): ([0-9]+)'", $v, $regs);
26
if($regs[0] == "")continue;
27
$data[$regs[1]][$regs[2]][$regs[3]][$regs[4]] = $regs[5];
32
/* Okay, all data has been read. Now build a nice page based on it. */
34
$mydata = $data[$network][$channel];
36
/* Add some statistics to the array */
38
while(list($k,$v) = each($mydata)) {
39
if($v["lines"] == 0 || $v["words"] == 0)continue;
40
$mydata[$k]["avg_words_per_line"] = $v["words"] / $v["lines"];
41
$mydata[$k]["avg_chars_per_line"] = $v["chars"] / $v["lines"];
47
<title><?=$channel;?> @ <?=$network;?> stats by ctrlproxy</title>
49
<body bgcolor="#ffffff">
51
<h1><?=$channel;?> @ <?=$network;?> stats by ctrlproxy</h1>
53
<? if(isset($extended)) { ?>
58
<? if($extended == "lines") { ?>
60
<tr><td></td><td><b>Nick</b></td><td><b>Lines</b></td><td><b>Words</b></td></tr>
61
<? sortmydata($mydata, "lines");
62
reset($mydata);$i = 0;
63
while(list($k,$v) = each($mydata)) {
66
print "<tr><td>$i</td><td>$k</td><td>" . $v["lines"] . "</td><td>" . $v["words"] . "</td></tr>\n";
68
?><p>Total lines: <?=$mydata[""]["lines"];
72
<tr><td></td><td><b>Nick</b></td><td><b><?=$extended;?></b></td></tr>
73
<? sortmydata($mydata, $extended);
74
reset($mydata);$i = 0;
75
while(list($k, $v) = each($mydata)) {
78
print "<tr><td>$i</td><td>$k</td><td>" . $v[$extended] . (isset($showprcnt)?(" (" . round($v[$extended] / $v["lines"] * 100) . "%)"):"") . "</td></tr>\n";
89
$fields["lines"] = array("title" => "Lines", "desc1" => "%s wrote the most lines: %d", "desc2" => "%s wrote almost as much lines: %d");
90
$fields["foul"] = array("title" => "Foul Language", "desc1" => "%s makes sailors blush", "desc2" => "%s has a potty mouth as well");
91
$fields["happy"] = array("title" => "Happy", "desc1" => "%s is the happiest person on the channel", "desc2" => "%s is quite happy as well");
92
$fields["unhappy"] = array("title" => "Unhappy", "desc1" => "%s is the saddest person on the channel", "desc2" => "%s is quite sad as well");
95
function expand_desc($desc, $k, $v)
97
return strtr($desc, array("%s" => $k, "%d" => $v));
101
while(list($k,$v) = each($fields)) {
102
sortmydata($mydata, $k);
104
echo "<h3>" . $v["title"] . "</h3>\n";
105
list($k1,$v1) = each($mydata);
106
if(isset($v["desc1"])) echo "<p>" . expand_desc($v["desc1"], $k1, $v1[$k]) . "\n";
107
list($k1,$v1) = each($mydata);
108
if(isset($v["desc2"])) echo "<p>" . expand_desc($v["desc2"], $k1, $v1[$k]) . "\n";
109
echo "<p><a href='$PHP_SELF?extended=$k&title=" . urlencode($v["title"]) . (isset($v["showpercent"])?"&showprcnt=1":"") . "'>...</a>";