apiTableauFromClassement.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. require_once "libs/fnMain.php";
  3. /**************************
  4. * Contrôle du token JWT
  5. **************************/
  6. if (!isset($_GET["jwt"], $_SETTINGS["jwt_secret"])) {
  7. echo "Manque d'arguments";
  8. die();
  9. }
  10. verifyJWTtoken($_GET["jwt"], $_SETTINGS["jwt_secret"]);
  11. /**************************
  12. * Contrôle du statut premium de l'utilisateur
  13. **************************/
  14. verifyUserPremium($_GET["jwt"]);
  15. /**************************
  16. * GENERATION DES CLASSEMENTS
  17. **************************/
  18. $isClassementValid = isset($_GET["classement"]) && (int) $_GET["classement"] !== 0;
  19. if ($isClassementValid) {
  20. $rangMoyen = (int) $_GET["classement"];
  21. // HTML renvoyé au site
  22. $html = <<<EOF
  23. <link rel="stylesheet" href="assets/bootstrap.min.css">
  24. <style>
  25. /* Tableau */
  26. table {
  27. font-size: 13px;
  28. text-align: center;
  29. border-collapse: collapse;
  30. white-space: nowrap;
  31. overflow: auto;
  32. }
  33. th, td {
  34. padding: 2px;
  35. border: 1px solid black;
  36. --text-color: lightgrey;
  37. }
  38. .all-choices {
  39. background-color: #28a745;
  40. /* color: #8fd19e; */
  41. color: white;
  42. }
  43. .half-choices {
  44. background-color: #8fd19e;
  45. color: black;
  46. }
  47. .last-choice {
  48. background-color: #ffdf7e;
  49. color: grey;
  50. }
  51. .no-choice {
  52. background-color: #ed969e;
  53. }
  54. .never-available {
  55. background-color: lightgrey;
  56. }
  57. </style>
  58. <h2>Tableau de classement pour le rang {$rangMoyen}</h2>
  59. <!--
  60. <h3>Légende</h3>
  61. <table>
  62. <thead>
  63. <th colspan="5">Légende (sur toutes les années)</th>
  64. </thead>
  65. <tbody>
  66. <tr>
  67. <td>Jamais proposé</td>
  68. <td class="no-choice">Aucun choix</td>
  69. <td class="last-choice">Une seule année</td>
  70. <td class="half-choices">Plusieurs choix</td>
  71. <td class="all-choices">Tous les choix</td>
  72. </tr>
  73. </tbody>
  74. </table> -->
  75. <p>
  76. Chaque nombre dans chaque case correspond au nombre d'années où ce choix était dispo au classement rentré <br>
  77. </p>
  78. EOF;
  79. $html .= "<h3>Résultats</h3>";
  80. // On va récupérer tous les rangs limited dispo triés par idChoix
  81. $reqRL = $db->query("SELECT idChoix, annee, rangLimite FROM dataset");
  82. $rangLimites = $reqRL->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC);
  83. // Récupération des datasets
  84. $specialityDatasetAbrev = getCsvToArrayKeyValue($_SETTINGS["datasetFolder"]."/liste_specialites_abrev.csv");
  85. $specialityDataset = getCsvToArrayKeyValue($_SETTINGS["datasetFolder"]."/liste_specialites.csv");
  86. $cityDataset = getCsvToArrayKeyValue($_SETTINGS["datasetFolder"]."/liste_villes.csv");
  87. $inputClassement = $rangMoyen;
  88. // Calcul et affichage des données
  89. // Affichage de la 1ère ligne = Titre des colonnes
  90. $html .= "<table><thead><tr><th></th>";
  91. foreach ($specialityDatasetAbrev as $specialityName) {
  92. $html .= "<th scope='col'>".$specialityName."</th>";
  93. }
  94. $html .= "</tr></thead><tbody>";
  95. // Affichage de la suite du tableau avec le calcul
  96. foreach ($cityDataset as $cityId => $cityName) {
  97. // 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)
  98. // La notation des lignes de séparation est sous forme XX_x car si on laissait XX, la fonction getCsvToArrayKeyValue
  99. // ne retourne la position que pour la 1ère occurence de XX;XX
  100. // 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
  101. // si ils sont égaux à XX, on fait une séparation
  102. // TODO : Faire un parseur csv qui prend en compte chaque ligne du csv dans l'ordre du fichier
  103. if (strpos($cityId, "XX") !== FALSE) {
  104. $html .= "<tr><th></th>";
  105. foreach ($specialityDatasetAbrev as $specialityName) {
  106. $html .= "<th scope='col'>".$specialityName."</th>";
  107. }
  108. $html .= "</th>";
  109. continue;
  110. }
  111. $html .= "<tr><th scope='row'>".$cityName."</th>";
  112. foreach ($specialityDatasetAbrev AS $specialityId => $specialityName) {
  113. $idChoice = "0".$cityId.$specialityId;
  114. if (!isset($rangLimites[$idChoice])) {
  115. $nbAnneePropose = 0;
  116. $nbPossibleAnneePropose = 0;
  117. } else {
  118. $nbAnneePropose = count($rangLimites[$idChoice]);
  119. $nbPossibleAnneePropose = 0;
  120. foreach ($rangLimites[$idChoice] as $rangLimite) {
  121. if ((int) $rangLimite["rangLimite"] >= $inputClassement) {$nbPossibleAnneePropose++;}
  122. }
  123. }
  124. // Affichage de la cellule
  125. $html .= "<td class=\"";
  126. switch (TRUE) {
  127. case ($nbPossibleAnneePropose === 0 && $nbAnneePropose === 0):
  128. $html .= "never-available";
  129. break;
  130. case ($nbPossibleAnneePropose === 0):
  131. $html .= "no-choice";
  132. break;
  133. case ($nbAnneePropose > $nbPossibleAnneePropose && $nbPossibleAnneePropose === 1):
  134. $html .= "last-choice";
  135. break;
  136. case ($nbAnneePropose > $nbPossibleAnneePropose && $nbPossibleAnneePropose !== 1):
  137. $html .= "half-choices";
  138. break;
  139. case ($nbAnneePropose === $nbPossibleAnneePropose):
  140. $html .= "all-choices";
  141. break;
  142. }
  143. $html .= "\">";
  144. if ($nbPossibleAnneePropose > 0) {
  145. $html .= $nbPossibleAnneePropose;
  146. } else if ($nbPossibleAnneePropose === 0) {
  147. $html .= "0";
  148. }
  149. $html .= "</td>";
  150. }
  151. $html .= "</tr>";
  152. }
  153. $html .= "</tbody></table><br>";
  154. // Affichage du HTML demandé
  155. echo $html;
  156. } else {
  157. echo "Classement entré incorrect.";
  158. }