Update date generic form parser for federal 2025 form.
This commit is contained in:
@@ -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'],
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
GENERIC_SURVEY=../generic-survey/responses.csv
|
||||
IMAGES=../generic-survey/images
|
||||
|
||||
DATA_PATH="../spl-data"
|
||||
DATA_PATH="../spl-data/federal_2025"
|
||||
|
||||
echo "Fetching latest responses to generic survey."
|
||||
rm -f $GENERIC_SURVEY # Force re-fetch
|
||||
rclone -v copyto --drive-export-formats csv 'bikewest:spl_generic_survey_2024/Streets People Love council election candidate pledge and survey (Responses).csv' $GENERIC_SURVEY
|
||||
rclone -v copyto --drive-export-formats csv 'bikewest:spl_generic_survey_federal_2025/Streets People Love Federal Election candidate pledge (Responses).csv' $GENERIC_SURVEY
|
||||
|
||||
config_files=()
|
||||
for folder in "$DATA_PATH"/*; do
|
||||
@@ -47,7 +47,7 @@ for key in $(jq -r 'keys[]' <<< $image_map) ; do
|
||||
;;
|
||||
esac
|
||||
|
||||
lga=$(jq -r ".[\"$key\"][\"match_lga\"]" <<< $image_map)
|
||||
lga=$(jq -r ".[\"$key\"][\"match_division\"]" <<< $image_map)
|
||||
dst="$DATA_PATH/$lga/$key$suffix"
|
||||
|
||||
if [ -f $dst ] ; then
|
||||
@@ -55,7 +55,7 @@ for key in $(jq -r 'keys[]' <<< $image_map) ; do
|
||||
fi
|
||||
|
||||
echo "Resizing $dst"
|
||||
convert $IMAGES/$key -resize 400x400 $dst
|
||||
magick $IMAGES/$key -resize 400x400 $dst
|
||||
done
|
||||
|
||||
echo "Generating candidates-generic.csv files."
|
||||
|
||||
Reference in New Issue
Block a user