cvs: docweb /include lib_general.inc.php /scripts notes_stats.php /www notes_stats.php
[email protected] ("Vincent Gevers")
| Newsgroups | php.doc.web |
|---|---|
| Message-ID | <cvsvincent1107185534@cvsserver> |
vincent Mon Jan 31 10:32:14 2005 EDT
Modified files:
/docweb/include lib_general.inc.php
/docweb/scripts notes_stats.php
/docweb/www notes_stats.php
Log:
Lots of fixes for the Notes stats scripts
vincent-20050131103214.txt
(text/plain, 11.7 KB)
http://cvs.php.net/diff.php/docweb/include/lib_general.inc.php?r1=1.40&r2=1.41&ty=u Index: docweb/include/lib_general.inc.php diff -u docweb/include/lib_general.inc.php:1.40 docweb/include/lib_general.inc.php:1.41 --- docweb/include/lib_general.inc.php:1.40 Tue Jan 25 23:56:54 2005 +++ docweb/include/lib_general.inc.php Mon Jan 31 10:32:11 2005 @@ -18,7 +18,7 @@ | Gabor Hojtsy <[email protected]> | | Sean Coates <[email protected]> | +----------------------------------------------------------------------+ -$Id: lib_general.inc.php,v 1.40 2005/01/26 04:56:54 sean Exp $ +$Id: lib_general.inc.php,v 1.41 2005/01/31 15:32:11 vincent Exp $ */ function is_translation($project, $language) @@ -231,6 +231,7 @@ switch(SITE) { case 'php': $links['orphan-notes'] = BASE_URL . '/orphan_notes.php'; + $links['notes-stats'] = BASE_URL . '/notes_stats.php'; case 'pear': case 'smarty': http://cvs.php.net/diff.php/docweb/scripts/notes_stats.php?r1=1.1&r2=1.2&ty=u Index: docweb/scripts/notes_stats.php diff -u docweb/scripts/notes_stats.php:1.1 docweb/scripts/notes_stats.php:1.2 --- docweb/scripts/notes_stats.php:1.1 Sun Jan 30 16:33:00 2005 +++ docweb/scripts/notes_stats.php Mon Jan 31 10:32:13 2005 @@ -15,20 +15,21 @@ +----------------------------------------------------------------------+ | Authors: Mehdi Achour <[email protected]> (Original Author) | | Vincent Gevers <[email protected]> | -| Credits: Sean Coates <[email protected]> +| Credits: Sean Coates <[email protected]> | +----------------------------------------------------------------------+ -$Id: notes_stats.php,v 1.1 2005/01/30 21:33:00 vincent Exp $ +$Id: notes_stats.php,v 1.2 2005/01/31 15:32:13 vincent Exp $ */ /* - * Warning: This script uses a lot of memory + * Warning: This script can use a lot of memory * * Usage: - * $ php notes_stats.php [mbox-file] > notes.php + * $ php notes_stats.php */ /* * TODO: + * - Use a library * - Database improvements * - Speed improvements * - Nicer layout @@ -39,11 +40,8 @@ // after how many secs should the list be chopped $after = 182.5*24*60*60; // half year -$inputs = array(); // pair subjects w/ dates from multiple sources +$startTime = getmicrotime(); -$time_start = getmicrotime(); - -//$inCli = true; require_once '../build-ops.php'; $DBFile = SQLITE_DIR . 'notes_stats.sqlite'; @@ -67,7 +65,7 @@ ); "; sqlite_query($sqlite, $sqlCreateInfo); -// total user stats (als required for proper working) +// total user stats $sqlCreateStats = " CREATE TABLE @@ -95,7 +93,7 @@ ); "; sqlite_query($sqlite, $sqlCreateStatsOld); -// not more than $after +// newer than $after $sqlCreateStatsNew = " CREATE TABLE @@ -109,6 +107,7 @@ ); "; sqlite_query($sqlite, $sqlCreateStatsNew); +// most active pages $sqlCreateFiles = " CREATE TABLE @@ -148,8 +147,8 @@ $bytesRead = 0; -$s = nntp_connect("news.php.net") or die("failed to connect to news server"); -$res = nntp_cmd($s,"GROUP php.notes",211) or die("failed to get infos on news group"); +$s = nntp_connect("news.php.net") or die("failed to connect to news server\n"); +$res = nntp_cmd($s,"GROUP php.notes",211) or die("failed to get infos on news group\n"); $sql = "SELECT last_article @@ -165,25 +164,26 @@ //$last = 84164; if ($first == $last) - die("Nothing I can do...\n"); + die("Nothing I can do, no new notes available\n"); echo "Fetching items: $first-$last\n"; -$res = nntp_cmd($s,"XOVER $first-$last", 224) or die("failed to XOVER the new items"); +$res = nntp_cmd($s,"XOVER $first-$last", 224) or die("failed to XOVER the new items\n"); $files = $team = $tmp = array(); - -$in_old = false; $tmp['o'] = array(); $tmp['n'] = array(); + +$in_old = false; +$dlStart = getmicrotime(); for ($i = $first; $i < $last; $i++) { $line = fgets($s, 4096); - $GLOBALS['bytesRead'] += strlen($line); + $bytesRead += strlen($line); list($n,$subj,$author,$odate) = explode("\t", $line, 5); if (feof($s)) { - die("EOF\n"); + die("EOF, Please re-run this script\n"); } -echo "$i: $subj @ $odate\n"; + echo "$i: $subj @ $odate\n"; // for debugging /* * What should be matched: @@ -245,8 +245,8 @@ $result = sqlite_query($sqlite, $sql); $users = array(); -while ($row = sqlite_fetch_array($result, SQLITE_ASSOC)) { - $users[] = $row['username']; +while ($users[] = sqlite_fetch_array($result, SQLITE_ASSOC)) { +// nothing here } @@ -375,8 +375,8 @@ $result = sqlite_query($sqlite, $sql); $pages = array(); -while ($row = sqlite_fetch_array($result, SQLITE_ASSOC)) { - $pages[] = $row['page']; +while ($pages[] = sqlite_fetch_array($result, SQLITE_ASSOC)) { +// nothing here } // Manual pages most active top 20 @@ -421,9 +421,9 @@ "; sqlite_query($sqlite, $sql); -$scriptTime = number_format(getmicrotime() - $time_start, 4); -$bytesSec = number_format(round($GLOBALS['bytesRead'] / ($dlDone - $time_start))); -$bytesRead = number_format($bytesRead); +$scriptTime = number_format(getmicrotime() - $startTime, 3); +$bytesSec = number_format(round($bytesRead / ($dlDone - $dlStart))); +$bytesRead = number_format($bytesRead, 1, ',', ''); echo "Completed in $scriptTime seconds\n"; echo "$bytesRead bytes read (~$bytesSec bytes/sec)\n"; @@ -439,15 +439,15 @@ $s = fsockopen($server,$port,$errno,$errstr,30); if (!$s) { - echo "<!-- error connecting to nntp server: $errstr -->\n"; + echo "error connecting to nntp server: $errstr\n"; return false; } $hello = fgets($s, 1024); if (substr($hello,0,4) != "200 ") { - echo "<!-- unexpected greeting: $hello -->\n"; + echo "unexpected greeting: $hello\n"; return false; } - #echo "<!-- $hello -->\n"; + //echo "$hello\n"; return $s; } @@ -455,7 +455,6 @@ if (strlen($command) > 510) die("command too long: $command"); fputs($conn, "$command\r\n"); $res = fgets($conn, 1024); - $GLOBALS['bytesRead'] += strlen($res); list($code,$extra) = explode(" ", $res, 2); return $code == $expected ? $extra : false; } http://cvs.php.net/diff.php/docweb/www/notes_stats.php?r1=1.1&r2=1.2&ty=u Index: docweb/www/notes_stats.php diff -u docweb/www/notes_stats.php:1.1 docweb/www/notes_stats.php:1.2 --- docweb/www/notes_stats.php:1.1 Sun Jan 30 16:33:00 2005 +++ docweb/www/notes_stats.php Mon Jan 31 10:32:14 2005 @@ -15,20 +15,36 @@ +----------------------------------------------------------------------+ | Authors: Vincent Gevers <[email protected]> | +----------------------------------------------------------------------+ -$Id: notes_stats.php,v 1.1 2005/01/30 21:33:00 vincent Exp $ +$Id: notes_stats.php,v 1.2 2005/01/31 15:32:14 vincent Exp $ */ require_once '../include/init.inc.php'; $minact = 100; -$sqlite = sqlite_open(SQLITE_DIR.'notes_stats.sqlite'); +$DBFile = SQLITE_DIR.'notes_stats.sqlite'; + +if (@filesize($DBFile) < 10) { + echo site_header('Statistics not available'); + echo '<h2>Statistics not available</h2>'; + echo site_footer(); + exit; +} + +$sqlite = sqlite_open($DBFile); $sql = "SELECT * FROM notes_info"; $info = sqlite_fetch_array(sqlite_query($sqlite, $sql), SQLITE_ASSOC); +if ($info['subjects'] == 0) { + echo site_header('Statistics not available yet'); + echo '<h2>Statistics not available yet</h2>'; + echo site_footer(); + exit; +} + echo site_header("Note Statistics for ".date('j F Y', $info['build_date'])); -$start = microtime(true); + ?> <h3><strong><?php echo $info['subjects']; ?></strong> subjects parsed</h1> @@ -47,7 +63,7 @@ <?php -$sql = "SELECT * FROM notes_stats"; +$sql = "SELECT * FROM notes_stats ORDER BY total DESC LIMIT 0,$minact"; $tmp = array(); $res = sqlite_query($sqlite, $sql); while($tmp[] = sqlite_fetch_array($res, SQLITE_ASSOC)) { @@ -92,7 +108,7 @@ <?php -$sql = "SELECT * FROM notes_stats_new"; +$sql = "SELECT * FROM notes_stats_new ORDER BY total DESC LIMIT 0,$minact"; $tmp = array(); $res = sqlite_query($sqlite, $sql); while($tmp[] = sqlite_fetch_array($res, SQLITE_ASSOC)) { @@ -106,11 +122,11 @@ echo "<tr bgcolor=\""; $bg = ($bg == '#EBEBEB') ? '#BEBEBE' : '#EBEBEB'; echo "$bg\">\n\t<td>".$c['username']."</td>\n\t<td>"; - echo isset($c['deleted']) ? $c['deleted'] : '0'; + echo $c['deleted']; echo "</td>\n\t<td>"; - echo isset($c['rejected']) ? $c['rejected'] : '0'; + echo $c['rejected']; echo "</td>\n\t<td>"; - echo isset($c['modified']) ? $c['modified'] : '0'; + echo $c['modified']; echo "</td>\n\t<td>"; echo $c['total']; echo "</td>\n</tr>\n"; @@ -137,7 +153,7 @@ <?php -$sql = "SELECT * FROM notes_stats_old"; +$sql = "SELECT * FROM notes_stats_old ORDER BY total DESC LIMIT 0,$minact"; $tmp = array(); $res = sqlite_query($sqlite, $sql); while($tmp[] = sqlite_fetch_array($res, SQLITE_ASSOC)) { @@ -151,11 +167,11 @@ echo "<tr bgcolor=\""; $bg = ($bg == '#EBEBEB') ? '#BEBEBE' : '#EBEBEB'; echo "$bg\">\n\t<td>".$c['username']."</td>\n\t<td>"; - echo isset($c['deleted']) ? $c['deleted'] : '0'; + echo $c['deleted']; echo "</td>\n\t<td>"; - echo isset($c['rejected']) ? $c['rejected'] : '0'; + echo $c['rejected']; echo "</td>\n\t<td>"; - echo isset($c['modified']) ? $c['modified'] : '0'; + echo $c['modified']; echo "</td>\n\t<td>"; echo $c['total']; echo "</td>\n</tr>\n"; @@ -229,7 +245,7 @@ </tr> <?php -$sql = "SELECT username, total FROM notes_stats ORDER BY total DESC"; +$sql = "SELECT username, total FROM notes_stats ORDER BY total DESC LIMIT 0,15"; $tmp = array(); $res = sqlite_query($sqlite, $sql); while($tmp[] = sqlite_fetch_array($res, SQLITE_ASSOC)) { @@ -237,16 +253,16 @@ } $i = 0; - foreach($tmp as $id => $c) { +foreach($tmp as $id => $c) { - $i++; - echo "<tr bgcolor=\""; - $bg = ($bg == '#EBEBEB') ? '#BEBEBE' : '#EBEBEB'; - echo "$bg\">\n\t". - "<td>".$i."</td>\n\t". - "<td>".$c['username']."</td>\n\t". - "<td>".$c['total']."</td>\n". - "</tr>\n"; + $i++; + echo "<tr bgcolor=\""; + $bg = ($bg == '#EBEBEB') ? '#BEBEBE' : '#EBEBEB'; + echo "$bg\">\n\t". + "<td>".$i."</td>\n\t". + "<td>".$c['username']."</td>\n\t". + "<td>".$c['total']."</td>\n". + "</tr>\n"; if ($i == 15) break; @@ -267,7 +283,7 @@ </tr> <?php -$sql = "SELECT * FROM notes_files ORDER BY total DESC"; +$sql = "SELECT * FROM notes_files ORDER BY total DESC LIMIT 0,20"; $tmp = array(); $res = sqlite_query($sqlite, $sql); while($tmp[] = sqlite_fetch_array($res, SQLITE_ASSOC)) { @@ -275,16 +291,16 @@ } $i = 0; - foreach($tmp as $id => $c) { +foreach($tmp as $id => $c) { - $i++; - echo "<tr bgcolor=\""; - $bg = ($bg == '#EBEBEB') ? '#BEBEBE' : '#EBEBEB'; - echo "$bg\">\n\t". - "<td>$i</td>\n\t". - "<td>".$c['page']."</td>\n\t". - "<td>".$c['total']."</td>\n". - "</tr>\n"; + $i++; + echo "<tr bgcolor=\""; + $bg = ($bg == '#EBEBEB') ? '#BEBEBE' : '#EBEBEB'; + echo "$bg\">\n\t". + "<td>".$i."</td>\n\t". + "<td>".$c['page']."</td>\n\t". + "<td>".$c['total']."</td>\n". + "</tr>\n"; if ($i == 20) break; @@ -295,9 +311,8 @@ </td></tr></table> <?php -sqlite_close($sqlite); -$total = microtime(true) - $start; -echo 'Took me ' . number_format($total, 4) . " seconds<br />\n"; + echo 'Last updated ' . date('r', $info['build_date']) . "\n"; +sqlite_close($sqlite); echo site_footer();