r90251 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90250‎ | r90251 | r90252 >
Date:02:00, 17 June 2011
Author:nimishg
Status:deferred
Tags:
Comment:
Created MetricsReportingQuery object, added more readable comments
Modified paths:
  • /trunk/wikistats/MetricsReporting/MetricsReporting.php (modified) (history)
  • /trunk/wikistats/MetricsReporting/MetricsReportingQuery.php (added) (history)
  • /trunk/wikistats/MetricsReporting/api/ApiAnalytics.php (modified) (history)

Diff [purge]

Index: trunk/wikistats/MetricsReporting/MetricsReporting.php
@@ -10,7 +10,17 @@
1111 'select_platform' => "MOBILE",
1212 );
1313
 14+$wgeAnalyticsFieldReturns = array(
 15+ 'select_regions' => "region",
 16+ 'select_countries' => "country",
 17+ 'select_web_projects' => "web project",
 18+ 'select_wikis' => "wiki",
 19+ 'select_editors' => "editors",
 20+ 'select_edits' => "edits",
 21+ 'select_platform' => "mobile",
 22+);
1423
 24+
1525 $wgeAnalyticsValidParams = array(
1626
1727 "select_regions" => array(
@@ -55,6 +65,14 @@
5666 );
5767
5868
 69+$wgAutoloadClasses['ApiAnalytics'] = $dir . '/api/ApiAnalytics.php';
 70+$wgAutoloadClasses['ApiAnalyticsMetric'] = $dir . '/api/ApiAnalyticsMetric.php';
 71+$wgAutoloadClasses['MetricsReportingQuery'] = $dir . '/MetricsReportingQuery.php';
 72+
 73+
 74+$dir = dirname( __FILE__ );
 75+
 76+
5977 $wgeAnalyticsMetricsList = array();
6078 $metricsdir = $dir."/metrics";
6179 $dh = opendir($metricsdir);
@@ -63,15 +81,16 @@
6482 $file_path_parts = pathinfo($dir.$file);
6583 if($file_path_parts['extension'] == 'php'){
6684 $wgAutoloadClasses["ApiAnalyticsMetric{$file_path_parts['filename']}"] = $dir.$file;
67 - include_once($dir.$file);
6885 $wgeAnalyticsMetricsList[] = $file_path_parts['filename'];
6986 }
70 -
7187 }
72 -
7388 }
7489
7590
 91+$wgAPIModules['analytics'] = 'ApiAnalytics';
 92+
 93+
 94+
7695 function wfAnalyticsMetricConnection() {
7796 global $wgeAnalyticsMetricDBserver, $wgeAnalyticsMetricDBname;
7897 global $wgeAnalyticsMetricDBuser, $wgeAnalyticsMetricDBpassword;
@@ -88,4 +107,7 @@
89108 }
90109
91110 return $db;
92 -}
\ No newline at end of file
 111+}
 112+
 113+
 114+class
