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.

users.php 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <?
  2. if (!list($Countries, $Rank, $CountryUsers, $CountryMax, $CountryMin, $LogIncrements) = $Cache->get_value('geodistribution')) {
  3. include_once(SERVER_ROOT.'/classes/charts.class.php');
  4. $DB->query('
  5. SELECT Code, Users
  6. FROM users_geodistribution');
  7. $Data = $DB->to_array();
  8. $Count = $DB->record_count() - 1;
  9. $CountryMinThreshold = Min($Count, 30);
  10. $CountryMax = ceil(log(Max(1, $Data[0][1])) / log(2)) + 1;
  11. $CountryMin = floor(log(Max(1, $Data[$CountryMinThreshold][1])) / log(2));
  12. $CountryRegions = array('RS' => array('RS-KM')); // Count Kosovo as Serbia as it doesn't have a TLD
  13. foreach ($Data as $Key => $Item) {
  14. list($Country, $UserCount) = $Item;
  15. $Countries[] = $Country;
  16. $CountryUsers[] = number_format((((log($UserCount) / log(2)) - $CountryMin) / ($CountryMax - $CountryMin)) * 100, 2);
  17. $Rank[] = round((1 - ($Key / $Count)) * 100);
  18. if (isset($CountryRegions[$Country])) {
  19. foreach ($CountryRegions[$Country] as $Region) {
  20. $Countries[] = $Region;
  21. $Rank[] = end($Rank);
  22. }
  23. }
  24. }
  25. reset($Rank);
  26. for ($i = $CountryMin; $i <= $CountryMax; $i++) {
  27. $LogIncrements[] = Format::human_format(pow(2, $i));
  28. }
  29. $Cache->cache_value('geodistribution', array($Countries, $Rank, $CountryUsers, $CountryMax, $CountryMin, $LogIncrements), 0);
  30. }
  31. if (!$ClassDistribution = $Cache->get_value('class_distribution')) {
  32. $DB->query("
  33. SELECT p.Name, COUNT(m.ID) AS Users
  34. FROM users_main AS m
  35. JOIN permissions AS p ON m.PermissionID = p.ID
  36. WHERE m.Enabled = '1'
  37. GROUP BY p.Name
  38. ORDER BY Users DESC");
  39. $ClassDistribution = $DB->to_array();
  40. $Cache->cache_value('class_distribution', $ClassDistribution, 3600 * 24 * 14);
  41. }
  42. if (!$PlatformDistribution = $Cache->get_value('platform_distribution')) {
  43. $DB->query("
  44. SELECT OperatingSystem, COUNT(UserID) AS Users
  45. FROM users_sessions
  46. GROUP BY OperatingSystem
  47. ORDER BY Users DESC");
  48. $PlatformDistribution = $DB->to_array();
  49. $Cache->cache_value('platform_distribution', $PlatformDistribution, 3600 * 24 * 14);
  50. }
  51. if (!$BrowserDistribution = $Cache->get_value('browser_distribution')) {
  52. $DB->query("
  53. SELECT Browser, COUNT(UserID) AS Users
  54. FROM users_sessions
  55. GROUP BY Browser
  56. ORDER BY Users DESC");
  57. $BrowserDistribution = $DB->to_array();
  58. $Cache->cache_value('browser_distribution', $BrowserDistribution, 3600 * 24 * 14);
  59. }
  60. //Timeline generation
  61. if (!list($Labels, $InFlow, $OutFlow) = $Cache->get_value('users_timeline')) {
  62. $DB->query("
  63. SELECT DATE_FORMAT(JoinDate,\"%b %Y\") AS Month, COUNT(UserID)
  64. FROM users_info
  65. GROUP BY Month
  66. ORDER BY JoinDate DESC
  67. LIMIT 1, 11");
  68. $TimelineIn = array_reverse($DB->to_array());
  69. $DB->query("
  70. SELECT DATE_FORMAT(BanDate,\"%b %Y\") AS Month, COUNT(UserID)
  71. FROM users_info
  72. WHERE BanDate > 0
  73. GROUP BY Month
  74. ORDER BY BanDate DESC
  75. LIMIT 1, 11");
  76. $TimelineOut = array_reverse($DB->to_array());
  77. $Labels = array();
  78. foreach($TimelineIn as $Month) {
  79. list($Labels[], $InFlow[]) = $Month;
  80. }
  81. foreach($TimelineOut as $Month) {
  82. list(, $OutFlow[]) = $Month;
  83. }
  84. $Cache->cache_value('users_timeline', array($Labels, $InFlow, $OutFlow), mktime(0, 0, 0, date('n') + 1, 2)); //Tested: fine for Dec -> Jan
  85. }
  86. //End timeline generation
  87. View::show_header('Detailed User Statistics', 'chart');
  88. ?>
  89. <h3 id="User_Flow"><a href="#User_Flow">User Flow</a></h3>
  90. <div class="box pad center">
  91. <canvas class="chart" id="chart_user_timeline"></canvas>
  92. <script>
  93. new Chart($('#chart_user_timeline').raw().getContext('2d'), {
  94. type: 'line',
  95. data: {
  96. labels: <? print '["'.implode('","',$Labels).'"]'; ?>,
  97. datasets: [ {
  98. label: "New Registrations",
  99. backgroundColor: "rgba(0,0,255,0.2)",
  100. borderColor: "rgba(0,0,255,0.8)",
  101. data: <? print "[".implode(",",$InFlow)."]"; ?>
  102. }, {
  103. label: "Disabled Users",
  104. backgroundColor: "rgba(255,0,0,0.2)",
  105. borderColor: "rgba(255,0,0,0.8)",
  106. data: <? print "[".implode(",",$OutFlow)."]"; ?>
  107. }]
  108. }
  109. })
  110. </script>
  111. </div>
  112. <br />
  113. <h3 id="User_Classes"><a href="#User_Classes">User Classes</a></h3>
  114. <div class="box pad center">
  115. <canvas class="chart" id="chart_user_classes"></canvas>
  116. <script>
  117. new Chart($('#chart_user_classes').raw().getContext('2d'), {
  118. type: 'pie',
  119. data: {
  120. labels: <? print '["'.implode('","', array_column($ClassDistribution, 'Name')).'"]'; ?>,
  121. datasets: [ {
  122. data: <? print "[".implode(",", array_column($ClassDistribution, 'Users'))."]"; ?>,
  123. backgroundColor: ['#8a00b8','#a944cb','#be71d8','#e8ccf1', '#f3e3f9', '#fbf6fd', '#ffffff']
  124. }]
  125. }
  126. })
  127. </script>
  128. </div>
  129. <br />
  130. <h3 id="User_Platforms"><a href="#User_Platforms">User Platforms</a></h3>
  131. <div class="box pad center">
  132. <canvas class="chart" id="chart_user_platforms"></canvas>
  133. <?
  134. $AllPlatforms = array_column($PlatformDistribution, 'OperatingSystem');
  135. $SlicedPlatforms = (count($AllPlatforms) > 14) ? array_slice($AllPlatforms,0,13)+[13=>'Other'] : $AllPlatforms;
  136. $AllUsers = array_column($PlatformDistribution, 'Users');
  137. $SlicedUsers = (count($AllUsers) > 14) ? array_slice($AllUsers,0,13)+[13=>array_sum(array_slice($AllUsers,13))] : $AllUsers;
  138. $Colors = [];
  139. $Palette = ["blue"=>['#46B','#34A','#239','#128','#117','#006'],"red"=>['#B45','#A34','#923'],"green"=>['#3B3','#2A2','#191','#080'],"purple"=>['#B3B','#A2A','#919','#808','#707','#606','#505','#404']];
  140. $Counts = [0,0,0,0];
  141. for ($i = 0; $i < count($SlicedPlatforms); $i++) {
  142. if (preg_match('/Windows/i', $SlicedPlatforms[$i])) {
  143. $Colors[] = $Palette["blue"][$Counts[0]];
  144. $Counts[0]++;
  145. } else if (preg_match('/Mac|OS ?X/i', $SlicedPlatforms[$i])) {
  146. $Colors[] = $Palette["red"][$Counts[1]];
  147. $Counts[1]++;
  148. } else if (preg_match('/Linux|Ubuntu|Fedora/i', $SlicedPlatforms[$i])) {
  149. $Colors[] = $Palette["green"][$Counts[2]];
  150. $Counts[2]++;
  151. } else {
  152. $Colors[] = $Palette["purple"][$Counts[3]];
  153. $Counts[3]++;
  154. }
  155. }
  156. ?>
  157. <script>
  158. new Chart($('#chart_user_platforms').raw().getContext('2d'), {
  159. type: 'pie',
  160. data: {
  161. labels: ["<?=implode('","', $SlicedPlatforms)?>"],
  162. datasets: [ {
  163. data: [<?=implode(",", $SlicedUsers)?>],
  164. backgroundColor: ["<?=implode('","', $Colors)?>"]
  165. }]
  166. }
  167. })
  168. </script>
  169. </div>
  170. <br />
  171. <h3 id="User_Browsers"><a href="#User_Browsers">User Browsers</a></h3>
  172. <div class="box pad center">
  173. <canvas class="chart" id="chart_user_browsers"></canvas>
  174. <?
  175. $AllBrowsers = array_column($BrowserDistribution, 'Browser');
  176. $SlicedBrowsers = (count($AllBrowsers) > 7) ? array_slice($AllBrowsers,0,6)+[6=>'Other'] : $AllBrowsers;
  177. $AllUsers = array_column($BrowserDistribution, 'Users');
  178. $SlicedUsers = (count($AllUsers) > 7) ? array_slice($AllUsers,0,6)+[6=>array_sum(array_slice($AllUsers,6))] : $AllUsers;
  179. $Colors = [];
  180. $Palette = ["blue"=>['#46B','#34A'],"orange"=>['#F53','#E42'],"green"=>['#3B3','#2A2'],"purple"=>['#B3B','#A2A','#919','#808','#707','#606','#505','#404']];
  181. $Counts = [0,0,0,0];
  182. for ($i = 0; $i < count($SlicedBrowsers); $i++) {
  183. if (preg_match('/Chrome/i', $SlicedBrowsers[$i])) {
  184. $Colors[] = $Palette["green"][$Counts[0]];
  185. $Counts[0]++;
  186. } else if (preg_match('/Firefox/i', $SlicedBrowsers[$i])) {
  187. $Colors[] = $Palette["orange"][$Counts[1]];
  188. $Counts[1]++;
  189. } else if (preg_match('/Safari/i', $SlicedBrowsers[$i])) {
  190. $Colors[] = $Palette["blue"][$Counts[2]];
  191. $Counts[2]++;
  192. } else {
  193. $Colors[] = $Palette["purple"][$Counts[3]];
  194. $Counts[3]++;
  195. }
  196. }
  197. ?>
  198. <script>
  199. new Chart($('#chart_user_browsers').raw().getContext('2d'), {
  200. type: 'pie',
  201. data: {
  202. labels: ["<?=implode('","', $SlicedBrowsers)?>"],
  203. datasets: [ {
  204. data: [<?=implode(",", $SlicedUsers)?>],
  205. backgroundColor: ["<?=implode('","', $Colors)?>"],
  206. }]
  207. }
  208. })
  209. </script>
  210. </div>
  211. <br />
  212. <h3 id="Geo_Dist_Map"><a href="#Geo_Dist_Map">Geographical Distribution Map</a></h3>
  213. <div class="box center">
  214. <img src="<?=ImageTools::process('https://chart.googleapis.com/chart?cht=map:fixed=-55,-180,73,180&chs=440x220&chd=t:'.implode(',', $Rank).'&chco=FFFFFF,EDEDED,1F0066&chld='.implode('|', $Countries).'&chf=bg,s,CCD6FF')?>" alt="Geographical Distribution Map - Worldwide" />
  215. <img src="<?=ImageTools::process('https://chart.googleapis.com/chart?cht=map:fixed=37,-26,65,67&chs=440x220&chs=440x220&chd=t:'.implode(',', $Rank).'&chco=FFFFFF,EDEDED,1F0066&chld='.implode('|', $Countries).'&chf=bg,s,CCD6FF')?>" alt="Geographical Distribution Map - Europe" />
  216. <br />
  217. <img src="<?=ImageTools::process('https://chart.googleapis.com/chart?cht=map:fixed=-46,-132,24,21.5&chs=440x220&chd=t:'.implode(',', $Rank).'&chco=FFFFFF,EDEDED,1F0066&chld='.implode('|', $Countries).'&chf=bg,s,CCD6FF')?>" alt="Geographical Distribution Map - South America" />
  218. <img src="<?=ImageTools::process('https://chart.googleapis.com/chart?cht=map:fixed=-11,22,50,160&chs=440x220&chd=t:'.implode(',', $Rank).'&chco=FFFFFF,EDEDED,1F0066&chld='.implode('|', $Countries).'&chf=bg,s,CCD6FF')?>" alt="Geographical Distribution Map - Asia" />
  219. <br />
  220. <img src="<?=ImageTools::process('https://chart.googleapis.com/chart?cht=map:fixed=-36,-57,37,100&chs=440x220&chd=t:'.implode(',', $Rank).'&chco=FFFFFF,EDEDED,1F0066&chld='.implode('|', $Countries).'&chf=bg,s,CCD6FF')?>" alt="Geographical Distribution Map - Africa" />
  221. <img src="<?=ImageTools::process('https://chart.googleapis.com/chart?cht=map:fixed=14.8,15,45,86&chs=440x220&chd=t:'.implode(',', $Rank).'&chco=FFFFFF,EDEDED,1F0066&chld='.implode('|', $Countries).'&chf=bg,s,CCD6FF')?>" alt="Geographical Distribution Map - Middle East" />
  222. <br />
  223. <img src="<?=ImageTools::process('https://chart.googleapis.com/chart?chxt=y,x&chg=0,-1,1,1&chxs=0,h&cht=bvs&chco=76A4FB&chs=880x300&chd=t:'.implode(',', array_slice($CountryUsers, 0, 31)).'&chxl=1:|'.implode('|', array_slice($Countries, 0, 31)).'|0:|'.implode('|', $LogIncrements).'&chf=bg,s,FFFFFF00')?>" alt="Number of users by country" />
  224. </div>
  225. <?
  226. View::show_footer();