diff -u -r -N yasuck-0.0.5.orig/docs/ChangeLog yasuck-0.0.5/docs/ChangeLog --- yasuck-0.0.5.orig/docs/ChangeLog 2004-09-29 14:52:37.000000000 -0500 +++ yasuck-0.0.5/docs/ChangeLog 2004-09-29 16:49:31.093541792 -0500 @@ -2,9 +2,18 @@ # Copyright (c)2004 badpenguins.com; Distributed under the GPL v2 # +*yasuck-0.0.6 (29 Sep 2004) + *yasuck-0.0.5 (24 Sep 2004) - 29 Sep 2004: Mike Green docs/Changelog, + 29 Sep 2004: Mike Green docs/ChangeLog, + includes/app.functions.php, yasuck, patch-0.0.5-02: + + Added poster stats table and --refresh argument to go along with it. Keeps + track of number of posts, number of recs, highest recs, average recs, etc.. + Added code to upgrade tables automatically. Bumped version up to 0.0.6. + + 29 Sep 2004: Mike Green docs/ChangeLog, includes/app.functions.php, includes/globals.php, yasuck, patch-0.0.5-01: Added --merge to merge another database into the existing one. Started diff -u -r -N yasuck-0.0.5.orig/includes/app.functions.php yasuck-0.0.5/includes/app.functions.php --- yasuck-0.0.5.orig/includes/app.functions.php 2004-09-29 14:34:59.000000000 -0500 +++ yasuck-0.0.5/includes/app.functions.php 2004-09-29 16:44:56.083349696 -0500 @@ -118,7 +118,17 @@ define(RECSALL,false); $j--; } - define(ACTION,"refresh"); + define(ACTION,"refreshrecs"); + define(BOARD,$board); + break; + case "--refresh": + if (defined('ACTION')) { return false; } + if (defined('BOARD')) { return false; } + $j++; + $board = $args[$j]; + if (empty($board)) { return false; } + if (substr($board,0,2) == "--") { return false; } + define(ACTION,"refreshstats"); define(BOARD,$board); break; case "--sanity": @@ -380,6 +390,7 @@ $sql = array(); $sql[] = "delete from message_ids where board_id=$board_id"; $sql[] = "delete from board_ids where board_id=$board_id"; +$sql[] = "delete from poster_stats where board_id=$board_id"; foreach($sql as $query) { if (!db_query($query)) { @@ -498,6 +509,7 @@ --poster POSTER Only retrieve messages posted by POSTER --quiet No non-error messages displayed while running --recs BOARD [all] Update recommendation counters only + --refresh BOARD Refresh post/rec statistics for board BOARD --sanity Run sanity check and display results --skipmsgs Don't import messages (subject/poster only) --start MSG Start with message number MSG (optional) @@ -610,12 +622,21 @@ KEY thread_id (thread_id), KEY message_date (message_date))"; +$poster_stats = "create table " . DBN . ".poster_stats ( +board_id int(10) unsigned NOT NULL default '0', +poster_id int(10) unsigned NOT NULL default '0', +posts_total int(10) unsigned NOT NULL default '0', +recs_total int(10) unsigned NOT NULL default '0', +recs_high int(10) unsigned NOT NULL default '0', +recs_avg int(10) unsigned NOT NULL default '0', +PRIMARY KEY (board_id,poster_id))"; + $sql = array(); $sql[] = "drop database if exists " . DBN; $sql[] = "create database " . DBN; $sql[] = $board_ids; $sql[] = $poster_ids; -//$sql[] = $thread_ids; +$sql[] = $poster_stats; $sql[] = $message_ids; foreach($sql as $query) { @@ -932,6 +953,9 @@ } else { echo "Updated counters\n"; } + if (!refreshStats($board_name)) { + echo "Failed to update stats\n"; + } } } @@ -1559,6 +1583,86 @@ /***************************************************************************** * * *****************************************************************************/ +function refreshStats($board_name='') { + +if ($board_name == '') { + echo "What board do you want to refresh stats for?"; + return false; + } +if (!checkDatabase()) { + echo "checkStatus(): checkDatabase() failure\n"; + return false; + } +$info_ar = queryBoardInfo($board_name,false); +if ($info_ar === false or !is_array($info_ar)) { + echo "queryBoardInfo() failed\n"; + return false; + } +$board_id = addslashes($info_ar['board_id']); + +$sql = "select distinct poster_id from message_ids where board_id=$board_id "; +$sql .= "order by poster_id"; +if (!$qid = db_query($sql)) { return false; } +$num = db_num_rows($qid); +if ($num < 1) { + echo "ERROR: no messages for board $board_name?\n"; + return false; + } + +$poster_ar = array(); +for ($j=0; $j < $num; $j++) { + $poster_ar[] = db_result($qid,$j,0); + } +db_free_result($qid); +echo "Refreshing stats for " . count($poster_ar) . " posters\n"; +// note - replace into probably is not portable! +foreach($poster_ar as $pid) { + $sql = "select count(message_id), sum(message_recs), max(message_recs) "; + $sql .= "from message_ids where board_id=$board_id and poster_id=$pid"; + if (!$qid = db_query($sql) or + db_num_rows($qid) !== 1) { + echo "ERROR: querying posts for poster_id $pid\n"; + continue; + } + $posts = db_result($qid,0,0); + $recs_total = db_result($qid,0,1); + $recs_high = db_result($qid,0,2); + + if ($recs_total > 0) { + $sql = "select count(message_id) from message_ids "; + $sql .= "where board_id=$board_id and poster_id=$pid and "; + $sql .= "message_recs > 0"; + if (! $qid = db_query($sql) or db_num_rows($qid) !== 1) { + echo "ERROR: $sql\n"; + continue; + } + $num = db_result($qid,0,0); + $recs_avg = round($recs_total / $num); + } else { + $recs_avg = 0; + } + + if (DEBUG) { + $msg = "P: $pid POSTS: $posts RECS(total): $recs_total RECS(high) "; + $msg .= "$recs_high RECS(avg): $recs_avg\n"; + echo $msg; + } + + $sql = "replace into poster_stats(board_id,poster_id,posts_total,"; + $sql .= "recs_total,recs_high,recs_avg) "; + $sql .= "values($board_id,$pid,$posts,$recs_total,$recs_high,$recs_avg)"; + if (!db_query($sql)) { + echo "ERROR: failed to update stats for poster $pid\n"; + } + } + +return true; + +} + +/***************************************************************************** + * * + *****************************************************************************/ function retrieveList($board_name='',$start='') { if ($board_name == '') { return false; } @@ -1612,7 +1716,7 @@ } } if (!$has_recs) { - echo "INFO: Upgrading message_ids: adding message_recs column\n"; + echo "UPGRADE: Upgrading message_ids: adding message_recs column\n"; $sql = "alter table " . DBN . ".message_ids add message_recs "; $sql .= "int(5) unsigned default '0' after message_subject"; if (!db_query($sql)) { @@ -1621,6 +1725,41 @@ } } +$has_stats = false; +$sql = "show tables from " . DBN; +if (!$qid = db_query($sql)) { + echo "ERROR: Upgrade failure - cannot list tables\n"; + return false; + } +$num = db_num_rows($qid); +if ($num < 1) { + echo "ERROR: Upgrade failure - no tables found\n"; + return false; + } +for($j=0; $j < $num; $j++) { + if (db_result($qid,$j,0) == "poster_stats") { + $has_stats = true; + break; + } + } + +if ($has_stats !== true) { + $sql = "create table " . DBN . ".poster_stats ("; + $sql .= "board_id int(10) unsigned NOT NULL default '0',"; + $sql .= "poster_id int(10) unsigned NOT NULL default '0',"; + $sql .= "posts_total int(10) unsigned NOT NULL default '0',"; + $sql .= "recs_total int(10) unsigned NOT NULL default '0',"; + $sql .= "recs_high int(10) unsigned NOT NULL default '0',"; + $sql .= "recs_avg int(10) unsigned NOT NULL default '0',"; + $sql .= "PRIMARY KEY (board_id,poster_id))"; + if (!db_query($sql)) { + echo "ERROR: Upgrade failure - could not create table poster_stats\n"; + return false; + } else { + echo "UPGRADE: created table poster_stats\n"; + } + } + return true; } @@ -1840,6 +1979,12 @@ processMessage($board_id,$j,$page); } +if (DRYRUN !== true) { + if (!refreshStats($board_name)) { + echo "Failed to update stats\n"; + } + } + return true; } @@ -1996,6 +2141,12 @@ } } +if (DRYRUN !== true) { + if (!refreshStats($board_name)) { + echo "Failed to update stats\n"; + } + } + return true; } diff -u -r -N yasuck-0.0.5.orig/yasuck yasuck-0.0.5/yasuck --- yasuck-0.0.5.orig/yasuck 2004-09-29 14:26:26.000000000 -0500 +++ yasuck-0.0.5/yasuck 2004-09-29 15:39:17.063171784 -0500 @@ -66,7 +66,7 @@ echo $status; exit(); break; - case "refresh": + case "refreshrecs": $rc = suckRecommendations(BOARD,START,END); if ($rc === true) { $status = "Done (success)\n"; @@ -77,6 +77,16 @@ echo $status; exit(); break; + case "refreshstats": + $rc = refreshStats(BOARD); + if ($rc === true) { + $status = "Done (success)\n"; + } else { + $status = "Done (failure)\n"; + } + echo $status; + exit(); + break; case "sanity": $rc = sanityCheck(); if ($rc === true) {