Index: trunk/extensions/CongressLookup/scripts/zip_file_parser.php |
— | — | @@ -148,6 +148,7 @@ |
149 | 149 | //Still a terrible way to do this. |
150 | 150 | $zipfile = file( 'zipcode_map.txt', FILE_SKIP_EMPTY_LINES ); |
151 | 151 | $zipmap = array(); |
| 152 | + $zip5_reps = array(); |
152 | 153 | foreach ( $zipfile as $line=>$val ){ |
153 | 154 | $val = explode(' ', $val); |
154 | 155 | $zipgroup = $val[0]; |
— | — | @@ -166,6 +167,7 @@ |
167 | 168 | $district = trim($val_2[1]); |
168 | 169 | |
169 | 170 | $zipmap[$zipgroup][$state . '-' . $district][] = $original_zipgroup; |
| 171 | + |
170 | 172 | //echo "Zipgroup = $zipgroup, State = $state, District = $district"; |
171 | 173 | } |
172 | 174 | //echo print_r( $zipmap, true ); |
— | — | @@ -175,6 +177,7 @@ |
176 | 178 | foreach ( $zipmap as $group => $districts ){ |
177 | 179 | if (count($districts) > 1){ |
178 | 180 | $splits[$group] = count($districts); |
| 181 | + $this->insert_reps_by_district($group, $districts); |
179 | 182 | } else { |
180 | 183 | unset( $zipmap[$group] ); |
181 | 184 | } |
— | — | @@ -182,8 +185,7 @@ |
183 | 186 | |
184 | 187 | echo print_r( $splits, true ); |
185 | 188 | echo count( $splits ) . " split zipcodes found, out of... I don't know. 40 thousand or something.\n"; |
186 | | - |
187 | | - die("Hurr!"); |
| 189 | + |
188 | 190 | } |
189 | 191 | |
190 | 192 | function insert_rep( $zip, $rep_id ){ |
— | — | @@ -199,6 +201,40 @@ |
200 | 202 | echo "Updated $zip to include rep id $rep_id\n"; |
201 | 203 | } |
202 | 204 | |
| 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 | + } |
203 | 239 | |
204 | 240 | function make_zip_string( $zip ){ |
205 | 241 | $zip = (string)$zip; |