Start generating image download script.

This commit is contained in:
Kim Taylor
2024-09-22 22:57:35 +10:00
parent 219b242503
commit f9c151bfae
5 changed files with 111 additions and 63 deletions

View File

@@ -35,6 +35,9 @@ foreach ($config_files as $config_file) {
$lga_list[] = $config;
}
/* Match user typed LGA/Ward to our database */
match_lga($candidate_data, $lga_list);
/* Calculate score for candidate */
foreach ($candidate_data as &$candidate) {
$score = 0;
@@ -48,46 +51,6 @@ foreach ($candidate_data as &$candidate) {
$candidate['Score'] = $score;
}
foreach ($candidate_data as &$candidate) {
/* Match user typed LGA/Ward to our database */
$max_score = 0;
foreach ($lga_list as $lga) {
$aa = preg_split("/[^a-z]/", strtolower($candidate['LGA']));
$bb = preg_split("/[^a-z]/", $lga['slug']);
$score_sum = 0;
foreach ($aa as $a) {
foreach ($bb as $b) {
similar_text($a, $b, $score);
if ($score > 70) $score_sum += $score;
else $score_sum -= 10;
}
}
if ($score_sum > $max_score) {
$max_score = $score_sum;
$match_lga = $lga;
}
}
$max_score = 0;
foreach ($match_lga['wardNames'] as $ward) {
similar_text($ward, $candidate['Ward'], $score);
if ($score > $max_score) {
$max_score = $score;
$match_ward = $ward;
}
}
$candidate['match_lga'] = $match_lga['slug'];
$candidate['match_ward'] = $match_ward;
}
/* Get picture */
foreach ($candidate_data as &$candidate) {
$candidate['match_picture'] = "";
}
$header = ["Ward", "Candidate Name", "Rating", "Picture"];
/* Generate candidates-generic.csv */
@@ -115,7 +78,7 @@ foreach ($lga_list as $lga) {
$candidate['match_ward'],
$candidate['Name'],
$candidate['Score'],
$candidate['match_picture'],
$candidate['Photo'],
];
if (fputcsv($handle, $fields) === FALSE) {