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

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