rankings.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * copyright 2018 SuperTuxKart-Team
  4. * This file is part of stk-addons.
  5. *
  6. * stk-addons is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * stk-addons is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with stk-addons. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. require_once(__DIR__ . DIRECTORY_SEPARATOR . "config.php");
  20. $tpl = StkTemplate::get('rankings.tpl')
  21. ->addDataTablesLibrary()
  22. ->addScriptInclude("stats.js");
  23. $tpl->assignTitle(_h('Player Rankings'));
  24. // disconnects is a 64bit bitflag,
  25. // divide it with min(num_races_done, 64) for races done < 64 to have correct value
  26. $query_rankings = <<<SQL
  27. SELECT
  28. IF (@score=s.scores, @rank:=@rank, @rank:=@rank+1)
  29. `Rank`,
  30. username `Username`,
  31. ROUND(@score:=s.scores,2) `Scores`,
  32. ROUND(max_scores, 2) `Maximum scores obtained`,
  33. num_races_done `Races done`,
  34. ROUND(rating_deviation, 2) `Rating Deviation`,
  35. concat(ROUND(BIT_COUNT(disconnects) /
  36. CAST(LEAST(num_races_done, 64) AS DOUBLE) * 100.0 , 2), '%') `Disconnection rate`
  37. FROM `{DB_VERSION}_rankings` s
  38. INNER JOIN `{DB_VERSION}_users` ON user_id = `{DB_VERSION}_users`.id,
  39. (SELECT @score:=0, @rank:=0) r
  40. ORDER BY Scores DESC
  41. SQL;
  42. $player_data = [ "sections" => [ Statistic::getSection($query_rankings) ] ];
  43. $tpl->assign("player_rankings", $player_data);
  44. echo $tpl;