PageRenderTime 52ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/html/pages/graph_pbreakdown.php

https://github.com/graywh/utstats
PHP | 130 lines | 113 code | 10 blank | 7 comment | 14 complexity | 034c7f62962c19743d3c9c741123c4ee MD5 | raw file
  1. <?php
  2. $max_height = 80;
  3. // Hourly Breakdown
  4. $sql_ghours = "SELECT HOUR(m.time) AS res_hour, COUNT(p.id) AS res_count
  5. FROM uts_match m, uts_player p WHERE $bgwhere AND m.id = p.matchid GROUP by res_hour";
  6. $q_ghours = mysql_query($sql_ghours) or die(mysql_error());
  7. $hour_max = 0;
  8. $hour_sum = 0;
  9. while ($r_ghours = mysql_fetch_array($q_ghours)) {
  10. $gb_hour[$r_ghours['res_hour']] = $r_ghours['res_count'];
  11. if ($r_ghours['res_count'] > $hour_max) $hour_max = $r_ghours['res_count'];
  12. $hour_sum += $r_ghours['res_count'];
  13. }
  14. if ($hour_max == 0) return;
  15. // Daily Breakdown
  16. // We use WEEKDAY rather then DAYOFWEEK because now the week starts with Monday instead of Sunday
  17. $sql_gdays = "SELECT WEEKDAY(time) AS res_day, COUNT(*) AS res_count
  18. FROM uts_match m, uts_player p WHERE $bgwhere AND m.id = p.matchid GROUP by res_day";
  19. $q_gdays = mysql_query($sql_gdays) or die(mysql_error());
  20. $day_max = 0;
  21. $day_sum = 0;
  22. while ($r_gdays = mysql_fetch_array($q_gdays)) {
  23. $gb_day[$r_gdays['res_day']] = $r_gdays['res_count'];
  24. if ($r_gdays['res_count'] > $day_max) $day_max = $r_gdays['res_count'];
  25. $day_sum += $r_gdays['res_count'];
  26. }
  27. // Monthly Breakdown
  28. $sql_gmonths = "SELECT MONTH(m.time) AS res_month, COUNT(p.id) AS res_count
  29. FROM uts_match m, uts_player p WHERE $bgwhere AND m.id = p.matchid GROUP by res_month";
  30. $q_gmonths = mysql_query($sql_gmonths) or die(mysql_error());
  31. $month_max = 0;
  32. $month_sum = 0;
  33. while ($r_gmonths = mysql_fetch_array($q_gmonths)) {
  34. $gb_month[$r_gmonths['res_month']] = $r_gmonths['res_count'];
  35. if ($r_gmonths['res_count'] > $month_max) $month_max = $r_gmonths['res_count'];
  36. $month_sum += $r_gmonths['res_count'];
  37. }
  38. echo'<table border="0" cellpadding="0" cellspacing="0">
  39. <tbody>
  40. <tr>
  41. <td class="heading" align="center" colspan="47">Hourly, Daily and Monthly Activity '.$gtitle.'</td>
  42. </tr>
  43. <tr>
  44. <td class="dark" align="center" colspan="47" height="10"></td>
  45. </tr>
  46. <tr>
  47. <td class="dark" align="center" width="15"></td>';
  48. // Hourly
  49. for ($i = 0; $i <= 23; $i++) {
  50. if (!isset($gb_hour[$i])) $gb_hour[$i] = 0;
  51. $title = $gb_hour[$i] .' ('. get_dp($gb_hour[$i] / $hour_sum * 100) .' %)';
  52. echo '<td class="dark" align="center" valign="bottom" width="15"><img border="0" src="images/bars/v_bar'. ($i % 16 + 1) .'.png" width="18" height="'.(int)($gb_hour[$i] / $hour_max * $max_height).'" alt="'. $title .'" title="'. $title .'"></td>';
  53. }
  54. echo '<td class="dark" align="center" valign="bottom" width="15" width="10"></td>';
  55. // Daily
  56. for ($i = 0; $i <= 6; $i++) {
  57. if (!isset($gb_day[$i])) $gb_day[$i] = 0;
  58. $title = $gb_day[$i] .' ('. get_dp($gb_day[$i] / $day_sum * 100) .' %)';
  59. echo '<td class="dark" align="center" valign="bottom" width="15"><img border="0" src="images/bars/v_bar'. ($i % 16 + 1) .'.png" width="18" height="'.(int)($gb_day[$i] / $day_max * $max_height).'" alt="'. $title .'" title="'. $title .'"></td>';
  60. }
  61. echo '<td class="dark" align="center" valign="bottom" width="15" width="10"></td>';
  62. // Monthly
  63. for ($i = 1; $i <= 12; $i++) {
  64. if (!isset($gb_month[$i])) $gb_month[$i] = 0;
  65. $title = $gb_month[$i] .' ('. get_dp($gb_month[$i] / $month_sum * 100) .' %)';
  66. echo '<td class="dark" align="center" valign="bottom" width="15"><img border="0" src="images/bars/v_bar'. (($i + 8) % 16 + 1) .'.png" width="18" height="'.(int)($gb_month[$i] / $month_max * $max_height).'" alt="'. $title .'" title="'. $title .'"></td>';
  67. }
  68. echo '<td class="dark" align="center" valign="bottom" width="15" width="10"></td>';
  69. echo'</tr><tr>
  70. <td class="grey" align="center" width="15"></td>
  71. <td class="grey" align="center">0</td>
  72. <td class="grey" align="center">1</td>
  73. <td class="grey" align="center">2</td>
  74. <td class="grey" align="center">3</td>
  75. <td class="grey" align="center">4</td>
  76. <td class="grey" align="center">5</td>
  77. <td class="grey" align="center">6</td>
  78. <td class="grey" align="center">7</td>
  79. <td class="grey" align="center">8</td>
  80. <td class="grey" align="center">9</td>
  81. <td class="grey" align="center">10</td>
  82. <td class="grey" align="center">11</td>
  83. <td class="grey" align="center">12</td>
  84. <td class="grey" align="center">13</td>
  85. <td class="grey" align="center">14</td>
  86. <td class="grey" align="center">15</td>
  87. <td class="grey" align="center">16</td>
  88. <td class="grey" align="center">17</td>
  89. <td class="grey" align="center">18</td>
  90. <td class="grey" align="center">19</td>
  91. <td class="grey" align="center">20</td>
  92. <td class="grey" align="center">21</td>
  93. <td class="grey" align="center">22</td>
  94. <td class="grey" align="center">23</td>
  95. <td class="grey" align="center" width="10"></td>
  96. <td class="grey" align="center">M</td>
  97. <td class="grey" align="center">T</td>
  98. <td class="grey" align="center">W</td>
  99. <td class="grey" align="center">T</td>
  100. <td class="grey" align="center">F</td>
  101. <td class="grey" align="center">S</td>
  102. <td class="grey" align="center">S</td>
  103. <td class="grey" align="center" width="10"></td>
  104. <td class="grey" align="center">J</td>
  105. <td class="grey" align="center">F</td>
  106. <td class="grey" align="center">M</td>
  107. <td class="grey" align="center">A</td>
  108. <td class="grey" align="center">M</td>
  109. <td class="grey" align="center">J</td>
  110. <td class="grey" align="center">J</td>
  111. <td class="grey" align="center">A</td>
  112. <td class="grey" align="center">S</td>
  113. <td class="grey" align="center">O</td>
  114. <td class="grey" align="center">N</td>
  115. <td class="grey" align="center">D</td>
  116. <td class="grey" align="center" width="15"></td>
  117. </tr>
  118. </tbody></table>
  119. <br>';
  120. ?>