PageRenderTime 2719ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/html/pages/graph_mbreakdown.php

https://github.com/graywh/utstats
PHP | 216 lines | 187 code | 16 blank | 13 comment | 26 complexity | 477aa53daf76fb050beb40f69eb2044d MD5 | raw file
  1. <?php
  2. $max_height = 100;;
  3. // Hourly Breakdown
  4. $sql_ghours = "SELECT HOUR(time) AS res_hour, COUNT(*) AS res_count
  5. FROM uts_match WHERE $bgwhere 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 WHERE $bgwhere 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(time) AS res_month, COUNT(*) AS res_count
  29. FROM uts_match WHERE $bgwhere 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. // very dirty hack, to deal with the $bgwhere containing an OR
  39. // if it contains an OR, all literals should be prefixed with "m."
  40. if (substr_count($bgwhere, ' or ') == 0){
  41. $bgwhere = 'm.' . $bgwhere;
  42. } else {
  43. $bgwhere = substr($bgwhere, 1, -1);
  44. $part = explode(' or ', $bgwhere);
  45. $bgwhere = '';
  46. foreach($part as $i){
  47. $bgwhere .= 'm.' . $i . ' OR ';
  48. }
  49. $bgwhere = '(' . substr($bgwhere, 0, -4) . ')';
  50. }
  51. // Country Breakdown
  52. $sql_gcountries = "SELECT country AS res_country, COUNT(*) AS res_count FROM
  53. (SELECT p.country AS country FROM uts_player AS p, uts_match AS m
  54. WHERE m.id = p.matchid AND $bgwhere GROUP BY p.pid) AS res_table
  55. GROUP BY res_country ORDER BY res_count DESC";
  56. $q_gcountries = mysql_query($sql_gcountries) or die(mysql_error());
  57. $country_max = 0;
  58. $country_sum = 0;
  59. $i = 0;
  60. while ($r_gcountries = mysql_fetch_array($q_gcountries)) {
  61. $gb_country[$i] = $r_gcountries['res_country'] . ";" . $r_gcountries['res_count'];
  62. if ($r_gcountries['res_count'] > $country_max) $country_max = $r_gcountries['res_count'];
  63. $country_sum += $r_gcountries['res_count'];
  64. $i++;
  65. }
  66. echo'<table border="0" cellpadding="0" cellspacing="0">
  67. <tbody>
  68. <tr>
  69. <td class="heading" align="center" colspan="47">Hourly, Daily and Monthly Activity '.$gtitle.'</td>
  70. </tr>
  71. <tr>
  72. <td class="dark" align="center" colspan="47" height="10"></td>
  73. </tr>
  74. <tr>
  75. <td class="dark" align="center" width="15"></td>';
  76. // Hourly
  77. for ($i = 0; $i <= 23; $i++) {
  78. if (!isset($gb_hour[$i])) $gb_hour[$i] = 0;
  79. $title = $gb_hour[$i] .' ('. get_dp($gb_hour[$i] / $hour_sum * 100) .' %)';
  80. 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>';
  81. }
  82. echo '<td class="dark" align="center" valign="bottom" width="15" width="10"></td>';
  83. // Daily
  84. for ($i = 0; $i <= 6; $i++) {
  85. if (!isset($gb_day[$i])) $gb_day[$i] = 0;
  86. $title = $gb_day[$i] .' ('. get_dp($gb_day[$i] / $day_sum * 100) .' %)';
  87. 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>';
  88. }
  89. echo '<td class="dark" align="center" valign="bottom" width="15" width="10"></td>';
  90. // Monthly
  91. for ($i = 1; $i <= 12; $i++) {
  92. if (!isset($gb_month[$i])) $gb_month[$i] = 0;
  93. $title = $gb_month[$i] .' ('. get_dp($gb_month[$i] / $month_sum * 100) .' %)';
  94. 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>';
  95. }
  96. echo '<td class="dark" align="center" valign="bottom" width="15" width="10"></td>';
  97. echo'</tr><tr>
  98. <td class="grey" align="center" width="15"></td>
  99. <td class="grey" align="center">0</td>
  100. <td class="grey" align="center">1</td>
  101. <td class="grey" align="center">2</td>
  102. <td class="grey" align="center">3</td>
  103. <td class="grey" align="center">4</td>
  104. <td class="grey" align="center">5</td>
  105. <td class="grey" align="center">6</td>
  106. <td class="grey" align="center">7</td>
  107. <td class="grey" align="center">8</td>
  108. <td class="grey" align="center">9</td>
  109. <td class="grey" align="center">10</td>
  110. <td class="grey" align="center">11</td>
  111. <td class="grey" align="center">12</td>
  112. <td class="grey" align="center">13</td>
  113. <td class="grey" align="center">14</td>
  114. <td class="grey" align="center">15</td>
  115. <td class="grey" align="center">16</td>
  116. <td class="grey" align="center">17</td>
  117. <td class="grey" align="center">18</td>
  118. <td class="grey" align="center">19</td>
  119. <td class="grey" align="center">20</td>
  120. <td class="grey" align="center">21</td>
  121. <td class="grey" align="center">22</td>
  122. <td class="grey" align="center">23</td>
  123. <td class="grey" align="center" width="10"></td>
  124. <td class="grey" align="center">M</td>
  125. <td class="grey" align="center">T</td>
  126. <td class="grey" align="center">W</td>
  127. <td class="grey" align="center">T</td>
  128. <td class="grey" align="center">F</td>
  129. <td class="grey" align="center">S</td>
  130. <td class="grey" align="center">S</td>
  131. <td class="grey" align="center" width="10"></td>
  132. <td class="grey" align="center">J</td>
  133. <td class="grey" align="center">F</td>
  134. <td class="grey" align="center">M</td>
  135. <td class="grey" align="center">A</td>
  136. <td class="grey" align="center">M</td>
  137. <td class="grey" align="center">J</td>
  138. <td class="grey" align="center">J</td>
  139. <td class="grey" align="center">A</td>
  140. <td class="grey" align="center">S</td>
  141. <td class="grey" align="center">O</td>
  142. <td class="grey" align="center">N</td>
  143. <td class="grey" align="center">D</td>
  144. <td class="grey" align="center" width="15"></td>
  145. </tr>
  146. </tbody></table>
  147. <br/><br/>';
  148. global $a_countries;
  149. // The number of different countries we want to display
  150. $no_countries = 20;
  151. // Check if there are more countries then $no_countries; if so, we can have a "others" column
  152. if ( count($gb_country) < $no_countries ){
  153. $max_cntry = count($gb_country);
  154. $collspan = $max_cntry + 2;
  155. $others = false;
  156. } else {
  157. $max_cntry = $no_countries;
  158. $collspan = $max_cntry + 3;
  159. $others = true;
  160. }
  161. echo'<table border="0" cellpadding="0" cellspacing="0">
  162. <tbody>
  163. <tr>
  164. <td class="heading" align="center" colspan="' . $collspan . '">&nbsp;&nbsp;Origin of Players&nbsp;&nbsp;</td>
  165. </tr>
  166. <tr>
  167. <td class="dark" align="center" colspan="' . $collspan . '" height="10"></td>
  168. </tr>
  169. <tr>
  170. <td class="dark" align="center" width="15"></td>';
  171. // Countries
  172. $x = 0;
  173. for ($i = 0; $i < $max_cntry; $i++) {
  174. if (!isset($gb_hour[$i])) $gb_hour[$i] = 0;
  175. $country = explode(";",$gb_country[$i]);
  176. $title = $a_countries[$country[0]] .': ' . $country[1] . ' ('. get_dp($country[1] / $country_sum * 100) .' %)';
  177. echo '<td class="dark" align="center" valign="bottom" width="20"><img border="0" src="images/bars/v_bar'. ($i % 16 + 1) .'.png" width="20" height="'.(int)($country[1] / $country_max * $max_height).'" alt="'. $title .'" title="'. $title .'"></td>';
  178. $x += $country[1];
  179. }
  180. if($others){
  181. $countries_left = $country_sum - $x;
  182. $title = 'Other Countries: ' . $countries_left . ' ('. get_dp($countries_left / $country_sum * 100) .' %)';
  183. echo '<td class="dark" align="center" valign="bottom" width="20"><img border="0" src="images/bars/v_bar'. ($max_cntry % 16 + 1) .'.png" width="20" height="'.(int)($countries_left / $country_max * $max_height).'" alt="'. $title .'" title="'. $title .'"></td>';
  184. };
  185. echo '<td class="dark" align="center" valign="bottom" width="18" width="10"></td>';
  186. echo'</tr><tr>
  187. <td class="grey" align="center" width="18"></td>';
  188. for ($i = 0; $i < $max_cntry; $i++) {
  189. $country = explode(";",$gb_country[$i]);
  190. $country = strtoupper($country[0]);
  191. echo '<td class="grey" align="center">' . $country . '</td>';
  192. }
  193. if($others){
  194. echo '<td class="grey" align="center">--</td>';
  195. }
  196. echo'<td class="grey" align="center" width="15"></td>
  197. </tr>
  198. </tbody></table>
  199. <br>';
  200. ?>