Index: trunk/extensions/CongressLookup/scripts/zip_file_parser.php |
— | — | @@ -1,5 +1,6 @@ |
2 | 2 | <?php |
3 | 3 | 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. >:[ |
4 | 5 | |
5 | 6 | $IP = getenv( 'MW_INSTALL_PATH' ); |
6 | 7 | if ( $IP === false ) { |
— | — | @@ -18,8 +19,24 @@ |
19 | 20 | if ( !empty( $_SERVER['argv'][1] ) && is_numeric( $_SERVER['argv'][1] ) ){ |
20 | 21 | $skip_up_to = $_SERVER['argv'][1]; |
21 | 22 | } |
| 23 | + $function = 'fillOutNulls'; |
| 24 | + if ( !empty( $_SERVER['argv'][1] ) && $_SERVER['argv'][1] === 'findSplits' ){ |
| 25 | + $function = 'findSplits'; |
| 26 | + } |
22 | 27 | |
| 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 | + } |
23 | 36 | |
| 37 | + echo "Done\n"; |
| 38 | + } |
| 39 | + |
| 40 | + function fill_out_nulls( $skip_up_to ){ |
24 | 41 | //get the "missing" zipcodes |
25 | 42 | $missing_zips = $this->getMissingZipcodes(); |
26 | 43 | |
— | — | @@ -120,6 +137,53 @@ |
121 | 138 | echo "Time: " . $duration . "\n"; |
122 | 139 | } |
123 | 140 | |
| 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!"); |
124 | 188 | } |
125 | 189 | |
126 | 190 | function insert_rep( $zip, $rep_id ){ |