Calculate scores based on Faith's criteria.
This commit is contained in:
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;
|
||||
}
|
||||
Reference in New Issue
Block a user