Calculate scores based on Faith's criteria.
This commit is contained in:
31
csv-generic/gen-generic.php
Normal file
31
csv-generic/gen-generic.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once("parse_generic_csv.php");
|
||||||
|
|
||||||
|
$options = getopt("", ["generic-csv:"]);
|
||||||
|
|
||||||
|
if (isset($options['generic-csv'])) {
|
||||||
|
$generic_csv = $options['generic-csv'];
|
||||||
|
} else {
|
||||||
|
error_log("Error: Missing required option '--generic-csv'.");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$candidate_data = parse_generic_csv($generic_csv);
|
||||||
|
|
||||||
|
/* Calculate score for candidate */
|
||||||
|
foreach ($candidate_data as &$candidate) {
|
||||||
|
$score = 0;
|
||||||
|
|
||||||
|
if ($candidate['Pledge'] === "Yes") $score++;
|
||||||
|
if ($candidate['q1'] === "Yes") $score++;
|
||||||
|
if ($candidate['q3'] === "Yes") $score++;
|
||||||
|
if ($candidate['q4'] === "Yes") $score++;
|
||||||
|
if ($candidate['q7'] === "Yes") $score++;
|
||||||
|
|
||||||
|
$candidate['Score'] = $score;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_r($candidate_data);
|
||||||
|
|
||||||
|
exit(0);
|
||||||
46
csv-generic/parse_generic_csv.php
Normal file
46
csv-generic/parse_generic_csv.php
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
function parse_generic_csv($generic_csv) {
|
||||||
|
$candidate_data = [];
|
||||||
|
if (($handle = fopen($generic_csv, "r")) !== FALSE) {
|
||||||
|
$headers = fgetcsv($handle);
|
||||||
|
while (($data = fgetcsv($handle)) !== FALSE) {
|
||||||
|
$candidate = [];
|
||||||
|
$question_no = 0;
|
||||||
|
$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, "Political Party")) $value = "Party";
|
||||||
|
|
||||||
|
if ($value === "Pledge") {
|
||||||
|
if (strstr($data[$key], "I pledge")) $data[$key] = "Yes";
|
||||||
|
else $data[$key] = "No";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($is_question) {
|
||||||
|
$candidate['q'.$question_no++] = $data[$key];
|
||||||
|
} else {
|
||||||
|
$candidate[$value] = $data[$key];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($value === "Pledge") {
|
||||||
|
$is_question = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$candidate_data[] = $candidate;
|
||||||
|
}
|
||||||
|
fclose($handle);
|
||||||
|
} else {
|
||||||
|
error_log('Error opening candidates file');
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $candidate_data;
|
||||||
|
}
|
||||||
12
get-generic.sh
Executable file
12
get-generic.sh
Executable file
@@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
DATA_LOC=../generic-survey
|
||||||
|
|
||||||
|
#rclone sync --progress bikewest:spl_generic_survey_2024 $DATA_LOC/google-data
|
||||||
|
|
||||||
|
#rclone --drive-export-formats csv copyto 'bikewest:spl_generic_survey_2024/Streets People Love council election candidate pledge and survey (Responses).csv' $DATA_LOC/responses.csv
|
||||||
|
|
||||||
|
|
||||||
|
#content=$(php pledge-update/pledge-page.php --candidates-files "${candidates_files[*]}")
|
||||||
|
|
||||||
|
php csv-generic/gen-generic.php --generic-csv $DATA_LOC/responses.csv
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
DATA_LOC=../generic-survey
|
|
||||||
|
|
||||||
rclone sync --progress bikewest:spl_generic_survey_2024 $DATA_LOC/google-data
|
|
||||||
|
|
||||||
rclone --drive-export-formats csv copyto 'bikewest:spl_generic_survey_2024/Streets People Love council election candidate pledge and survey (Responses).csv' $DATA_LOC/responses.csv
|
|
||||||
Reference in New Issue
Block a user