r109212 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109211‎ | r109212 | r109213 >
Date:20:56, 17 January 2012
Author:khorn
Status:ok
Tags:sopa 
Comment:
Working on finding split zipcodes in the zip map.
Modified paths:
  • /trunk/extensions/CongressLookup/scripts/zip_file_parser.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CongressLookup/scripts/zip_file_parser.php
@@ -1,5 +1,6 @@
22 <?php
33 die( "Dying for safety, because nobody should actually use this.\nIf you disagree, you'll need to uncomment line 2.\n" );
 4+//just don't commit it uncommented. >:[
45
56 $IP = getenv( 'MW_INSTALL_PATH' );
67 if ( $IP === false ) {
@@ -18,8 +19,24 @@
1920 if ( !empty( $_SERVER['argv'][1] ) && is_numeric( $_SERVER['argv'][1] ) ){
2021 $skip_up_to = $_SERVER['argv'][1];
2122 }
 23+ $function = 'fillOutNulls';
 24+ if ( !empty( $_SERVER['argv'][1] ) && $_SERVER['argv'][1] === 'findSplits' ){
 25+ $function = 'findSplits';
 26+ }
2227
 28+ switch ( $function ){
 29+ case 'fillOutNulls':
 30+ $this->fill_out_nulls( $skip_up_to );
 31+ break;
 32+ case 'findSplits':
 33+ $this->find_split_zipcodes( $skip_up_to );
 34+ break;
 35+ }
2336
 37+ echo "Done\n";
 38+ }
 39+
 40+ function fill_out_nulls( $skip_up_to ){
2441 //get the "missing" zipcodes
2542 $missing_zips = $this->getMissingZipcodes();
2643
@@ -120,6 +137,53 @@
121138 echo "Time: " . $duration . "\n";
122139 }
123140
 141+ }
 142+
 143+
 144+ function find_split_zipcodes( $skip_up_to ){
 145+ //get the "missing" zipcodes
 146+ //$missing_zips = $this->getMissingZipcodes();
 147+
 148+ //load the file
 149+ //Still a terrible way to do this.
 150+ $zipfile = file( 'zipcode_map.txt', FILE_SKIP_EMPTY_LINES );
 151+ $zipmap = array();
 152+ foreach ( $zipfile as $line=>$val ){
 153+ $val = explode(' ', $val);
 154+ $zipgroup = $val[0];
 155+ $extended = '';
 156+ $exploded_zipgroup = explode( '-', $zipgroup );
 157+ $original_zipgroup = $zipgroup;
 158+
 159+ if ( count( $exploded_zipgroup ) > 1 ){
 160+ $zipgroup = $exploded_zipgroup[0];
 161+ $extended = $exploded_zipgroup[1];
 162+ }
 163+
 164+ $val_2 = explode('-', $val[1]);
 165+
 166+ $state = $val_2[0];
 167+ $district = trim($val_2[1]);
 168+
 169+ $zipmap[$zipgroup][$state . '-' . $district][] = $original_zipgroup;
 170+ //echo "Zipgroup = $zipgroup, State = $state, District = $district";
 171+ }
 172+ //echo print_r( $zipmap, true );
 173+ //die();
 174+
 175+ $splits = array();
 176+ foreach ( $zipmap as $group => $districts ){
 177+ if (count($districts) > 1){
 178+ $splits[$group] = count($districts);
 179+ } else {
 180+ unset( $zipmap[$group] );
 181+ }
 182+ }
 183+
 184+ echo print_r( $splits, true );
 185+ echo count( $splits ) . " split zipcodes found, out of... I don't know. 40 thousand or something.\n";
 186+
 187+ die("Hurr!");
124188 }
125189
126190 function insert_rep( $zip, $rep_id ){

Status & tagging log