r109265 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109264‎ | r109265 | r109266 >
Date:00:36, 18 January 2012
Author:khorn
Status:ok
Tags:sopa 
Comment:
More log parsing. This one deals with the split zipcodes. Still dying out of the box for safety.
Modified paths:
  • /trunk/extensions/CongressLookup/scripts/zip_file_parser.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CongressLookup/scripts/zip_file_parser.php
@@ -148,6 +148,7 @@
149149 //Still a terrible way to do this.
150150 $zipfile = file( 'zipcode_map.txt', FILE_SKIP_EMPTY_LINES );
151151 $zipmap = array();
 152+ $zip5_reps = array();
152153 foreach ( $zipfile as $line=>$val ){
153154 $val = explode(' ', $val);
154155 $zipgroup = $val[0];
@@ -166,6 +167,7 @@
167168 $district = trim($val_2[1]);
168169
169170 $zipmap[$zipgroup][$state . '-' . $district][] = $original_zipgroup;
 171+
170172 //echo "Zipgroup = $zipgroup, State = $state, District = $district";
171173 }
172174 //echo print_r( $zipmap, true );
@@ -175,6 +177,7 @@
176178 foreach ( $zipmap as $group => $districts ){
177179 if (count($districts) > 1){
178180 $splits[$group] = count($districts);
 181+ $this->insert_reps_by_district($group, $districts);
179182 } else {
180183 unset( $zipmap[$group] );
181184 }
@@ -182,8 +185,7 @@
183186
184187 echo print_r( $splits, true );
185188 echo count( $splits ) . " split zipcodes found, out of... I don't know. 40 thousand or something.\n";
186 -
187 - die("Hurr!");
 189+
188190 }
189191
190192 function insert_rep( $zip, $rep_id ){
@@ -199,6 +201,40 @@
200202 echo "Updated $zip to include rep id $rep_id\n";
201203 }
202204
 205+ function insert_reps_by_district( $zip, $districts ){
 206+ $dbr = wfGetDB( DB_SLAVE );
 207+ echo "Zip: $zip\n";
 208+ echo "Districts: " . print_r( $districts, true );
 209+
 210+ $rep_ids = array();
 211+ foreach ( $districts as $district => $z9 ){
 212+ $district = explode('-', $district);
 213+ $state = $district[0];
 214+ $district = $district[1];
 215+ $rep_ids[] = $this->get_rep_ids( $state, $district );
 216+ }
 217+ echo print_r( $rep_ids, true );
 218+
 219+ //delete everything with the current zipcode.
 220+ $dbr->delete( 'cl_zip5', array( 'clz5_zip' => $zip ) );
 221+
 222+ foreach ( $rep_ids as $rep_id ){
 223+ echo " Count of Rep IDs: " . count( $rep_id ) . "\n";
 224+ if ( count( $rep_id ) === 1 ){
 225+ $rep_id = $rep_id[0];
 226+ $dbr->insert( 'cl_zip5',
 227+ array(
 228+ 'clz5_zip' => $zip,
 229+ 'clz5_rep_id' => $rep_id,
 230+ )
 231+ );
 232+ } else {
 233+// echo " Count of Rep IDs was NOT one for $zip.\n";
 234+ }
 235+ echo "Updated $zip to include rep id $rep_id\n";
 236+ }
 237+
 238+ }
203239
204240 function make_zip_string( $zip ){
205241 $zip = (string)$zip;

Status & tagging log