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 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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" data-chart='{
  46. "type": "line",
  47. "data": {
  48. "labels": <? print '["'.implode('","',$Labels).'"]'; ?>,
  49. "datasets": [ {
  50. "label": "New Torrents",
  51. "backgroundColor": "rgba(0,0,255,0.2)",
  52. "borderColor": "rgba(0,0,255,0.8)",
  53. "data": <? print "[".implode(",",$InFlow)."]"; ?>
  54. }, {
  55. "label": "Deleted Torrents",
  56. "backgroundColor": "rgba(255,0,0,0.2)",
  57. "borderColor": "rgba(255,0,0,0.8)",
  58. "data": <? print "[".implode(",",$OutFlow)."]"; ?>
  59. }]
  60. }
  61. }'></canvas>
  62. </div>
  63. <h3 id="Torrent_Categories"><a href="#Torrent_Categories">Torrents by category</a></h3>
  64. <div class="box pad center">
  65. <canvas class="chart" id="chart_torrent_categories" data-chart='{
  66. "type": "pie",
  67. "data": {
  68. "labels": <? print '["'.implode('","', array_column($CategoryDistribution, 'CategoryID')).'"]'; ?>,
  69. "datasets": [ {
  70. "data": <? print "[".implode(",", array_column($CategoryDistribution, 'Torrents'))."]"; ?>,
  71. "backgroundColor": ["#8a00b8","#a944cb","#be71d8","#e8ccf1","#f3e3f9","#fbf6fd","#ffffff"]
  72. }]
  73. }
  74. }'></canvas>
  75. </div>
  76. <?
  77. View::show_footer();