cvs: pearbot /modules bugstats.php

From: Date: Mon, 21 Aug 2006 17:23:39 +0000
Subject: cvs: pearbot /modules bugstats.php
Groups: php.pear.bot 
Request: Send a blank email to pear-bot+get-53@lists.php.net to get a copy of this message
amir Mon Aug 21 17:23:39 2006 UTC Modified files: /pearbot/modules bugstats.php Log: Ratio http://cvs.php.net/viewvc.cgi/pearbot/modules/bugstats.php?r1=1.11&r2=1.12&diff_format=u Index: pearbot/modules/bugstats.php diff -u pearbot/modules/bugstats.php:1.11 pearbot/modules/bugstats.php:1.12 --- pearbot/modules/bugstats.php:1.11 Sun May 7 19:01:48 2006 +++ pearbot/modules/bugstats.php Mon Aug 21 17:23:39 2006 @@ -1,25 +1,27 @@ <?php /** - * $Id: bugstats.php,v 1.11 2006/05/07 19:01:48 meebey Exp $ - * $Revision: 1.11 $ - * $Author: meebey $ - * $Date: 2006/05/07 19:01:48 $ + * $Id: bugstats.php,v 1.12 2006/08/21 17:23:39 amir Exp $ + * $Revision: 1.12 $ + * $Author: amir $ + * $Date: 2006/08/21 17:23:39 $ * * Copyright (c) 2004 Tobias Schlitt <toby@php.net> & Mirco Bauer <meebey@php.net> */ require_once "HTTP/Request.php"; +require_once "PEAR/XMLParser.php"; class Net_SmartIRC_module_bugstats { - var $name = 'bugstats'; - var $description = '!bugstats command'; - var $author = 'Tobias Schlitt <toby@php.net> & Mirco Bauer <meebey@php.net>'; - var $version = '$Revision: 1.11 $'; - var $license = 'LGPL'; + var $name = 'bugstats'; + var $description = '!bugstats command'; + var $author = 'Tobias Schlitt <toby@php.net> & Mirco Bauer <meebey@php.net> & Amir Mohammad Saied <amir@php.net>'; + var $version = '$Revision: 1.12 $'; + var $license = 'LGPL'; - var $lastCount = 0; - var $timeout = 900000; + var $lastCount = 0; + var $lastPackagesCount = 0; + var $timeout = 900000; var $actionids = array(); var $timeids = array(); @@ -40,18 +42,21 @@ function bugstats(&$irc, &$data) { - $count = $this->getStats(); + $count = $this->getStats(); + $packages = $this->getTotalPackages(); + $ratio = round($count/$packages, 2); if (PEAR::isError($count) || !$count) { $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $count->getMessage()); return; } - $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $data->nick.': Current bug count is '.$count); + $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $data->nick.': Current bug count is '.$count. ' ('.$ratio.' bugs/package)'); $this->updateTopic($irc); } function updateTopic(&$irc) { - $count = $this->getStats(); + $count = $this->getStats(); + $packages = $this->getTotalPackages(); if (PEAR::isError($count) || !$count) { return $count; } @@ -63,10 +68,12 @@ } else { $oldBugCount = "Sorry, I was not able to determine the old bug count."; } - $topic = preg_replace('/[\| ]*[0-9]+ open bugs/isU', '', $topic); - if ($this->lastCount != $count) { + $topic = preg_replace('/[\| ]*[0-9]+ open bugs \([0-9.]+ bugs\/package\)/isU', '', $topic); + if ($this->lastCount != $count || $this->lastPackagesCount != $packages) { $this->lastCount = $count; - $irc->setTopic('#pear', $topic.' | '.$count.' open bugs'); + $this->lastPackagesCount = $packages; + $ratio = round($count/$packages, 2); + $irc->setTopic('#pear', $topic.' | '.$count.' open bugs ('.$ratio.' bugs/package)'); $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $oldBugCount); } } @@ -80,5 +87,23 @@ } return (int)$req->getResponseBody(); } + + function getTotalPackages() + { + $req =& new HTTP_Request('http://pear.php.net/rest/p/packages.xml'); + $result = $req->sendRequest(); + if (PEAR::isError($result)) { + return PEAR::raiseError('Error fetching packages XML file: '.$result->getMessage(), 0); + } + $content = $req->getResponseBody(); + $parser = new PEAR_XMLParser; + $err = $parser->parse($content); + if (PEAR::isError($err)) { + return PEAR::raiseError('Invalid XML file: '.$err->getMessage(), 0); + } + $content = $parser->getData(); + + return count($content['p']); + } } ?>

« previous php.pear.bot (#53) next »