games.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?php
  2. $page = 2;
  3. require("inc_header.php");
  4. // ======================================================
  5. // LATEST GAMES
  6. // ======================================================
  7. $table = "";
  8. $query = "SELECT `title`, `difficulty`, songinstance.id as siid, song.id as sid, (`enemies_hit` / (`enemies_missed` + `enemies_hit`)) * 100 as ratio, `buttons_pressed`, `joystick_moved`, `start_time`, `play_time`
  9. FROM `playdata`, `songinstance`, `song`
  10. WHERE playdata.songinstance = songinstance.id AND songinstance.song = song.id
  11. ORDER BY `start_time` DESC";
  12. $result_temp = mysqli_query($connection, $query);
  13. while($result = mysqli_fetch_assoc($result_temp))
  14. {
  15. $ratio = round($result['ratio']);
  16. $label = "danger";
  17. if($ratio >= 40)
  18. $label = "warning";
  19. if($ratio >= 80)
  20. $label = "success";
  21. $table .= "<tr>";
  22. $table .= "<td><a href='" . returnurl('song.php?id=' . $result['sid']) . "'>" . $result['title'] . "</a></td>";
  23. $table .= "<td><a href='" . returnurl('songinstance.php?id=' . $result['siid']) . "'>" . $result['difficulty'] . "</a></td>";
  24. $table .= "<td><span class='label label-" . $label . "'>" . $ratio . "<small>%</small></span></td>";
  25. $table .= "<td>" . $result['buttons_pressed'] . "</td>";
  26. $table .= "<td>" . $result['joystick_moved'] . "</td>";
  27. $table .= "<td>" . format($result['play_time'])['string'] . "</td>";
  28. $table .= "<td>" . $result['start_time'] . "</td>";
  29. $table .= "</tr>";
  30. }
  31. // ======================================================
  32. // DATA POINTS FOR MOST PLAYED GRAPH
  33. // DATA POINTS FOR AVERAGE PLAY TIME GRAPH
  34. // ======================================================
  35. $most_played_array = array();
  36. $average_play_time_array = array();
  37. $query = "SELECT DATE(`start_time`) AS date, COUNT(*) AS data, AVG(`play_time`) AS average
  38. FROM `playdata`
  39. GROUP BY DATE(`start_time`)
  40. ORDER BY `start_time` DESC
  41. LIMIT 0,14";
  42. $result_temp = mysqli_query($connection, $query);
  43. while($result = mysqli_fetch_assoc($result_temp))
  44. {
  45. $most_played_array[] = "{y: '" . $result['date'] . "', gp: " . $result['data'] . "}";
  46. $average_play_time_array[] = "{y: '" . $result['date'] . "', pt: " . format($result['average'])['tseconds'] . "}";
  47. }
  48. $most_played_array = array_reverse($most_played_array);
  49. $average_play_time_array = array_reverse($average_play_time_array);
  50. // ======================================================
  51. // PERCENTAGE OF DIFFICULTY
  52. // ======================================================
  53. $easy = 0;
  54. $medium = 0;
  55. $hard = 0;
  56. $other = 0;
  57. $query = "SELECT `difficulty`, COUNT(1) as num, COUNT(1) / (SELECT COUNT(1) FROM `playdata` ) * 100 as avg
  58. FROM `songinstance` AS si, `playdata` as pd
  59. WHERE si.id = pd.songinstance
  60. GROUP BY `difficulty`";
  61. $result_temp = mysqli_query($connection, $query);
  62. while($result = mysqli_fetch_assoc($result_temp))
  63. {
  64. if(strtolower($result['difficulty']) == "easy")
  65. {
  66. $easy = $easy + round($result['avg']);
  67. }
  68. else if(strtolower($result['difficulty']) == "medium")
  69. {
  70. $medium = $medium + round($result['avg']);
  71. }
  72. else if(strtolower($result['difficulty']) == "hard")
  73. {
  74. $hard = $hard + round($result['avg']);
  75. }
  76. else
  77. {
  78. $other = $other + $result['avg'];
  79. }
  80. }
  81. $other = round($other);
  82. ?>
  83. <!-- Content Wrapper. Contains page content -->
  84. <div class="content-wrapper">
  85. <!-- Content Header (Page header) -->
  86. <section class="content-header">
  87. <h1>
  88. Games
  89. <small>All game activity in one quick overview</small>
  90. </h1>
  91. <ol class="breadcrumb">
  92. <li class="active"><a href="#"><i class="fa fa-gamepad"></i> Games</a></li>
  93. </ol>
  94. </section>
  95. <section class="content">
  96. <div class="row">
  97. <div class="col-lg-4">
  98. <!-- games played graph -->
  99. <div class="box box-solid bg-teal">
  100. <div class="box-header">
  101. <i class="fa fa-gamepad"></i>
  102. <h3 class="box-title">Games played</h3>
  103. </div>
  104. <div class="box-body border-radius-none">
  105. <div class="chart" id="games-played-chart" style="height: 145px;"></div>
  106. </div><!-- /.box-body -->
  107. </div><!-- /.box -->
  108. </div>
  109. <div class="col-lg-4">
  110. <!-- Avarage Play Time -->
  111. <div class="box box-solid bg-orange">
  112. <div class="box-header">
  113. <i class="ion ion-clock"></i>
  114. <h3 class="box-title">Average Play Time</h3>
  115. </div>
  116. <div class="box-body border-radius-none">
  117. <div class="chart" id="average-play-time-chart" style="height: 145px;"></div>
  118. </div><!-- /.box-body -->
  119. </div><!-- /.box -->
  120. </div>
  121. <div class="col-lg-4">
  122. <!-- gamemodes -->
  123. <div class="box">
  124. <div class="box-header with-border">
  125. <i class="fa fa-gamepad"></i>
  126. <h3 class="box-title">Gamemodes</h3>
  127. </div><!-- /.box-header -->
  128. <div class="box-body">
  129. <div class="row">
  130. <div class="col-xs-3 text-center" style="border-right: 1px solid #f4f4f4">
  131. <input type="text" class="knob" data-readonly="true" value="<?php echo $easy; ?>" data-width="60" data-height="60" data-fgColor="#39CCCC"/>
  132. <div class="knob-label">Easy</div>
  133. </div><!-- ./col -->
  134. <div class="col-xs-3 text-center" style="border-right: 1px solid #f4f4f4">
  135. <input type="text" class="knob" data-readonly="true" value="<?php echo $medium; ?>" data-width="60" data-height="60" data-fgColor="#39CCCC"/>
  136. <div class="knob-label">Medium</div>
  137. </div><!-- ./col -->
  138. <div class="col-xs-3 text-center" style="border-right: 1px solid #f4f4f4">
  139. <input type="text" class="knob" data-readonly="true" value="<?php echo $hard; ?>" data-width="60" data-height="60" data-fgColor="#39CCCC"/>
  140. <div class="knob-label">Hard</div>
  141. </div><!-- ./col -->
  142. <div class="col-xs-3 text-center">
  143. <input type="text" class="knob" data-readonly="true" value="<?php echo $other; ?>" data-width="60" data-height="60" data-fgColor="#39CCCC"/>
  144. <div class="knob-label">Other</div>
  145. </div><!-- ./col -->
  146. </div><!-- /.row -->
  147. </div><!-- /.box-body -->
  148. </div><!-- /.box -->
  149. </div>
  150. </div>
  151. <div class="row">
  152. <div class="col-lg-12">
  153. <!-- TABLE: LATEST SONGS -->
  154. <div class="box">
  155. <div class="box-header with-border">
  156. <i class="fa fa-gamepad"></i>
  157. <h3 class="box-title">Latest Games</h3>
  158. </div><!-- /.box-header -->
  159. <div class="box-body">
  160. <table id="games-played-table" class="table table-bordered">
  161. <thead>
  162. <tr>
  163. <th>Song Name</th>
  164. <th>Difficulty</th>
  165. <th>Hit Ratio</th>
  166. <th>Buttons Pressed</th>
  167. <th>Joystick Moved</th>
  168. <th>Length</th>
  169. <th>Time</th>
  170. </tr>
  171. </thead>
  172. <tbody>
  173. <?php
  174. echo $table;
  175. ?>
  176. </tbody>
  177. </table>
  178. </div><!-- /.box-body -->
  179. </div><!-- /.box -->
  180. </div><!-- /.col -->
  181. </div><!-- /.row -->
  182. </section><!-- /.content -->
  183. </div><!-- /.content-wrapper -->
  184. <!-- Morris.js charts -->
  185. <script src="http://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
  186. <script src="plugins/morris/morris.min.js" type="text/javascript"></script>
  187. <!-- jQuery Knob Chart -->
  188. <script src="plugins/knob/jquery.knob.js" type="text/javascript"></script>
  189. <!-- DATA TABES SCRIPT -->
  190. <script src="plugins/datatables/jquery.dataTables.min.js" type="text/javascript"></script>
  191. <script src="plugins/datatables/dataTables.bootstrap.min.js" type="text/javascript"></script>
  192. <!-- Page specific javascript -->
  193. <script type="text/javascript">
  194. var most_played_data = [ <?php
  195. foreach ($most_played_array as $value)
  196. {
  197. echo $value . ",\n";
  198. }
  199. ?> ];
  200. var average_play_time_data = [ <?php
  201. foreach ($average_play_time_array as $value)
  202. {
  203. echo $value . ",\n";
  204. }
  205. ?> ];
  206. </script>
  207. <script src="dist/js/pages/games.js" type="text/javascript"></script>
  208. <?php
  209. require("inc_footer.php");
  210. ?>