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.

user_flow.php 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. if (!check_perms('site_view_flow')) {
  3. error(403);
  4. }
  5. // Timeline generation
  6. if (!isset($_GET['page'])) {
  7. if (!list($Labels, $InFlow, $OutFlow) = $Cache->get_value('users_timeline')) {
  8. $DB->query("
  9. SELECT DATE_FORMAT(JoinDate, \"%b %y\") AS Month, COUNT(UserID)
  10. FROM users_info
  11. GROUP BY Month
  12. ORDER BY JoinDate DESC
  13. LIMIT 1, 11");
  14. $TimelineIn = array_reverse($DB->to_array());
  15. $DB->query("
  16. SELECT DATE_FORMAT(BanDate, \"%b %y\") AS Month, COUNT(UserID)
  17. FROM users_info
  18. WHERE BanDate > 0
  19. GROUP BY Month
  20. ORDER BY BanDate DESC
  21. LIMIT 1, 11");
  22. $TimelineOut = array_reverse($DB->to_array());
  23. $Labels = [];
  24. foreach ($TimelineIn as $Month) {
  25. list($Labels[], $InFlow[]) = $Month;
  26. }
  27. foreach ($TimelineOut as $Month) {
  28. list(, $OutFlow[]) = $Month;
  29. }
  30. $Cache->cache_value('users_timeline', array($Labels, $InFlow, $OutFlow), mktime(0, 0, 0, date('n') + 1, 2));
  31. }
  32. }
  33. // End timeline generation
  34. define('DAYS_PER_PAGE', 100);
  35. list($Page, $Limit) = Format::page_limit(DAYS_PER_PAGE);
  36. # wtf
  37. $RS = $DB->query("
  38. SELECT
  39. SQL_CALC_FOUND_ROWS
  40. j.Date,
  41. DATE_FORMAT(j.Date, '%Y-%m') AS Month,
  42. CASE ISNULL(j.Flow)
  43. WHEN 0 THEN j.Flow
  44. ELSE '0'
  45. END AS Joined,
  46. CASE ISNULL(m.Flow)
  47. WHEN 0 THEN m.Flow
  48. ELSE '0'
  49. END AS Manual,
  50. CASE ISNULL(r.Flow)
  51. WHEN 0 THEN r.Flow
  52. ELSE '0'
  53. END AS Ratio,
  54. CASE ISNULL(i.Flow)
  55. WHEN 0 THEN i.Flow
  56. ELSE '0'
  57. END AS Inactivity
  58. FROM (
  59. SELECT
  60. DATE_FORMAT(JoinDate, '%Y-%m-%d') AS Date,
  61. COUNT(UserID) AS Flow
  62. FROM users_info
  63. WHERE JoinDate IS NOT NULL
  64. GROUP BY Date
  65. ) AS j
  66. LEFT JOIN (
  67. SELECT
  68. DATE_FORMAT(BanDate, '%Y-%m-%d') AS Date,
  69. COUNT(UserID) AS Flow
  70. FROM users_info
  71. WHERE BanDate IS NOT NULL
  72. AND BanReason = '1'
  73. GROUP BY Date
  74. ) AS m ON j.Date = m.Date
  75. LEFT JOIN (
  76. SELECT
  77. DATE_FORMAT(BanDate, '%Y-%m-%d') AS Date,
  78. COUNT(UserID) AS Flow
  79. FROM users_info
  80. WHERE BanDate IS NOT NULL
  81. AND BanReason = '2'
  82. GROUP BY Date
  83. ) AS r ON j.Date = r.Date
  84. LEFT JOIN (
  85. SELECT
  86. DATE_FORMAT(BanDate, '%Y-%m-%d') AS Date,
  87. COUNT(UserID) AS Flow
  88. FROM users_info
  89. WHERE BanDate IS NOT NULL
  90. AND BanReason = '3'
  91. GROUP BY Date
  92. ) AS i ON j.Date = i.Date
  93. ORDER BY j.Date DESC
  94. LIMIT $Limit");
  95. $DB->query('SELECT FOUND_ROWS()');
  96. list($Results) = $DB->next_record();
  97. View::show_header('User Flow', 'chart');
  98. $DB->set_query_id($RS);
  99. ?>
  100. <div class="linkbox">
  101. <?php
  102. $Pages = Format::get_pages($Page, $Results, DAYS_PER_PAGE, 11);
  103. echo $Pages;
  104. ?>
  105. </div>
  106. <div class="box">
  107. <table width="100%">
  108. <tr class="colhead">
  109. <td>Date</td>
  110. <td>+ Joined</td>
  111. <td>− Manual</td>
  112. <td>− Ratio</td>
  113. <td>− Inactivity</td>
  114. <td>− Total</td>
  115. <td>Net Growth</td>
  116. </tr>
  117. <?php
  118. while (list($Date, $Month, $Joined, $Manual, $Ratio, $Inactivity) = $DB->next_record()) {
  119. $TotalOut = $Ratio + $Inactivity + $Manual;
  120. $TotalGrowth = $Joined - $TotalOut; ?>
  121. <tr class="row">
  122. <td>
  123. <?=$Date?>
  124. </td>
  125. <td>
  126. <?=number_format($Joined)?>
  127. </td>
  128. <td>
  129. <?=number_format($Manual)?>
  130. </td>
  131. <td>
  132. <?=number_format((float)$Ratio)?>
  133. </td>
  134. <td>
  135. <?=number_format($Inactivity)?>
  136. </td>
  137. <td>
  138. <?=number_format($TotalOut)?>
  139. </td>
  140. <td>
  141. <?=number_format($TotalGrowth)?>
  142. </td>
  143. </tr>
  144. <?php
  145. } ?>
  146. </table>
  147. </div>
  148. <div class="linkbox">
  149. <?=$Pages?>
  150. </div>
  151. </div>
  152. <?php
  153. View::show_footer();