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 @@ |
2 | 2 | <?php |
3 | 3 | |
| 4 | +require_once "Statistics.php"; |
| 5 | + |
4 | 6 | /** |
5 | 7 | * Represents an article and associated rating |
6 | 8 | **/ |
— | — | @@ -16,18 +18,6 @@ |
17 | 19 | private $old_quality; |
18 | 20 | private $inDB = false; |
19 | 21 | |
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 | | - |
32 | 22 | public function __construct( $project, $namespace, $title, $quality, $quality_timestamp, $importance, $importance_timestamp ) { |
33 | 23 | $this->project = $project; |
34 | 24 | $this->namespace = $namespace; |
— | — | @@ -59,7 +49,7 @@ |
60 | 50 | $dbw = wfGetDB( DB_MASTER ); |
61 | 51 | // Rating has just been detected. |
62 | 52 | // So we can ignore $old_importance and $old_quality |
63 | | - $importance_column = Rating::getImportanceColumn( $this->importance ); |
| 53 | + $importance_column = Statistics::getImportanceColumn( $this->importance ); |
64 | 54 | $project = $dbw->addQuotes($this->project); |
65 | 55 | $quality = $dbw->addQuotes($this->quality); |
66 | 56 | $query = "INSERT INTO project_stats (ps_project, ps_quality, $importance_column) "; |
— | — | @@ -67,7 +57,7 @@ |
68 | 58 | $query .= "ON DUPLICATE KEY "; |
69 | 59 | $query .= "UPDATE $importance_column = $importance_column + 1 "; |
70 | 60 | 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 ); |
72 | 62 | $query .= ", $old_importance_column = $old_importance_column - 1"; |
73 | 63 | } |
74 | 64 | $query .= ";"; |
— | — | @@ -116,7 +106,6 @@ |
117 | 107 | $this->updateAggregateStats( true ); |
118 | 108 | $this->inDB = true; |
119 | 109 | } |
120 | | - |
121 | 110 | } |
122 | 111 | |
123 | 112 | public static function forTitle( $title ) { |
— | — | @@ -147,4 +136,4 @@ |
148 | 137 | } |
149 | 138 | return $ratings; |
150 | 139 | } |
151 | | -} |
| 140 | +} |