1
0

test asort

This commit is contained in:
Daniel Tartavel 2022-09-23 00:52:56 +02:00
parent d8b19465e4
commit f5c2f4309f
4 changed files with 113 additions and 36 deletions

View File

@ -0,0 +1,67 @@
<?php
class schulze
{
public int $nvotant;
public int $ncandidats;
public array $nvotes;
$v = array(
array(5, 1, 3, 2, 4),
array(1, 5, 2, 4, 3),
array(5, 3, 2, 4, 1),
array(5, 1, 3, 2, 4)
);
function matrix()
{
foreach($nvotes as $votes)
{
for ($i=1;$i<=$votes;$i++)
{
for ($j=1;$j<=$ncandidats;$j++)
{
void
}
}
}
}
function test($v)
{
asort($v);
var_dump($v);
}
function result()
{
for ($i=1;$i<=$ncandidats;$i++)
{
for ($j=1;$j<=$ncandidats;$j++)
{
if ($d[$i][$j] > $d[$j][$i])
{
$p[$i][$j] = $d[$i][$j];
}else
{
$p[$i][$j] = 0;
}
}
}
for ($i=1;$i<=$ncandidats;$i++)
{
for ($j=1;$j<=$ncandidats;$j++)
{
for ($k=1;$k<=$ncandidats;$k++)
{
if ($j != $k)
{
$p[$j][$k] = max($p[$j][$k], min($p[$j][$i],$p[$i][$k]));
}
}
}
return $p;
}
}
}
?>

4
test.php Normal file
View File

@ -0,0 +1,4 @@
<?php
$vote = new schulze;
$vote->test();
?>

View File

@ -12,9 +12,9 @@ $idVotation = $_GET["v"];
$dolibarr = new dbDolibarr();
$query = "SELECT * FROM llx_adherent as a LEFT JOIN llx_adherent_type as t ON a.fk_adherent_type=t.rowid WHERE a.login='" . $dolibarr->protect($idVotant) . "' AND (DATE(a.datefin)>=CURDATE() OR t.subscription=0) AND t.vote=1";
print $query .EOLH;
print $query . EOLH;
$result = $dolibarr->query($query);
print_r($dolibarr);
//print_r($dolibarr);
$votant = $dolibarr->result->fetch_array();
print('<br><br>
<!-- lalis Grid Section -->

View File

@ -64,41 +64,48 @@ print(' <br><br>
$votes = $db->result->fetch_all(MYSQLI_ASSOC);
foreach ($votes as $vote)
{
$total = 0;
echo "<div><h5>" . $vote["libelle"] . "</h5><br>";
$query='SELECT * FROM liste_candidats WHERE idVotation=' . $idVotation . ' AND idVote=' . $vote["id"];
$result = $db->query($query);
$candidats = $db->result->fetch_all(MYSQLI_ASSOC);
echo "<pre>";
//$resultatCandidats = '';
switch ($vote["method"])
{
case 1:
$total = 0;
echo "<div><h5>" . $vote["libelle"] . "</h5><br>";
$query='SELECT * FROM liste_candidats WHERE idVotation=' . $idVotation . ' AND idVote=' . $vote["id"];
$result = $db->query($query);
$candidats = $db->result->fetch_all(MYSQLI_ASSOC);
echo "<pre>";
//$resultatCandidats = '';
$query='SELECT COUNT(*) as n FROM votes WHERE idVotation=' . $db->protect($idVotation) . ' AND idVote=' . $vote["id"] .' AND idCandidat=0';
$result = $db->query($query);
$resultat = $db->result->fetch_array(MYSQLI_ASSOC);
$blanc = $resultat["n"];
echo 'Votes blancs&nbsp;: ' . $blanc . '<br>';
foreach($candidats as $candidat)
{
$query='SELECT COUNT(*) as n FROM votes WHERE idVotation=' . $db->protect($idVotation) . ' AND idVote=' . $vote["id"] .' AND idCandidat=' . $candidat["id"];
$result = $db->query($query);
$resultat = $db->result->fetch_array(MYSQLI_ASSOC);
echo $candidat["candidat"] . '&nbsp;:' . $resultat["n"] . '<br>';
$resultatCandidats[$candidat['candidat']] = $resultat["n"];
$total += $resultat["n"];
$query='SELECT COUNT(*) as n FROM votes WHERE idVotation=' . $db->protect($idVotation) . ' AND idVote=' . $vote["id"] .' AND idCandidat=0';
$result = $db->query($query);
$resultat = $db->result->fetch_array(MYSQLI_ASSOC);
$blanc = $resultat["n"];
echo 'Votes blancs&nbsp;: ' . $blanc . '<br>';
foreach($candidats as $candidat)
{
$query='SELECT COUNT(*) as n FROM votes WHERE idVotation=' . $db->protect($idVotation) . ' AND idVote=' . $vote["id"] .' AND idCandidat=' . $candidat["id"];
$result = $db->query($query);
$resultat = $db->result->fetch_array(MYSQLI_ASSOC);
echo $candidat["candidat"] . '&nbsp;:' . $resultat["n"] . '<br>';
$resultatCandidats[$candidat['candidat']] = $resultat["n"];
$total += $resultat["n"];
}
array_multisort($resultatCandidats, SORT_DESC, SORT_NUMERIC);
reset($resultatCandidats);
if ($total >= $blanc)
{
print("<h5>Remporte le vote : " . key($resultatCandidats));
unset($resultatCandidats);
print("</h5>");
}else
{
print("<h5>Aucun candidat n'emporte le vote, car il y a plus de 50% de votes blancs.</h5>");
}
listeVotants($idVotation, $vote["id"], $listeAdherents);
print("</pre></div><br>" . EOLH);
break;
default:
break;
}
array_multisort($resultatCandidats, SORT_DESC, SORT_NUMERIC);
reset($resultatCandidats);
if ($total >= $blanc)
{
print("<h5>Remporte le vote : " . key($resultatCandidats));
unset($resultatCandidats);
print("</h5>");
}else
{
print("<h5>Aucun candidat n'emporte le vote, car il y a plus de 50% de votes blancs.</h5>");
}
listeVotants($idVotation, $vote["id"], $listeAdherents);
print("</pre></div><br>" . EOLH);
}
}else
{
@ -106,7 +113,6 @@ print(' <br><br>
}
}
print (' <div>
</div>
</div>