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

@@ -42,21 +42,22 @@ match_lga($candidate_data, $lga_list);
foreach ($candidate_data as $key => $candidate) {
$score = 0;
if ($candidate['Pledge'] === "y") $score++;
if ($candidate['q0'] === "Yes") $score++;
if ($candidate['q1'] === "Yes") $score++;
if ($candidate['q2'] === "Yes") $score++;
if ($candidate['q3'] === "Yes") $score++;
if ($candidate['q4'] === "Yes") $score++;
if ($candidate['q7'] === "Yes") $score++;
$candidate_data[$key]['Score'] = $score;
$candidate_data[$key]['Pledge'] = $score > 0 ? "Yes" : "No";
}
$header = ["Ward", "Candidate Name", "Rating", "Pledge", "Picture"];
$header = ["Candidate Name", "Rating", "Pledge", "Picture"];
/* Generate candidates-generic.csv */
foreach ($lga_list as $lga) {
$lga_candidates = array_filter($candidate_data, function ($candidate) use ($lga) {
return $candidate['match_lga'] === $lga['slug'];
return $candidate['match_division'] === $lga['slug'];
});
if (count($lga_candidates) === 0) continue;
@@ -91,7 +92,6 @@ foreach ($lga_list as $lga) {
}
$lines[] = [
$candidate['match_ward'],
$candidate['Name'],
$candidate['Score'],
$candidate['Pledge'],

View File

@@ -42,7 +42,7 @@ $image_map = [];
foreach ($candidate_data as $candidate) {
if (strlen($candidate['photo_url'])) {
$map['url'] = $candidate['photo_url'];
$map['match_lga'] = $candidate['match_lga'];
$map['match_division'] = $candidate['match_division'];
$image_map[$candidate['Photo']] = $map;
}
}

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;
}
}