Index: trunk/wikistats/MetricsReporting/MetricsReporting.php |
— | — | @@ -10,7 +10,17 @@ |
11 | 11 | 'select_platform' => "MOBILE", |
12 | 12 | ); |
13 | 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 | +); |
14 | 23 | |
| 24 | + |
15 | 25 | $wgeAnalyticsValidParams = array( |
16 | 26 | |
17 | 27 | "select_regions" => array( |
— | — | @@ -55,6 +65,14 @@ |
56 | 66 | ); |
57 | 67 | |
58 | 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 | + |
59 | 77 | $wgeAnalyticsMetricsList = array(); |
60 | 78 | $metricsdir = $dir."/metrics"; |
61 | 79 | $dh = opendir($metricsdir); |
— | — | @@ -63,15 +81,16 @@ |
64 | 82 | $file_path_parts = pathinfo($dir.$file); |
65 | 83 | if($file_path_parts['extension'] == 'php'){ |
66 | 84 | $wgAutoloadClasses["ApiAnalyticsMetric{$file_path_parts['filename']}"] = $dir.$file; |
67 | | - include_once($dir.$file); |
68 | 85 | $wgeAnalyticsMetricsList[] = $file_path_parts['filename']; |
69 | 86 | } |
70 | | - |
71 | 87 | } |
72 | | - |
73 | 88 | } |
74 | 89 | |
75 | 90 | |
| 91 | +$wgAPIModules['analytics'] = 'ApiAnalytics'; |
| 92 | + |
| 93 | + |
| 94 | + |
76 | 95 | function wfAnalyticsMetricConnection() { |
77 | 96 | global $wgeAnalyticsMetricDBserver, $wgeAnalyticsMetricDBname; |
78 | 97 | global $wgeAnalyticsMetricDBuser, $wgeAnalyticsMetricDBpassword; |
— | — | @@ -88,4 +107,7 @@ |
89 | 108 | } |
90 | 109 | |
91 | 110 | 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 @@ |
11 | 11 | |
12 | 12 | public function execute() { |
13 | 13 | |
14 | | - global $wgeAnalyticsMetricsList; |
| 14 | + global $wgeAnalyticsMetricsList, $wgeAnalyticsFieldReturns; |
15 | 15 | $params = $this->extractRequestParams(); |
16 | 16 | $result = $this->getResult(); |
17 | 17 | |
18 | 18 | foreach($wgeAnalyticsMetricsList as $metricName){ |
| 19 | + //find the metric requested |
19 | 20 | if($metricName == $params["metric"]){ |
| 21 | + |
| 22 | + //instantiate the class and an empty array of metricsreportingquery objects |
20 | 23 | $metricClassName = "ApiAnalyticsMetric$metricName"; |
21 | 24 | $metric = new $metricClassName; |
22 | 25 | $filterParams = $metric->getAllowedFilterParams(); |
23 | 26 | $queries = array(); |
| 27 | + |
| 28 | + //check to see which filters are set |
24 | 29 | foreach($filterParams as $filterParam){ |
25 | 30 | 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 |
29 | 50 | |
| 51 | + //calculate time |
30 | 52 | $range = " DATE = {$params["months"]}"; //TODO: query |
31 | | - |
| 53 | + $minDate = $params["months"]; |
32 | 54 | if(strpos($params["months"],";") !== FALSE){ |
33 | 55 | $rangeVals = explode($params["months"], ";"); |
34 | 56 | $range = " DATE >= $rangeVals[0] AND DATE <= $rangeVals[1]"; |
| 57 | + $minDate = $rangeVals[0]; |
35 | 58 | } |
| 59 | + $timeStart = 0; |
| 60 | + if(($timeStart = strtotime($str)) !== false){ |
| 61 | + $result->addValue("","timeStart",strfmttime("%Y%m%d%H%M%S",$timeStart)); |
| 62 | + } |
36 | 63 | |
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; |
39 | 67 | |
| 68 | + foreach($queryObj->queryProperties as $filterName => $filterVal){ |
| 69 | + $result->addValue("", $filterName, $filterVal); //filters |
| 70 | + } |
| 71 | + |
40 | 72 | if($metric->canBeNormalized){ |
41 | | - $result->addValue("","normalized","false"); |
42 | 73 | //TODO: modify queries for normalization |
43 | 74 | if(isset($params["normalized"]) && (strpos($params["normalized"], "true") !== FALSE)){ |
44 | 75 | //is normalized |
45 | | - $result->addValue("","normalized","true"); |
| 76 | + $result->addValue("","normalized","true"); |
| 77 | + } else { |
| 78 | + $result->addValue("","normalized","false"); |
46 | 79 | } |
| 80 | + |
| 81 | + |
| 82 | + if(isset($params["modailty"]) && (strpos($params["modality"], "indexed") !== FALSE)){ |
| 83 | + //modify query for indexed |
| 84 | + $result->addValue("","modality","indexed"); |
| 85 | + } |
| 86 | + |
47 | 87 | } |
48 | 88 | |
49 | 89 | } |
— | — | @@ -52,8 +92,6 @@ |
53 | 93 | $dbr = wfAnalyticsMetricConnection(); |
54 | 94 | //TODO: build return object from queries |
55 | 95 | |
56 | | - |
57 | | - |
58 | 96 | } |
59 | 97 | } |
60 | 98 | } |
— | — | @@ -65,7 +103,7 @@ |
66 | 104 | |
67 | 105 | //get rid of any potential whitespace |
68 | 106 | $param = preg_replace('/\s\s+/', '', $fieldVal); |
69 | | - $returnQueries = array(); |
| 107 | + $returnQueries = array(new MetricsReportingQuery); |
70 | 108 | |
71 | 109 | if(!isset ($wgeAnalyticsFieldNames["$field"]) ){ |
72 | 110 | return $returnQueries; |
— | — | @@ -85,17 +123,20 @@ |
86 | 124 | foreach($and_params as $and_param){ |
87 | 125 | $this->validate_atomic_param($and_param, $field); |
88 | 126 | } |
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 |
90 | 129 | } |
91 | 130 | else{ |
92 | 131 | if(!$topval){ |
93 | 132 | //TODO:check for {project}:{lang} (ie wp:en) style here |
94 | 133 | |
95 | 134 | $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); |
97 | 137 | } |
98 | 138 | 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); |
100 | 141 | } |
101 | 142 | } |
102 | 143 | } |
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 |
1 | 115 | + native |