r91521 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91520‎ | r91521 | r91522 >
Date:03:24, 6 July 2011
Author:reedy
Status:deferred (Comments)
Tags:
Comment:
Boo for coding when tired

Yay for getting it done

<region region_code="AS" region_name="Asia Pacific">
<data>
<d date="2008-01-31" reach="19.4" />
<d date="2008-02-29" reach="19.5" />
<d date="2008-03-31" reach="19.8" />
<d date="2008-04-30" reach="20.1" />
<d date="2008-05-31" reach="19.7" />
<d date="2008-06-30" reach="20.1" />
</data>
</region>

etc etc
Modified paths:
  • /trunk/extensions/MetricsReporting/ApiAnalyticsBase.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MetricsReporting/ApiAnalyticsBase.php
@@ -133,22 +133,33 @@
134134 $this->profileDBOut();
135135
136136 $result = $this->getResult();
137 - $data = array();
138137
139138 $fields = array_map( array( $this, 'getColumnName' ), $query['fields'] );
140139
 140+ $things = array();
 141+ // Build result set
141142 foreach( $res as $row ) {
142143 // Dump all data to output
143144 $item = array();
144 - foreach( $fields as $field ) {
 145+ foreach( array_diff( $fields, array( 'region_code', 'region_name' ) ) as $field ) {
145146 $item[$field] = $row->$field;
146147 }
147 - $data[ $row->{$this->getColumnName( 'comscore.region_code' )} ][] = $item;
148 - $result->setIndexedTagName( $data[ $row->{$this->getColumnName( 'comscore.region_code' )} ], 'region' );
 148+
 149+ if( !isset( $things[$row->region_code] ) ) {
 150+ $things[$row->region_code] = array( 'region_code' => $row->region_code, 'region_name' => $row->region_name );
 151+ }
 152+
 153+ $things[$row->region_code]['data'][] = $item;
 154+ $result->setIndexedTagName( $things[$row->region_code]['data'], 'd' );
149155 }
150156
151 - $result->setIndexedTagName( $data, 'data' );
152 - $result->addValue( 'metric', $this->getModuleName(), $data );
 157+ // Add data to the output
 158+ foreach( $things as $thing ) {
 159+ $result->addValue( array( $this->getModuleName() ), null, $thing );
 160+ }
 161+ $result->setIndexedTagName_internal( array( $this->getModuleName() ), 'region' );
 162+
 163+
153164 }
154165
155166 // TODO: Deal with foo AS bar, and return bar for nicer aliasing of stuff

Comments

#Comment by Reedy (talk | contribs)   03:26, 6 July 2011

TODO: Use more sensible variable names

TODO: Genericise up for the different result outputs

Status & tagging log