|
|
@@ -0,0 +1,219 @@
|
|
|
+<?php
|
|
|
+require_once "libs/fnMain.php";
|
|
|
+
|
|
|
+/**************************
|
|
|
+ * VALIDATION DES DONNEES
|
|
|
+ **************************/
|
|
|
+$isNoteValid = isset($_GET["note"]) && (float) $_GET["note"] !== 0;
|
|
|
+$isAnneeValid = isset($_GET["annee"]) && (int) $_GET["annee"] !== 0;
|
|
|
+
|
|
|
+/**************************
|
|
|
+ * Affichage du formulaire
|
|
|
+ **************************/
|
|
|
+if ($isNoteValid && $isAnneeValid) {
|
|
|
+ // On exclut le cas où les années entrées ne sont pas les bonnes
|
|
|
+ // TIPS : Modifier les années au besoin
|
|
|
+ if ((int) $_GET["annee"] > 2020 || (int) $_GET["annee"] < 2016) {
|
|
|
+ echo "L'année entrée n'est pas valide";
|
|
|
+ die();
|
|
|
+ }
|
|
|
+
|
|
|
+ $rangMoyen = 0; // Variable donnant le rang utilisé pour calculer le tableau des choix, et servant aussi au classement affiché
|
|
|
+ $sqlLimiteBasse = "SELECT * FROM notes_rang
|
|
|
+ WHERE annee = :annee AND note >= :note
|
|
|
+ ORDER BY classement DESC
|
|
|
+ LIMIT 1";
|
|
|
+ $sqlLimiteHaute = "SELECT * FROM notes_rang
|
|
|
+ WHERE annee = :annee AND note <= :note
|
|
|
+ ORDER BY classement
|
|
|
+ LIMIT 1";
|
|
|
+
|
|
|
+ $reqLimBasse = $db->prepare($sqlLimiteBasse);
|
|
|
+ $reqLimBasse->execute([
|
|
|
+ "annee" => $_GET["annee"],
|
|
|
+ "note" => $_GET["note"]
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if ($reqLimBasse->rowCount() === 0) {
|
|
|
+ // Pas de note au dessus de la note entrée => Forcément 1er
|
|
|
+ $rangMoyen = 1;
|
|
|
+ } else {
|
|
|
+ $reqLimiteHaute = $db->prepare($sqlLimiteHaute);
|
|
|
+ $reqLimiteHaute->execute([
|
|
|
+ "annee" => $_GET["annee"],
|
|
|
+ "note" => $_GET["note"]
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $rangBasArray = $reqLimBasse->fetch(PDO::FETCH_ASSOC);
|
|
|
+ if ($reqLimiteHaute->rowCount() === 0) {
|
|
|
+ // Pas de note en dessous => Forcément dernier
|
|
|
+ $rangMoyen = $rangBasArray["classement"] + 10;
|
|
|
+ } else {
|
|
|
+ // Note entre 2 classements connus de la DB
|
|
|
+ $rangHautArray = $reqLimiteHaute->fetch(PDO::FETCH_ASSOC);
|
|
|
+
|
|
|
+ // Ligne non utilisée car révèle les points utilisés (entre xxx et yyy) sont connus
|
|
|
+ // $rangText = "Entre ".$rangBasArray["classement"]." et ".$rangHautArray["classement"];
|
|
|
+
|
|
|
+ $rangMoyen = ((int) $rangBasArray["classement"] + (int) $rangHautArray["classement"]) / 2;
|
|
|
+ $rangMoyen = (int) $rangMoyen;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // HTML renvoyé au site
|
|
|
+ $html = <<<EOF
|
|
|
+ <link rel="stylesheet" href="assets/bootstrap.min.css">
|
|
|
+ <style>
|
|
|
+ /* Tableau */
|
|
|
+ table {
|
|
|
+ font-size: 13px;
|
|
|
+ text-align: center;
|
|
|
+ border-collapse: collapse;
|
|
|
+ white-space: nowrap;
|
|
|
+ overflow: auto;
|
|
|
+ }
|
|
|
+
|
|
|
+ th, td {
|
|
|
+ padding: 2px;
|
|
|
+ border: 1px solid black;
|
|
|
+ --text-color: lightgrey;
|
|
|
+ }
|
|
|
+
|
|
|
+ .all-choices {
|
|
|
+ background-color: #28a745;
|
|
|
+ /* color: #8fd19e; */
|
|
|
+ color: white;
|
|
|
+ }
|
|
|
+
|
|
|
+ .half-choices {
|
|
|
+ background-color: #8fd19e;
|
|
|
+ color: black;
|
|
|
+ }
|
|
|
+
|
|
|
+ .last-choice {
|
|
|
+ background-color: #ffdf7e;
|
|
|
+ color: grey;
|
|
|
+ }
|
|
|
+
|
|
|
+ .no-choice {
|
|
|
+ background-color: #ed969e;
|
|
|
+ }
|
|
|
+
|
|
|
+ .never-available {
|
|
|
+ background-color: lightgrey;
|
|
|
+ }
|
|
|
+ </style>
|
|
|
+ <h2>Tableau de classement pour le rang {$rangMoyen}</h2>
|
|
|
+ <p>Rang estimé pour la note {$_GET["note"]}/10800 : {$rangMoyen}</p>
|
|
|
+ <h3>Légende</h3>
|
|
|
+ <table>
|
|
|
+ <thead>
|
|
|
+ <th colspan="5">Légende (sur toutes les années)</th>
|
|
|
+ </thead>
|
|
|
+ <tbody>
|
|
|
+ <tr>
|
|
|
+ <td>Jamais proposé</td>
|
|
|
+ <td class="no-choice">Aucun choix</td>
|
|
|
+ <td class="last-choice">Une seule année</td>
|
|
|
+ <td class="half-choices">Plusieurs choix</td>
|
|
|
+ <td class="all-choices">Tous les choix</td>
|
|
|
+ </tr>
|
|
|
+ </tbody>
|
|
|
+ </table>
|
|
|
+ <p>
|
|
|
+ Chaque nombre dans chaque case correspond au nombre d'années où ce choix était dispo au classement rentré <br>
|
|
|
+ </p>
|
|
|
+EOF;
|
|
|
+
|
|
|
+ $html .= "<h3>Résultats</h3>";
|
|
|
+
|
|
|
+ // On va récupérer tous les rangs limited dispo triés par idChoix
|
|
|
+ $reqRL = $db->query("SELECT idChoix, annee, rangLimite FROM dataset");
|
|
|
+ $rangLimites = $reqRL->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC);
|
|
|
+
|
|
|
+ // Récupération des datasets
|
|
|
+ $specialityDatasetAbrev = getCsvToArrayKeyValue($_SETTINGS["datasetFolder"]."/liste_specialites_abrev.csv");
|
|
|
+ $specialityDataset = getCsvToArrayKeyValue($_SETTINGS["datasetFolder"]."/liste_specialites.csv");
|
|
|
+ $cityDataset = getCsvToArrayKeyValue($_SETTINGS["datasetFolder"]."/liste_villes.csv");
|
|
|
+ $inputClassement = $rangMoyen;
|
|
|
+
|
|
|
+ // Calcul et affichage des données
|
|
|
+ // Affichage de la 1ère ligne = Titre des colonnes
|
|
|
+ $html .= "<table><thead><tr><th></th>";
|
|
|
+ foreach ($specialityDatasetAbrev as $specialityName) {
|
|
|
+ $html .= "<th scope='col'>".$specialityName."</th>";
|
|
|
+ }
|
|
|
+ $html .= "</tr></thead><tbody>";
|
|
|
+
|
|
|
+ // Affichage de la suite du tableau avec le calcul
|
|
|
+ foreach ($cityDataset as $cityId => $cityName) {
|
|
|
+ // On gère la séparation des différentes régions entre elles (représentées dans le csv villes par les lignes XX_:XX)
|
|
|
+ // La notation des lignes de séparation est sous forme XX_x car si on laissait XX, la fonction getCsvToArrayKeyValue
|
|
|
+ // ne retourne la position que pour la 1ère occurence de XX;XX
|
|
|
+ // La manière de fix ça de manière la plus opti et sale, c'est de faire un substr et de tester les 2 premiers charactères
|
|
|
+ // si ils sont égaux à XX, on fait une séparation
|
|
|
+ // TODO : Faire un parseur csv qui prend en compte chaque ligne du csv dans l'ordre du fichier
|
|
|
+ if (strpos($cityId, "XX") !== FALSE) {
|
|
|
+ $html .= "<tr><th></th>";
|
|
|
+ foreach ($specialityDatasetAbrev as $specialityName) {
|
|
|
+ $html .= "<th scope='col'>".$specialityName."</th>";
|
|
|
+ }
|
|
|
+ $html .= "</th>";
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ $html .= "<tr><th scope='row'>".$cityName."</th>";
|
|
|
+ foreach ($specialityDatasetAbrev AS $specialityId => $specialityName) {
|
|
|
+ $idChoice = "0".$cityId.$specialityId;
|
|
|
+
|
|
|
+ if (!isset($rangLimites[$idChoice])) {
|
|
|
+ $nbAnneePropose = 0;
|
|
|
+ $nbPossibleAnneePropose = 0;
|
|
|
+ } else {
|
|
|
+ $nbAnneePropose = count($rangLimites[$idChoice]);
|
|
|
+ $nbPossibleAnneePropose = 0;
|
|
|
+ foreach ($rangLimites[$idChoice] as $rangLimite) {
|
|
|
+ if ((int) $rangLimite["rangLimite"] >= $inputClassement) {$nbPossibleAnneePropose++;}
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Affichage de la cellule
|
|
|
+ $html .= "<td class=\"";
|
|
|
+ switch (TRUE) {
|
|
|
+ case ($nbPossibleAnneePropose === 0 && $nbAnneePropose === 0):
|
|
|
+ $html .= "never-available";
|
|
|
+ break;
|
|
|
+
|
|
|
+ case ($nbPossibleAnneePropose === 0):
|
|
|
+ $html .= "no-choice";
|
|
|
+ break;
|
|
|
+
|
|
|
+ case ($nbAnneePropose > $nbPossibleAnneePropose && $nbPossibleAnneePropose === 1):
|
|
|
+ $html .= "last-choice";
|
|
|
+ break;
|
|
|
+
|
|
|
+ case ($nbAnneePropose > $nbPossibleAnneePropose && $nbPossibleAnneePropose !== 1):
|
|
|
+ $html .= "half-choices";
|
|
|
+ break;
|
|
|
+
|
|
|
+ case ($nbAnneePropose === $nbPossibleAnneePropose):
|
|
|
+ $html .= "all-choices";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ $html .= "\">";
|
|
|
+ if ($nbPossibleAnneePropose > 0) {
|
|
|
+ $html .= $nbPossibleAnneePropose;
|
|
|
+ }
|
|
|
+ $html .= "</td>";
|
|
|
+ }
|
|
|
+ $html .= "</tr>";
|
|
|
+ }
|
|
|
+
|
|
|
+ $html .= "</tbody></table><br>";
|
|
|
+
|
|
|
+ // Affichage du HTML demandé
|
|
|
+ echo $html;
|
|
|
+} else {
|
|
|
+ echo "Valeurs d'année et/ou note incorrecte.";
|
|
|
+}
|
|
|
+
|