Oppaitime'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.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?
  2. if (!list($Labels, $InFlow, $OutFlow, $Max) = $Cache->get_value('torrents_timeline')) {
  3. $DB->query("
  4. SELECT DATE_FORMAT(Time,\"%b %Y\") AS Month, COUNT(ID)
  5. FROM log
  6. WHERE Message LIKE 'Torrent % was uploaded by %'
  7. GROUP BY Month
  8. ORDER BY Time DESC
  9. LIMIT 1, 12");
  10. $TimelineIn = array_reverse($DB->to_array());
  11. $DB->query("
  12. SELECT DATE_FORMAT(Time,\"%b %Y\") AS Month, COUNT(ID)
  13. FROM log
  14. WHERE Message LIKE 'Torrent % was deleted %'
  15. GROUP BY Month
  16. ORDER BY Time DESC
  17. LIMIT 1, 12");
  18. $TimelineOut = array_reverse($DB->to_array());
  19. foreach ($TimelineIn as $Month) {
  20. list($Labels[], $InFlow[]) = $Month;
  21. }
  22. foreach ($TimelineOut as $Month) {
  23. list(, $OutFlow[]) = $Month;
  24. }
  25. $Cache->cache_value('torrents_timeline', array($Labels, $InFlow, $OutFlow, $Max), mktime(0, 0, 0, date('n') + 1, 2)); //Tested: fine for dec -> jan
  26. }
  27. if (!$CategoryDistribution = $Cache->get_value('category_distribution')) {
  28. $DB->query("
  29. SELECT tg.CategoryID, COUNT(t.ID) AS Torrents
  30. FROM torrents AS t
  31. JOIN torrents_group AS tg ON tg.ID = t.GroupID
  32. GROUP BY tg.CategoryID
  33. ORDER BY Torrents DESC");
  34. $CategoryDistribution = $DB->to_array();
  35. $Cache->cache_value('category_distribution', $CategoryDistribution, 3600 * 24 * 14);
  36. }
  37. foreach ($CategoryDistribution as $i => $Category) {
  38. list($CategoryID, $Torrents) = $Category;
  39. $CategoryDistribution[$i]['CategoryID'] = $Categories[$CategoryID - 1];
  40. }
  41. View::show_header('Detailed torrent statistics', 'chart');
  42. ?>
  43. <h3 id="Upload_Flow"><a href="#Upload_Flow">Uploads by month</a></h3>
  44. <div class="box pad center">
  45. <canvas class="chart" id="chart_torrents_timeline"></canvas>
  46. <script>
  47. new Chart($('#chart_torrents_timeline').raw().getContext('2d'), {
  48. type: 'line',
  49. data: {
  50. labels: <? print '["'.implode('","',$Labels).'"]'; ?>,
  51. datasets: [ {
  52. label: "New Torrents",
  53. backgroundColor: "rgba(0,0,255,0.2)",
  54. borderColor: "rgba(0,0,255,0.8)",
  55. data: <? print "[".implode(",",$InFlow)."]"; ?>
  56. }, {
  57. label: "Deleted Torrents",
  58. backgroundColor: "rgba(255,0,0,0.2)",
  59. borderColor: "rgba(255,0,0,0.8)",
  60. data: <? print "[".implode(",",$OutFlow)."]"; ?>
  61. }]
  62. }
  63. })
  64. </script>
  65. </div>
  66. <h3 id="Torrent_Categories"><a href="#Torrent_Categories">Torrents by category</a></h3>
  67. <div class="box pad center">
  68. <canvas class="chart" id="chart_torrent_categories"></canvas>
  69. <script>
  70. new Chart($('#chart_torrent_categories').raw().getContext('2d'), {
  71. type: 'pie',
  72. data: {
  73. labels: <? print '["'.implode('","', array_column($CategoryDistribution, 'CategoryID')).'"]'; ?>,
  74. datasets: [ {
  75. data: <? print "[".implode(",", array_column($CategoryDistribution, 'Torrents'))."]"; ?>,
  76. backgroundColor: ['#8a00b8','#a944cb','#be71d8','#e8ccf1', '#f3e3f9', '#fbf6fd', '#ffffff']
  77. }]
  78. }
  79. })
  80. </script>
  81. </div>
  82. <?
  83. View::show_footer();