\ No newline at end of file
Index: trunk/wikistats/MetricsReporting/api/ApiAnalytics.php
@@ -10,39 +10,79 @@
1111
1212 public function execute() {
1313
14 - global $wgeAnalyticsMetricsList;
 14+ global $wgeAnalyticsMetricsList, $wgeAnalyticsFieldReturns;
1515 $params = $this->extractRequestParams();
1616 $result = $this->getResult();
1717
1818 foreach($wgeAnalyticsMetricsList as $metricName){
 19+ //find the metric requested
1920 if($metricName == $params["metric"]){
 21+
 22+ //instantiate the class and an empty array of metricsreportingquery objects
2023 $metricClassName = "ApiAnalyticsMetric$metricName";
2124 $metric = new $metricClassName;
2225 $filterParams = $metric->getAllowedFilterParams();
2326 $queries = array();
 27+
 28+ //check to see which filters are set
2429 foreach($filterParams as $filterParam){
2530 if(isset( $params["$filterParam"])){
26 - $queries= array_merge($queries, $this->collectQueryFilters($filterParam, $params["$filterParam"]));
27 - }
28 - }
 31+ $filter_results = $this->collectQueryFilters($filterParam, $params["$filterParam"]);
 32+
 33+ //if multiple results returned, merge each of the query objects with whatever exists
 34+ if (count($filter_results) > 1){
 35+ foreach ($filter_results as $result){
 36+ foreach ($queries as $queryObj){
 37+ $result->merge($queryObj);
 38+ }
 39+ }
 40+ $queries = $filter_results;
 41+ }
 42+ //else just merge with the only object
 43+ else{
 44+ foreach($queries as &$queryObj){
 45+ $queryObj->merge($filter_results[0]);
 46+ }
 47+ }
 48+ } //endif
 49+ }//end filters
2950
 51+ //calculate time
3052 $range = " DATE = {$params["months"]}"; //TODO: query
31 -
 53+ $minDate = $params["months"];
3254 if(strpos($params["months"],";") !== FALSE){
3355 $rangeVals = explode($params["months"], ";");
3456 $range = " DATE >= $rangeVals[0] AND DATE <= $rangeVals[1]";
 57+ $minDate = $rangeVals[0];
3558 }
 59+ $timeStart = 0;
 60+ if(($timeStart = strtotime($str)) !== false){
 61+ $result->addValue("","timeStart",strfmttime("%Y%m%d%H%M%S",$timeStart));
 62+ }
3663
37 - foreach($queries as &$query){
38 - $query = $query . " AND " . $range;
 64+ //foreach query
 65+ foreach($queries as &$queryObj){
 66+ $queryObj->query = $queryObj->query . " AND " . $range;
3967
 68+ foreach($queryObj->queryProperties as $filterName => $filterVal){
 69+ $result->addValue("", $filterName, $filterVal); //filters
 70+ }
 71+
4072 if($metric->canBeNormalized){
41 - $result->addValue("","normalized","false");
4273 //TODO: modify queries for normalization
4374 if(isset($params["normalized"]) && (strpos($params["normalized"], "true") !== FALSE)){
4475 //is normalized
45 - $result->addValue("","normalized","true");
 76+ $result->addValue("","normalized","true");
 77+ } else {
 78+ $result->addValue("","normalized","false");
4679 }
 80+
 81+
 82+ if(isset($params["modailty"]) && (strpos($params["modality"], "indexed") !== FALSE)){
 83+ //modify query for indexed
 84+ $result->addValue("","modality","indexed");
 85+ }
 86+
4787 }
4888
4989 }
@@ -52,8 +92,6 @@
5393 $dbr = wfAnalyticsMetricConnection();
5494 //TODO: build return object from queries
5595
56 -
57 -
5896 }
5997 }
6098 }
@@ -65,7 +103,7 @@
66104
67105 //get rid of any potential whitespace
68106 $param = preg_replace('/\s\s+/', '', $fieldVal);
69 - $returnQueries = array();
 107+ $returnQueries = array(new MetricsReportingQuery);
