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

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