BioTorrents.de’s version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

torrents.php 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. #declare(strict_types=1);
  3. /*
  4. ...
  5. DESC
  6. LIMIT 1, 12
  7. */
  8. if (!list($Labels, $InFlow, $OutFlow, $Max) = $Cache->get_value('torrents_timeline')) {
  9. $DB->query("
  10. SELECT
  11. DATE_FORMAT(`Time`, '%b %Y') AS Month,
  12. COUNT(`ID`)
  13. FROM
  14. `log`
  15. WHERE
  16. `Message` LIKE 'Torrent % uploaded %'
  17. GROUP BY
  18. `Month`
  19. ORDER BY
  20. `Time`
  21. DESC
  22. ");
  23. $TimelineIn = array_reverse($DB->to_array());
  24. $DB->query("
  25. SELECT
  26. DATE_FORMAT(`Time`, '%b %Y') AS Month,
  27. COUNT(`ID`)
  28. FROM
  29. `log`
  30. WHERE
  31. `Message` LIKE 'Torrent % deleted %'
  32. GROUP BY
  33. `Month`
  34. ORDER BY
  35. `Time`
  36. DESC
  37. ");
  38. $TimelineOut = array_reverse($DB->to_array());
  39. foreach ($TimelineIn as $Month) {
  40. list($Labels[], $InFlow[]) = $Month;
  41. }
  42. foreach ($TimelineOut as $Month) {
  43. list(, $OutFlow[]) = $Month;
  44. }
  45. $Cache->cache_value('torrents_timeline', array($Labels, $InFlow, $OutFlow, $Max), mktime(0, 0, 0, date('n') + 1, 2)); //Tested: fine for dec -> jan
  46. }
  47. if (!$CategoryDistribution = $Cache->get_value('category_distribution')) {
  48. $DB->query("
  49. SELECT
  50. tg.`category_id`,
  51. COUNT(t.`ID`) AS Torrents
  52. FROM
  53. `torrents` AS t
  54. JOIN `torrents_group` AS tg
  55. ON
  56. tg.`id` = t.`GroupID`
  57. GROUP BY
  58. tg.`category_id`
  59. ORDER BY
  60. `Torrents`
  61. DESC
  62. ");
  63. $CategoryDistribution = $DB->to_array();
  64. $Cache->cache_value('category_distribution', $CategoryDistribution, 3600 * 24 * 14);
  65. }
  66. foreach ($CategoryDistribution as $i => $Category) {
  67. list($CategoryID, $Torrents) = $Category;
  68. $CategoryDistribution[$i]['CategoryID'] = $Categories[$CategoryID - 1];
  69. }
  70. View::show_header('Detailed torrent statistics', 'vendor/chart.min');
  71. ?>
  72. <h2 class="header">
  73. Torrent Stats
  74. </h2>
  75. <h3>
  76. Flow
  77. </h3>
  78. <div class="box pad center">
  79. <canvas class="chart" id="chart_torrents_timeline" width="80%"></canvas>
  80. <script>
  81. var ctx = document.getElementById('chart_torrents_timeline').getContext('2d');
  82. var myChart = new Chart(ctx, {
  83. type: 'line',
  84. data: {
  85. labels: <?= ' ["'.implode('","', $Labels).'"]'; ?> ,
  86. datasets: [{
  87. label: 'New Torrents',
  88. backgroundColor: 'rgba(179, 229, 252, 0.8)', // #B3E5FC
  89. borderColor: 'rgba(1, 87, 155, 0.8)', // #01579B
  90. data:
  91. <?= "[".implode(",", $InFlow)."]"; ?>
  92. },
  93. {
  94. label: 'Deleted Torrents',
  95. backgroundColor: 'rgba(255, 224, 178, 0.8)', // #FFE0B2
  96. borderColor: 'rgba(230, 81, 0, 0.8)', // #E65100
  97. data:
  98. <?= "[".implode(",", $OutFlow)."]"; ?>
  99. }
  100. ]
  101. }
  102. });
  103. </script>
  104. </div>
  105. <h3>
  106. Categories
  107. </h3>
  108. <div class="box pad center">
  109. <canvas class="chart" id="chart_torrent_categories" width="80%"></canvas>
  110. <script>
  111. var ctx = document.getElementById('chart_torrent_categories').getContext('2d');
  112. var myChart = new Chart(ctx, {
  113. type: 'pie',
  114. data: {
  115. labels: <?= ' ["'.implode('","', array_column($CategoryDistribution, 'CategoryID')).'"]'; ?> ,
  116. datasets: [{
  117. data:
  118. <?= "[".implode(",", array_column($CategoryDistribution, 'Torrents'))."]"; ?>
  119. ,
  120. backgroundColor: [
  121. 'rgba(255, 205, 210, 0.8)', // #FFCDD2
  122. 'rgba(225, 190, 231, 0.8)', // #E1BEE7
  123. 'rgba(197, 202, 233, 0.8)', // #C5CAE9
  124. 'rgba(179, 229, 252, 0.8)', // #B3E5FC
  125. 'rgba(178, 223, 219, 0.8)', // #B2DFDB
  126. 'rgba(220, 237, 200, 0.8)', // #DCEDC8
  127. 'rgba(255, 249, 196, 0.8)', // #FFF9C4
  128. 'rgba(255, 224, 178, 0.8)', // #FFE0B2
  129. 'rgba(215, 204, 200, 0.8)', // #D7CCC8
  130. 'rgba(207, 216, 220, 0.8)', // #CFD8DC
  131. 'rgba(158, 158, 158, 0.8)', // #9E9E9E
  132. ]
  133. }]
  134. }
  135. });
  136. </script>
  137. </div>
  138. <?php
  139. include SERVER_ROOT.'/sections/tools/data/database_specifics.php';
  140. View::show_footer();