70108
71109 if(!isset ($wgeAnalyticsFieldNames["$field"]) ){
72110 return $returnQueries;
@@ -85,17 +123,20 @@
86124 foreach($and_params as $and_param){
87125 $this->validate_atomic_param($and_param, $field);
88126 }
89 - $returnQueries[] = "$filedName = $sub_query "; //TODO: This is not what the query means
 127+ $returnQueries[] = new MetricsReportingQuery("$filedName = $sub_query ",
 128+ $fieldName,$sub_query);; //TODO: This is not what the query means
90129 }
91130 else{
92131 if(!$topval){
93132 //TODO:check for {project}:{lang} (ie wp:en) style here
94133
95134 $this->validate_atomic_param($sub_query, $field);
96 - $returnQueries[] = "$fieldName = $sub_query ";
 135+ $returnQueries[] = new MetricsReportingQuery("$fieldName = $sub_query ", //TODO: this might be what this query means
 136+ $fieldName, $sub_query);
97137 }
98138 else{
99 - $returnQueries[] = "$fieldName < $topval"; //TODO: This is not what this query means
 139+ $returnQueries[] = new MetricsReportingQuery("$fieldName < $topval", //TODO: This is not what this query means
 140+ $fieldName, $topval);
100141 }
101142 }
102143 }
Index: trunk/wikistats/MetricsReporting/MetricsReportingQuery.php
@@ -0,0 +1,113 @@
 2+<?php
 3+
 4+$wgeAnalyticsFieldNames = array(
 5+ 'select_regions' => "REGION",
 6+ 'select_countries' => "COUNTRY",
 7+ 'select_web_projects' => "WEBPROJ",
 8+ 'select_wikis' => "WIKI",
 9+ 'select_editors' => "EDITOR",
 10+ 'select_edits' => "EDITS",
 11+ 'select_platform' => "MOBILE",
 12+);
 13+
 14+$wgeAnalyticsFieldReturns = array(
 15+ 'select_regions' => "region",
 16+ 'select_countries' => "country",
 17+ 'select_web_projects' => "web project",
 18+ 'select_wikis' => "wiki",
 19+ 'select_editors' => "editors",
 20+ 'select_edits' => "edits",
 21+ 'select_platform' => "mobile",
 22+);
 23+
 24+
 25+$wgeAnalyticsValidParams = array(
 26+
 27+"select_regions" => array(
 28+ "AS" => "Asia Pacific",
 29+ "C" => "China",
 30+ "EU" => "Europe",
 31+ "I" => "India",
 32+ "LA" => "Latin-America",
 33+ "MA" => "Middle-East/Africa",
 34+ "NA" => "North-America",
 35+ "US" => "United States",
 36+ "W" => "World",
 37+),
 38+//"select_countries" => array(),
 39+//"select_web_properties"=> array(),
 40+"select_projects"=> array(
 41+ "wb" => "Wikibooks",
 42+ "wk" => "Wiktionary",
 43+ "wn" => "Wikinews",
 44+ "wp" => "Wikipedia",
 45+ "wq" => "Wikiquote",
 46+ "ws" => "Wikisource",
 47+ "wv" => "Wikiversity",
 48+ "co" => "Commons",
 49+ "wx" => "Other projects",
 50+),
 51+//"select_wikis"=> array(),
 52+"select_editors"=> array(
 53+ "A" => "Anonymous",
 54+ "R" => "Registered User",
 55+ "B" => "Bot",
 56+),
 57+"select_edits"=> array(
 58+ "M" => "Manual",
 59+ "B" => "Bot",
 60+),
 61+"select_platform"=> array(
 62+ "M" => "Moblie",
 63+ "N" => "Non-Mobile",
 64+),
 65+
 66+);
 67+
 68+
 69+$wgAutoloadClasses['ApiAnalytics'] = $dir . '/api/ApiAnalytics.php';
 70+$wgAutoloadClasses['ApiAnalyticsMetric'] = $dir . '/api/ApiAnalyticsMetric.php';
 71+$wgAutoloadClasses['MetricsReportingQuery'] = $dir . '/MetricsReportingQuery.php';
 72+
 73+
 74+$dir = dirname( __FILE__ );
 75+
 76+
 77+$wgeAnalyticsMetricsList = array();
 78+$metricsdir = $dir."/metrics";
 79+$dh = opendir($metricsdir);
 80+while( ($file = readdir($dh)) !== false){
 81+ if(filetype($dir.$file) == "file" ){
 82+ $file_path_parts = pathinfo($dir.$file);
 83+ if($file_path_parts['extension'] == 'php'){
 84+ $wgAutoloadClasses["ApiAnalyticsMetric{$file_path_parts['filename']}"] = $dir.$file;
 85+ $wgeAnalyticsMetricsList[] = $file_path_parts['filename'];
 86+ }
 87+ }
 88+}
 89+
 90+
 91+$wgAPIModules['analytics'] = 'ApiAnalytics';
 92+
 93+
 94+
 95+function wfAnalyticsMetricConnection() {
 96+ global $wgeAnalyticsMetricDBserver, $wgeAnalyticsMetricDBname;
 97+ global $wgeAnalyticsMetricDBuser, $wgeAnalyticsMetricDBpassword;
 98+
 99+ static $db;
 100+
 101+ if ( !$db ) {
 102+ $db = new DatabaseMysql(
 103+ $wgeAnalyticsMetricDBserver,
 104+ $wgeAnalyticsMetricDBuser,
 105+ $wgeAnalyticsMetricDBpassword,
 106+ $wgeAnalyticsMetricDBname );
 107+ $db->query( "SET names utf8" );
 108+ }
 109+
 110+ return $db;
 111+}
 112+
 113+
 114+class
\ No newline at end of file
Property changes on: trunk/wikistats/MetricsReporting/MetricsReportingQuery.php
___________________________________________________________________
Added: svn:eol-style
1115 + native

Status & tagging log