Update date generic form parser for federal 2025 form.

This commit is contained in:
Kim Taylor
2025-03-30 23:02:48 +11:00
parent 05b0898979
commit 675058201a
4 changed files with 19 additions and 25 deletions

View File

@@ -10,20 +10,12 @@ function parse_generic_csv($generic_csv) {
$is_question = false;
foreach ($headers as $key => $value) {
/* Override key name for questions */
if ($value === "Verified") {
$is_question = false;
}
if (strstr($value, "candidate photo")) $value = "Photo";
if (strstr($value, "In which Local Government Area")) $value = "LGA";
if (strstr($value, "In which Ward")) $value = "Ward";
if (strstr($value, "In which federal Division are")) continue;
if (strstr($value, "In which Federal Division are")) $value = "Division";
if (strstr($value, "Political Party")) $value = "Party";
if (strstr($value, "Protected bike lanes provide")) continue;
if ($value === "Pledge") {
if (strstr($data[$key], "I pledge")) $data[$key] = "y";
else $data[$key] = "n";
}
if ($value === "Photo") {
$candidate['photo_url'] = $data[$key];
$data[$key] = preg_filter("/.*id=/", "", $data[$key]);
@@ -35,7 +27,7 @@ function parse_generic_csv($generic_csv) {
$candidate[$value] = $data[$key];
}
if ($value === "Pledge") {
if ($value === "Party") {
$is_question = true;
}
}
@@ -55,7 +47,7 @@ function match_lga(&$candidate_data, $lga_list) {
/* Match user typed LGA/Ward to our database */
$max_score = 0;
foreach ($lga_list as $lga) {
$aa = preg_split("/[^a-z]/", strtolower($candidate['LGA']));
$aa = preg_split("/[^a-z]/", strtolower($candidate['Division']));
$bb = preg_split("/[^a-z]/", $lga['slug']);
$score_sum = 0;
@@ -73,6 +65,7 @@ function match_lga(&$candidate_data, $lga_list) {
}
}
/*
$max_score = 0;
foreach ($match_lga['wardNames'] as $ward) {
similar_text(strtolower($ward), strtolower($candidate['Ward']), $score);
@@ -81,9 +74,10 @@ function match_lga(&$candidate_data, $lga_list) {
$match_ward = $ward;
}
}
*/
$candidate['match_lga'] = $match_lga['slug'];
$candidate['match_ward'] = $match_ward;
$candidate['match_division'] = $match_lga['slug'];
//$candidate['match_ward'] = $match_ward;
}
}