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.

users.php 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <?php
  2. if (!$ClassDistribution = $Cache->get_value('class_distribution')) {
  3. $DB->query("
  4. SELECT p.Name, COUNT(m.ID) AS Users
  5. FROM users_main AS m
  6. JOIN permissions AS p ON m.PermissionID = p.ID
  7. WHERE m.Enabled = '1'
  8. GROUP BY p.Name
  9. ORDER BY Users DESC");
  10. $ClassDistribution = $DB->to_array();
  11. $Cache->cache_value('class_distribution', $ClassDistribution, 3600 * 24 * 14);
  12. }
  13. if (!$PlatformDistribution = $Cache->get_value('platform_distribution')) {
  14. $DB->query("
  15. SELECT OperatingSystem, COUNT(DISTINCT UserID) AS Users
  16. FROM users_sessions
  17. GROUP BY OperatingSystem
  18. ORDER BY Users DESC");
  19. $PlatformDistribution = $DB->to_array();
  20. $Cache->cache_value('platform_distribution', $PlatformDistribution, 3600 * 24 * 14);
  21. }
  22. if (!$BrowserDistribution = $Cache->get_value('browser_distribution')) {
  23. $DB->query("
  24. SELECT Browser, COUNT(DISTINCT UserID) AS Users
  25. FROM users_sessions
  26. GROUP BY Browser
  27. ORDER BY Users DESC");
  28. $BrowserDistribution = $DB->to_array();
  29. $Cache->cache_value('browser_distribution', $BrowserDistribution, 3600 * 24 * 14);
  30. }
  31. // Timeline generation
  32. if (!list($Labels, $InFlow, $OutFlow) = $Cache->get_value('users_timeline')) {
  33. $DB->query("
  34. SELECT DATE_FORMAT(JoinDate,\"%b %Y\") AS Month, COUNT(UserID)
  35. FROM users_info
  36. GROUP BY Month
  37. ORDER BY JoinDate DESC
  38. LIMIT 1, 11");
  39. $TimelineIn = array_reverse($DB->to_array());
  40. $DB->query("
  41. SELECT DATE_FORMAT(BanDate,\"%b %Y\") AS Month, COUNT(UserID)
  42. FROM users_info
  43. WHERE BanDate > 0
  44. GROUP BY Month
  45. ORDER BY BanDate DESC
  46. LIMIT 1, 11");
  47. $TimelineOut = array_reverse($DB->to_array());
  48. $Labels = [];
  49. foreach ($TimelineIn as $Month) {
  50. list($Labels[], $InFlow[]) = $Month;
  51. }
  52. foreach ($TimelineOut as $Month) {
  53. list(, $OutFlow[]) = $Month;
  54. }
  55. $Cache->cache_value('users_timeline', array($Labels, $InFlow, $OutFlow), mktime(0, 0, 0, date('n') + 1, 2)); //Tested: fine for Dec -> Jan
  56. }
  57. // End timeline generation
  58. View::show_header('User Statistics', $JSIncludes = 'vendor/chart.min');
  59. ?>
  60. <h2 class="header">
  61. User Stats
  62. </h2>
  63. <h3>
  64. Flow
  65. </h3>
  66. <div class="box pad center">
  67. <canvas class="chart" id="chart_user_timeline"></canvas>
  68. <script>
  69. var ctx = document.getElementById('chart_user_timeline').getContext('2d');
  70. var myChart = new Chart(ctx, {
  71. type: 'line',
  72. data: {
  73. labels: <?= ' ["'.implode('","', $Labels).'"]'; ?> ,
  74. datasets: [{
  75. label: 'New Registrations',
  76. backgroundColor: 'rgba(179, 229, 252, 0.8)', // #B3E5FC
  77. borderColor: 'rgba(1, 87, 155, 0.8)', // #01579B
  78. data:
  79. <?= "[".implode(",", $InFlow)."]"; ?>
  80. },
  81. {
  82. label: 'Disabled Users',
  83. backgroundColor: 'rgba(255, 224, 178, 0.8)', // #FFE0B2
  84. borderColor: 'rgba(230, 81, 0, 0.8)', // #E65100
  85. data:
  86. <?= "[".implode(",", $OutFlow)."]"; ?>
  87. }
  88. ]
  89. }
  90. });
  91. </script>
  92. </div>
  93. <h3>
  94. Classes
  95. </h3>
  96. <div class="box pad center">
  97. <canvas class="chart" id="chart_user_classes"></canvas>
  98. <script>
  99. var ctx = document.getElementById('chart_user_classes').getContext('2d');
  100. var myChart = new Chart(ctx, {
  101. type: 'pie',
  102. data: {
  103. labels: <?= ' ["'.implode('","', array_column($ClassDistribution, 'Name')).'"]'; ?> ,
  104. datasets: [{
  105. data:
  106. <?= "[".implode(",", array_column($ClassDistribution, 'Users'))."]"; ?>
  107. ,
  108. backgroundColor: [
  109. 'rgba(241, 248, 233, 0.8)', // #F1F8E9
  110. 'rgba(220, 237, 200, 0.8)', // #DCEDC8
  111. 'rgba(197, 225, 165, 0.8)', // #C5E1A5
  112. 'rgba(174, 213, 129, 0.8)', // #AED581
  113. 'rgba(156, 204, 101, 0.8)', // #9CCC65
  114. 'rgba(139, 195, 74, 0.8)', // #8BC34A
  115. 'rgba(124, 179, 66, 0.8)', // #7CB342
  116. 'rgba(104, 159, 56, 0.8)', // #689F38
  117. 'rgba(85, 139, 47, 0.8)', // #558B2F
  118. 'rgba(51, 105, 30, 0.8)', // #33691E
  119. ]
  120. }]
  121. }
  122. });
  123. </script>
  124. </div>
  125. <h3>
  126. Platforms
  127. </h3>
  128. <div class="box pad center">
  129. <?php
  130. $AllPlatforms = array_column($PlatformDistribution, 'OperatingSystem');
  131. $SlicedPlatforms = (count($AllPlatforms) > 14) ? array_slice($AllPlatforms, 0, 13)+[13=>'Other'] : $AllPlatforms;
  132. $AllUsers = array_column($PlatformDistribution, 'Users');
  133. $SlicedUsers = (count($AllUsers) > 14) ? array_slice($AllUsers, 0, 13)+[13=>array_sum(array_slice($AllUsers, 13))] : $AllUsers;
  134. ?>
  135. <canvas class="chart" id="chart_user_platforms"></canvas>
  136. <script>
  137. var ctx = document.getElementById('chart_user_platforms').getContext('2d');
  138. var myChart = new Chart(ctx, {
  139. type: 'pie',
  140. data: {
  141. labels: [
  142. "<?=implode('","', $AllPlatforms)?>"
  143. ],
  144. datasets: [{
  145. data: [ <?=implode(",", $AllUsers)?> ],
  146. backgroundColor: [
  147. 'rgba(255, 205, 210, 0.8)', // #FFCDD2
  148. 'rgba(225, 190, 231, 0.8)', // #E1BEE7
  149. 'rgba(197, 202, 233, 0.8)', // #C5CAE9
  150. 'rgba(179, 229, 252, 0.8)', // #B3E5FC
  151. 'rgba(178, 223, 219, 0.8)', // #B2DFDB
  152. 'rgba(220, 237, 200, 0.8)', // #DCEDC8
  153. 'rgba(255, 249, 196, 0.8)', // #FFF9C4
  154. 'rgba(255, 224, 178, 0.8)', // #FFE0B2
  155. 'rgba(215, 204, 200, 0.8)', // #D7CCC8
  156. 'rgba(207, 216, 220, 0.8)', // #CFD8DC
  157. 'rgba(158, 158, 158, 0.8)', // #9E9E9E
  158. ]
  159. }]
  160. }
  161. });
  162. </script>
  163. </div>
  164. <h3>
  165. Browsers
  166. </h3>
  167. <div class="box pad center">
  168. <?php
  169. $AllBrowsers = array_column($BrowserDistribution, 'Browser');
  170. $SlicedBrowsers = (count($AllBrowsers) > 7) ? array_slice($AllBrowsers, 0, 6)+[6=>'Other'] : $AllBrowsers;
  171. $AllUsers = array_column($BrowserDistribution, 'Users');
  172. $SlicedUsers = (count($AllUsers) > 7) ? array_slice($AllUsers, 0, 6)+[6=>array_sum(array_slice($AllUsers, 6))] : $AllUsers;
  173. ?>
  174. <canvas class="chart" id="chart_user_browsers"></canvas>
  175. <script>
  176. var ctx = document.getElementById('chart_user_browsers').getContext('2d');
  177. var myChart = new Chart(ctx, {
  178. type: 'pie',
  179. data: {
  180. labels: [
  181. "<?=implode('","', $AllBrowsers)?>"
  182. ],
  183. datasets: [{
  184. data: [ <?=implode(",", $AllUsers)?> ],
  185. backgroundColor: [
  186. 'rgba(158, 158, 158, 0.8)', // #9E9E9E
  187. 'rgba(207, 216, 220, 0.8)', // #CFD8DC
  188. 'rgba(215, 204, 200, 0.8)', // #D7CCC8
  189. 'rgba(255, 224, 178, 0.8)', // #FFE0B2
  190. 'rgba(255, 249, 196, 0.8)', // #FFF9C4
  191. 'rgba(220, 237, 200, 0.8)', // #DCEDC8
  192. 'rgba(178, 223, 219, 0.8)', // #B2DFDB
  193. 'rgba(179, 229, 252, 0.8)', // #B3E5FC
  194. 'rgba(197, 202, 233, 0.8)', // #C5CAE9
  195. 'rgba(225, 190, 231, 0.8)', // #E1BEE7
  196. 'rgba(255, 205, 210, 0.8)', // #FFCDD2
  197. ]
  198. }]
  199. }
  200. });
  201. </script>
  202. </div>
  203. <?php View::show_footer();