r91382 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91381‎ | r91382 | r91383 >
Date:20:14, 3 July 2011
Author:yuvipanda
Status:ok
Tags:
Comment:
Model to deal with reading stats from the db
Modified paths:
  • /trunk/extensions/GPoC/models/Rating.php (modified) (history)
  • /trunk/extensions/GPoC/models/Statistics.php (added) (history)

Diff [purge]

Index: trunk/extensions/GPoC/models/Statistics.php
@@ -0,0 +1,53 @@
 2+<?php
 3+
 4+/**
 5+ * Has static methods to grab assessment statistics
 6+ **/
 7+
 8+class Statistics {
 9+ public static function getImportanceColumn( $importance ) {
 10+ $importanceColumnMapping = array(
 11+ 'top' => 'ps_top_icount',
 12+ 'high' => 'ps_high_icount',
 13+ 'mid' => 'ps_mid_icount',
 14+ 'low' => 'ps_mid_icount',
 15+ 'no' => 'ps_no_icount',
 16+ '' => 'ps_unclassified_icount'
 17+ );
 18+
 19+ return $importanceColumnMapping[ strtolower( $importance ) ];
 20+ }
 21+
 22+ public static function getProjectStats( $project ) {
 23+ $dbr = wfGetDB( DB_SLAVE );
 24+ $query = $dbr->select(
 25+ "project_stats",
 26+ "*",
 27+ array(
 28+ "ps_project" => $project
 29+ ),
 30+ __METHOD__
 31+ );
 32+
 33+ $project_statistics = array(
 34+ "top" => array(),
 35+ "high" => array(),
 36+ "mid" => array(),
 37+ "low" => array(),
 38+ "no" => array(),
 39+ "" => array()
 40+ );
 41+
 42+
 43+ foreach( $query as $row_object ) {
 44+ $data_row = (array)$row_object;
 45+ $quality = $data_row['ps_quality'];
 46+ foreach( $project_statistics as $importance => &$importance_row ) {
 47+ $importance_row[$quality] = $data_row[Statistics::getImportanceColumn( $importance )];
 48+ }
 49+ }
 50+
 51+ return $project_statistics;
 52+ }
 53+
 54+}
Index: trunk/extensions/GPoC/models/Rating.php
@@ -1,5 +1,7 @@
22 <?php
33
 4+require_once "Statistics.php";
 5+
46 /**
57 * Represents an article and associated rating
68 **/
@@ -16,18 +18,6 @@
1719 private $old_quality;
1820 private $inDB = false;
1921
20 - private static function getImportanceColumn( $importance ) {
21 - $importanceColumnMapping = array(
22 - 'top' => 'ps_top_icount',
23 - 'high' => 'ps_high_icount',
24 - 'mid' => 'ps_mid_icount',
25 - 'low' => 'ps_mid_icount',
26 - 'no' => 'ps_no_icount',
27 - '' => 'ps_unclassified_icount'
28 - );
29 - return $importanceColumnMapping[ strtolower( $importance ) ];
30 - }
31 -
3222 public function __construct( $project, $namespace, $title, $quality, $quality_timestamp, $importance, $importance_timestamp ) {
3323 $this->project = $project;
3424 $this->namespace = $namespace;
@@ -59,7 +49,7 @@
6050 $dbw = wfGetDB( DB_MASTER );
6151 // Rating has just been detected.
6252 // So we can ignore $old_importance and $old_quality
63 - $importance_column = Rating::getImportanceColumn( $this->importance );
 53+ $importance_column = Statistics::getImportanceColumn( $this->importance );
6454 $project = $dbw->addQuotes($this->project);
6555 $quality = $dbw->addQuotes($this->quality);
6656 $query = "INSERT INTO project_stats (ps_project, ps_quality, $importance_column) ";
@@ -67,7 +57,7 @@
6858 $query .= "ON DUPLICATE KEY ";
6959 $query .= "UPDATE $importance_column = $importance_column + 1 ";
7060 if(! $is_new_rating && ! empty( $this->old_importance ) ) {
71 - $old_importance_column = Rating::getImportanceColumn( $this->old_importance );
 61+ $old_importance_column = Statistics::getImportanceColumn( $this->old_importance );
7262 $query .= ", $old_importance_column = $old_importance_column - 1";
7363 }
7464 $query .= ";";
@@ -116,7 +106,6 @@
117107 $this->updateAggregateStats( true );
118108 $this->inDB = true;
119109 }
120 -
121110 }
122111
123112 public static function forTitle( $title ) {
@@ -147,4 +136,4 @@
148137 }
149138 return $ratings;
150139 }
151 -}
 140+}

Status & tagging log