fr -> en code
This commit is contained in:
@@ -21,9 +21,9 @@ if ($verbose) {
|
||||
var_dump($poll);
|
||||
}
|
||||
|
||||
$votants=$poll['votants']['decompte'];
|
||||
$candidats=$poll['candidats'];
|
||||
$nombre_candidats=count($candidats);
|
||||
$voters=$poll['voters']['count'];
|
||||
$candidates=$poll['candidates'];
|
||||
$nombre_candidates=count($candidates);
|
||||
|
||||
# l'ordre des mentions est de la meilleure à la pire (reject)
|
||||
$nom_mentions=$poll['mentions'];
|
||||
@@ -33,22 +33,22 @@ $default_mention=$mentions-1;
|
||||
|
||||
$votes=$poll["votation"]["votes"];
|
||||
if ($verbose) {
|
||||
print("candidats\n");
|
||||
var_dump($candidats);
|
||||
print("candidates\n");
|
||||
var_dump($candidates);
|
||||
print("votes:\n");
|
||||
var_dump($votes);
|
||||
}
|
||||
|
||||
$warnings=[];
|
||||
$default_vote=[];
|
||||
foreach ($candidats as $candidat => $nom_candidat ) {
|
||||
foreach ($candidates as $candidat => $nom_candidat ) {
|
||||
$default_vote[$candidat]=$default_mention;
|
||||
}
|
||||
|
||||
$collect=[];
|
||||
foreach ($votes as $vote) {
|
||||
# missing candidat in vote is the worts one
|
||||
foreach ($candidats as $candidat => $nom_candidat ) {
|
||||
foreach ($candidates as $candidat => $nom_candidat ) {
|
||||
if (! array_key_exists($candidat,$vote)) {
|
||||
$vote[$candidat]=$default_mention;
|
||||
}
|
||||
@@ -78,24 +78,24 @@ if ($verbose) {
|
||||
print(json_encode($collect));
|
||||
}
|
||||
|
||||
$votant_median_check= ($votants % 2 == 0) ? intdiv($votants,2) : intdiv(($votants-1),2) + 1;
|
||||
$voter_median_check= ($voters % 2 == 0) ? intdiv($voters,2) : intdiv(($voters-1),2) + 1;
|
||||
|
||||
$votant_median=intdiv($votants, 2) + $votants % 2;
|
||||
$voter_median=intdiv($voters, 2) + $voters % 2;
|
||||
|
||||
if ( $votant_median_check != $votant_median ) {
|
||||
print('[ERROR] le nombre median de votants (' . $votant_median_check . '/' . $votant_median . ') semble erroné. contactez le developpeur de ce code.');
|
||||
if ( $voter_median_check != $voter_median ) {
|
||||
print('[ERROR] le nombre median de voters (' . $voter_median_check . '/' . $voter_median . ') semble erroné. contactez le developpeur de ce code.');
|
||||
}
|
||||
|
||||
$merite=[];
|
||||
$merit=[];
|
||||
$mention_mediane=[];
|
||||
$merite_pourcent=[];
|
||||
$merit_pourcent=[];
|
||||
|
||||
# cumul : du meilleur au pire
|
||||
# range_mentions = range(count(mentions))
|
||||
# cumul du pire au meilleur
|
||||
$range_mentions = $mentions;
|
||||
|
||||
foreach ($candidats as $candidat => $nom_candidat) {
|
||||
foreach ($candidates as $candidat => $nom_candidat) {
|
||||
$vote=$collect[$candidat];
|
||||
$cumul=0;
|
||||
for ($i=0; $i < $range_mentions; $i ++) {
|
||||
@@ -106,24 +106,24 @@ foreach ($candidats as $candidat => $nom_candidat) {
|
||||
for ($mention=$range_mentions -1; $mention >=0; $mention --) {
|
||||
if ( array_key_exists($mention,$vote) ) {
|
||||
$cumul=$cumul+$vote[$mention];
|
||||
$pourcent[$mention]= ( 100 * $vote[$mention] ) / $votants;
|
||||
$pourcent[$mention]= ( 100 * $vote[$mention] ) / $voters;
|
||||
}
|
||||
if ($cumul >= $votant_median and $mention_m == null ) {
|
||||
if ($cumul >= $voter_median and $mention_m == null ) {
|
||||
$mention_m=$mention;
|
||||
}
|
||||
$m[$mention]=$cumul;
|
||||
}
|
||||
if ($cumul < $votants) {
|
||||
print("[ERROR] le cumul des votes " . $cumul . " doit correspondre au nombre de votants. contactez le developpeur de ce code.");
|
||||
if ($cumul < $voters) {
|
||||
print("[ERROR] votes cumulated " . $cumul . " should match voters. Contact this code developer.");
|
||||
}
|
||||
$mention_mediane[$candidat]=$mention_m;
|
||||
$merite[$candidat]=$m;
|
||||
$merite_pourcent[$candidat]=$pourcent;
|
||||
$merit[$candidat]=$m;
|
||||
$merit_pourcent[$candidat]=$pourcent;
|
||||
}
|
||||
|
||||
if ($verbose) {
|
||||
print("\nmerite:\n");
|
||||
print(json_encode($merite));
|
||||
print("\nmerit:\n");
|
||||
print(json_encode($merit));
|
||||
print("\nmention_mediane:\n");
|
||||
print(json_encode($mention_mediane));
|
||||
}
|
||||
@@ -132,10 +132,10 @@ if ($verbose) {
|
||||
$found=[];
|
||||
|
||||
for ($mention = 0; $mention < $mentions; $mention ++) {
|
||||
foreach ($mention_mediane as $candidat => $merite_median)
|
||||
if ($merite_median == $mention) {
|
||||
foreach ($mention_mediane as $candidat => $merit_median)
|
||||
if ($merit_median == $mention) {
|
||||
$item=[];
|
||||
$item[$candidat]=$candidats[$candidat];
|
||||
$item[$candidat]=$candidates[$candidat];
|
||||
array_push($found,$item);
|
||||
}
|
||||
if (count($found) > 0) {
|
||||
@@ -148,7 +148,7 @@ if ($verbose) {
|
||||
print($nom_mentions[$mention]);
|
||||
}
|
||||
|
||||
$result = ['resultat'=> ['mention'=>$nom_mentions[$mention],'candidats' => $found],'merite' => $merite,'profil' => $merite_pourcent,"warnings" => $warnings];
|
||||
$result = ['result'=> ['mention'=>$nom_mentions[$mention],'candidates' => $found],'merit' => $merit,'profil' => $merit_pourcent,"warnings" => $warnings];
|
||||
|
||||
print(json_encode($result));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user