https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114579
Revision: 114579
Author: bsitu
Date: 2012-03-28 21:44:51 +0000 (Wed, 28 Mar 2012)
Log Message:
-----------
add more functions to generate dashboard stat data
Modified Paths:
--------------
trunk/extensions/PageTriage/includes/PageTriageUtil.php
Modified: trunk/extensions/PageTriage/includes/PageTriageUtil.php
===================================================================
--- trunk/extensions/PageTriage/includes/PageTriageUtil.php 2012-03-28
21:38:46 UTC (rev 114578)
+++ trunk/extensions/PageTriage/includes/PageTriageUtil.php 2012-03-28
21:44:51 UTC (rev 114579)
@@ -40,16 +40,16 @@
* @Todo - Limit the number of records by a timestamp filter, maybe 30
days etc,
* depends on the time the triage queue should look back for
listview
*/
- public static function getUntriageArticleStat() {
+ public static function getUntriagedArticleStat() {
global $wgMemc;
-
+
$key = wfMemcKey( 'pagetriage', 'untriaged-article', 'stat' );
$data = $wgMemc->get( $key );
if ( $data !== false ) {
return $data;
}
-
+
$dbr = wfGetDB( DB_SLAVE );
$res = $dbr->selectRow(
@@ -63,7 +63,7 @@
$data = array( 'count' => 0 );
foreach ( $percentile as $val ) {
- $data['age-' . $val . 'th-percentile'] = false;
+ $data['age-' . $val . 'th-percentile'] = false;
}
if ( $res ) {
@@ -76,45 +76,92 @@
}
}
}
-
+
// make it expire in an hour
$wgMemc->set( $key, $data, 3600 );
return $data;
}
/**
- * Get top page triagers in the past week
- * @param $num int - number of records to retrieve
+ * Get top page triagers in various time frame
+ * @param $time string - time to look back for top triagers, possible
values include
+ * last-day, last-week, last-month, last-year
* @return array
*/
- public static function getTopTriager( $num = 5 ) {
+ public static function getTopTriager( $time = 'last-day' ) {
global $wgMemc;
+ $now = wfTimestamp( TS_UNIX );
+
+ // times to look back for top trigers and expiration time in
cache
+ $timeFrame = array(
+ 'last-day' => array( 'ts' => $now - 24 * 60 *
60, 'expire' => 60 * 60 ),
+ 'last-week' => array( 'ts' => $now - 7 * 24 *
60 * 60, 'expire' => 24 * 60 * 60 ),
+ //Todo: Do we really want to include big
timeframe?
+ 'last-month' => array( 'ts' => $now - 30 * 24 *
60 * 60, 'expire' => 7 * 24 * 60 * 60 ),
+ 'last-year'=> array( 'ts' => $now - 365 * 24 *
60 * 60, 'expire' => 30 * 24 * 60 * 60 )
+ );
+
+ if ( !isset( $timeFrame[$time] ) ) {
+ $time = 'last-day';
+ }
+
$dbr = wfGetDB( DB_SLAVE );
- $key = wfMemcKey( 'pagetriage', 'top-triager', 'past-week' );
+ $key = wfMemcKey( 'pagetriage', 'top-triager', $time );
$topTriager = $wgMemc->get( $key );
if ( $topTriager === false ) {
- $timestamp = wfTimestamp( TS_UNIX ) - 7 * 24 * 60 * 60;
// 1 week ago
-
$res = $dbr->select(
array( 'pagetriage_log', 'user' ),
array( 'user_name', 'COUNT(ptrl_id) AS num' ),
- array( 'user_id = ptrl_user_id',
'ptrl_timestamp > ' . $dbr->addQuotes( $dbr->timestamp( $timestamp ) ) ),
+ array( 'user_id = ptrl_user_id',
'ptrl_timestamp > ' . $dbr->addQuotes( $dbr->timestamp( $timeFrame[$time]['ts']
) ) ),
__METHOD__,
- array( 'GROUP BY' => 'user_id', 'ORDER BY' =>
'num DESC', 'LIMIT' => $num )
+ array( 'GROUP BY' => 'user_id', 'ORDER BY' =>
'num DESC', 'LIMIT' => 50 )
);
$topTriager = iterator_to_array( $res );
- // make it expire in 2 hours
- $wgMemc->set( $key, $topTriager, 7200 );
+ $wgMemc->set( $key, $topTriager,
$timeFrame[$time]['expire'] );
}
return $topTriager;
}
/**
+ * Get the number of triaged articles in last week
+ * @return int
+ */
+ public static function getTriagedArticleNum() {
+ global $wgMemc;
+
+ $dbr = wfGetDB( DB_SLAVE );
+ $key = wfMemcKey( 'pagetriage', 'triaged-article', 'num' );
+
+ $triagedArticleNum = $wgMemc->get( $key );
+
+ if ( $triagedArticleNum !== false) {
+ return $triagedArticleNum;
+ }
+
+ $res = $dbr->selectRow(
+ array( 'pagetriage_page' ),
+ array( 'COUNT(ptrp_id) AS num' ),
+ array( 'ptrp_triaged = 1', 'ptrp_timestamp > ' .
$dbr->addQuotes( $dbr->timestamp( wfTimestamp( TS_UNIX ) - 7 * 24 * 60 * 60 ) )
),
+ __METHOD__
+ );
+
+ if ( $res ) {
+ $triagedArticleNum = $res->num;
+ } else {
+ $triagedArticleNum = 0;
+ }
+
+ $wgMemc->set( $key, $triagedArticleNum, 6 * 60 * 60 );
+
+ return $triagedArticleNum;
+ }
+
+ /**
* Calculate the age of untriaged articles by percentile
* @param $percentile int
* @param $count int
@@ -138,12 +185,12 @@
$order = 'DESC';
}
- $start = floor( ( $percentile / 100 ) * $count ) - 1;
+ $start = floor( ( $percentile / 100 ) * $count ) - 1;
if ( $start < 0 ) {
$start = 0;
}
-
+
$dbr = wfGetDB( DB_SLAVE );
$res = $dbr->selectRow(
@@ -157,7 +204,7 @@
if ( $res ) {
return $res->ptrp_timestamp;
} else {
- return false;
+ return false;
}
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs