PageRenderTime 47ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/temperature_graphs.php

https://gitlab.com/guilleJB/jayfishv30
PHP | 291 lines | 202 code | 80 blank | 9 comment | 58 complexity | b5ca0e4531068c4fbf125131e2325933 MD5 | raw file
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script src="js/Chart.js"></script>
  5. </head>
  6. <!-- MY CODE -->
  7. <?php
  8. include "include.php";
  9. ?>
  10. <head></head>
  11. <body>
  12. <?php
  13. $count = array(1,2,3,4,5,6,7,8,9,10,11,12);
  14. $collect = array("08","10","12","14","16","18","20","22","00","02","04","06");
  15. foreach ($count as $key => $value) {
  16. $timeslot = $collect[$key];
  17. $query="SELECT * FROM `therm` WHERE `timeset` BETWEEN '$timeslot:00:00' AND '$timeslot:15:00' AND dateset='$yesterday' LIMIT 1;";
  18. $result = mysqli_query($con,$query) or die (mysqli_error($con));
  19. while($rows = mysqli_fetch_array($result)) {
  20. if ($thermtype=="1") {
  21. $yesterday_therm = "yesterday_therm" . $value;
  22. $$yesterday_therm = $rows['therm'];
  23. $yesterday_thermii = "yesterday_thermii" . $value;
  24. $$yesterday_thermii = $rows['thermii'];
  25. }
  26. else
  27. {
  28. $yesterday_therm = "yesterday_therm" . $value;
  29. $$yesterday_therm = $rows['therm'] * 9 / 5 + 32;
  30. $yesterday_thermii = "yesterday_thermii" . $value;
  31. $$yesterday_thermii = $rows['thermii'] * 9 / 5 + 32;
  32. };
  33. }
  34. };
  35. $count = array(1,2,3,4,5,6,7,8,9,10,11,12);
  36. foreach ($count as $key => $value) {
  37. $yesterday_therm = "yesterday_therm" . $value;
  38. if (empty($$yesterday_therm)) {$$yesterday_therm=0;};
  39. if (is_null($$yesterday_therm)) {$$yesterday_therm=0;};
  40. $yesterday_thermii = "yesterday_thermii" . $value;
  41. if (empty($$yesterday_thermii)) {$$yesterday_thermii=0;};
  42. if (is_null($$yesterday_thermii)) {$$yesterday_thermii=0;};
  43. # code...
  44. };
  45. $labelcontrolyesterday = array();
  46. if ($yesterday_therm9 + $yesterday_thermii9 > 0) { array_push($labelcontrolyesterday, "'12am',");} else {;};
  47. if ($yesterday_therm10 + $yesterday_thermii10 > 0) {array_push($labelcontrolyesterday, "'2am',");} else {;};
  48. if ($yesterday_therm11 + $yesterday_thermii11 > 0) {array_push($labelcontrolyesterday, "'4am',");} else {;};
  49. if ($yesterday_therm12 + $yesterday_thermii12 > 0) {array_push($labelcontrolyesterday, "'6am',");} else {;};
  50. if ($yesterday_therm1 + $yesterday_thermii1 > 0) {array_push($labelcontrolyesterday, "'8am',");} else {;};
  51. if ($yesterday_therm2 + $yesterday_thermii2 > 0) {array_push($labelcontrolyesterday, "'10am',");} else {;};
  52. if ($yesterday_therm3 + $yesterday_thermii3 > 0) {array_push($labelcontrolyesterday, "'12pm',");} else {;};
  53. if ($yesterday_therm4 + $yesterday_thermii4 > 0) {array_push($labelcontrolyesterday, "'2pm',");} else {;};
  54. if ($yesterday_therm5 + $yesterday_thermii5 > 0) {array_push($labelcontrolyesterday, "'4pm',");} else {;};
  55. if ($yesterday_therm6 + $yesterday_thermii6 > 0) {array_push($labelcontrolyesterday, "'6pm',");} else {;};
  56. if ($yesterday_therm7 + $yesterday_thermii7 > 0) {array_push($labelcontrolyesterday, "'8pm',");} else {;};
  57. if ($yesterday_therm8 + $yesterday_thermii8 > 0) {array_push($labelcontrolyesterday, "'10pm',");} else {;};
  58. ?>
  59. <script>
  60. var lineChartData_yesterday = {
  61. labels : [<?php foreach ($labelcontrolyesterday as $key => $value) {
  62. print $value;
  63. # code...
  64. }; ?>],
  65. datasets : [
  66. {
  67. label: "Water",
  68. fillColor : "rgba(100,100,205,0.2)",
  69. strokeColor : "rgba(151,187,205,1)",
  70. pointColor : "rgba(151,187,205,1)",
  71. pointStrokeColor : "#fff",
  72. pointHighlightFill : "#fff",
  73. pointHighlightStroke : "rgba(151,187,205,1)",
  74. data : [<?php echo $yesterday_therm9; ?>,<?php echo $yesterday_therm10; ?>,<?php echo $yesterday_therm11; ?>,<?php echo $yesterday_therm12; ?>,<?php echo $yesterday_therm1; ?>,<?php echo $yesterday_therm2; ?>,<?php echo $yesterday_therm3; ?>,<?php echo $yesterday_therm4; ?>,<?php echo $yesterday_therm5; ?>,<?php echo $yesterday_therm6; ?>,<?php echo $yesterday_therm7; ?>,<?php echo $yesterday_therm8; ?>]
  75. },
  76. {
  77. label: "Air",
  78. fillColor : "rgba(200,200,200,0.4)",
  79. strokeColor : "rgba(220,220,220,1)",
  80. pointColor : "rgba(220,220,220,1)",
  81. pointStrokeColor : "#fff",
  82. pointHighlightFill : "#fff",
  83. pointHighlightStroke : "rgba(220,220,220,1)",
  84. data : [<?php echo $yesterday_thermii9; ?>,<?php echo $yesterday_thermii10; ?>,<?php echo $yesterday_thermii11; ?>,<?php echo $yesterday_thermii12; ?>,<?php echo $yesterday_thermii1; ?>,<?php echo $yesterday_thermii2; ?>,<?php echo $yesterday_thermii3; ?>,<?php echo $yesterday_thermii4; ?>,<?php echo $yesterday_thermii5; ?>,<?php echo $yesterday_thermii6; ?>,<?php echo $yesterday_thermii7; ?>,<?php echo $yesterday_thermii8; ?>]
  85. }
  86. ]
  87. }
  88. // window.onload = function(){
  89. // var ctxa = document.getElementById("canvas").getContext("2d");
  90. // window.myLine = new Chart(ctxa).Line(lineChartData_yesterday, {responsive: false});
  91. // }
  92. </script>
  93. <!-- ---------------------------------------------------- -->
  94. <?php
  95. $count = array(1,2,3,4,5,6,7,8,9,10,11,12);
  96. $collect = array("08","10","12","14","16","18","20","22","00","02","04","06");
  97. foreach ($count as $key => $value) {
  98. $timeslot = $collect[$key];
  99. $query="SELECT * FROM `therm` WHERE `timeset` BETWEEN '$timeslot:00:00' AND '$timeslot:15:00' AND dateset=current_date() LIMIT 1;";
  100. $result = mysqli_query($con,$query) or die (mysqli_error($con));
  101. while($rows = mysqli_fetch_array($result)) {
  102. if ($thermtype=="1") {
  103. $therm = "therm" . $value;
  104. $$therm = $rows['therm'];
  105. $thermii = "thermii" . $value;
  106. $$thermii = $rows['thermii'];
  107. }
  108. else
  109. {
  110. $therm = "therm" . $value;
  111. $$therm = $rows['therm']* 9 / 5 + 32;
  112. $thermii = "thermii" . $value;
  113. $$thermii = $rows['thermii']* 9 / 5 + 32;
  114. };
  115. };
  116. };
  117. $count = array(1,2,3,4,5,6,7,8,9,10,11,12);
  118. foreach ($count as $key => $value) {
  119. $therm = "therm" . $value;
  120. if (empty($$therm)) {$$therm=0;};
  121. if (is_null($$therm)) {$$therm=0;};
  122. $thermii = "thermii" . $value;
  123. if (empty($$thermii)) {$$thermii=0;};
  124. if (is_null($$thermii)) {$$thermii=0;};
  125. # code...
  126. };
  127. ?>
  128. <!-- #################### Month Data Pulle ####################### -->
  129. <?php
  130. $labelcontroltoday = array();
  131. if ($therm9 + $thermii9 > 0) { array_push($labelcontroltoday, "'12am',");} else {print '';};
  132. if ($therm10 + $thermii10 > 0) {array_push($labelcontroltoday, "'2am',");} else {print '';};
  133. if ($therm11 + $thermii11 > 0) {array_push($labelcontroltoday, "'4am',");} else {print '';};
  134. if ($therm12 + $thermii12 > 0) {array_push($labelcontroltoday, "'6am',");} else {print '';};
  135. if ($therm1 + $thermii1 > 0) {array_push($labelcontroltoday, "'8am',");} else {print '';};
  136. if ($therm2 + $thermii2 > 0) {array_push($labelcontroltoday, "'10am',");} else {print '';};
  137. if ($therm3 + $thermii3 > 0) {array_push($labelcontroltoday, "'12pm',");} else {print '';};
  138. if ($therm4 + $thermii4 > 0) {array_push($labelcontroltoday, "'2pm',");} else {print '';};
  139. if ($therm5 + $thermii5 > 0) {array_push($labelcontroltoday, "'4pm',");} else {print '';};
  140. if ($therm6 + $thermii6 > 0) {array_push($labelcontroltoday, "'6pm',");} else {print '';};
  141. if ($therm7 + $thermii7 > 0) {array_push($labelcontroltoday, "'8pm',");} else {print '';};
  142. if ($therm8 + $thermii8 > 0) {array_push($labelcontroltoday, "'10pm',");} else {print '';};
  143. ?>
  144. <script>
  145. // var randomScalingFactor = function(){ return Math.round(Math.random()*100)};
  146. var lineChartData_today = {
  147. labels : [<?php foreach ($labelcontroltoday as $key => $value) {
  148. print $value;
  149. # code...
  150. }; ?>],
  151. datasets : [
  152. {
  153. label: "Water",
  154. fillColor : "rgba(100,100,205,0.2)",
  155. strokeColor : "rgba(151,187,205,1)",
  156. pointColor : "rgba(151,187,205,1)",
  157. pointStrokeColor : "#fff",
  158. pointHighlightFill : "#fff",
  159. pointHighlightStroke : "rgba(151,187,205,1)",
  160. data : [<?php echo $therm9; ?>,<?php echo $therm10; ?>,<?php echo $therm11; ?>,<?php echo $therm12; ?>,<?php echo $therm1; ?>,<?php echo $therm2; ?>,<?php echo $therm3; ?>,<?php echo $therm4; ?>,<?php echo $therm5; ?>,<?php echo $therm6; ?>,<?php echo $therm7; ?>,<?php echo $therm8; ?>]
  161. },
  162. {
  163. label: "Air",
  164. fillColor : "rgba(200,200,200,0.4)",
  165. strokeColor : "rgba(220,220,220,1)",
  166. pointColor : "rgba(220,220,220,1)",
  167. pointStrokeColor : "#fff",
  168. pointHighlightFill : "#fff",
  169. pointHighlightStroke : "rgba(220,220,220,1)",
  170. data : [<?php echo $thermii9; ?>,<?php echo $thermii10; ?>,<?php echo $thermii11; ?>,<?php echo $thermii12; ?>,<?php echo $thermii1; ?>,<?php echo $thermii2; ?>,<?php echo $thermii3; ?>,<?php echo $thermii4; ?>,<?php echo $thermii5; ?>,<?php echo $thermii6; ?>,<?php echo $thermii7; ?>,<?php echo $thermii8; ?>]
  171. }
  172. ]
  173. }
  174. window.onload = function(){
  175. var ctxb = document.getElementById("canvas_today").getContext("2d");
  176. window.myLine = new Chart(ctxb).Line(lineChartData_today, {responsive: false});
  177. var ctxa = document.getElementById("canvas_yesterday").getContext("2d");
  178. window.myLine = new Chart(ctxa).Line(lineChartData_yesterday, {responsive: false});
  179. var ctxc = document.getElementById("canvas_month").getContext("2d");
  180. window.myLine = new Chart(ctxc).Line(lineChartData_month, {responsive: false});
  181. }
  182. </script>
  183. <div class="row">
  184. <div align="center" >
  185. <div class="col-md-2"></div>
  186. <div class="col-md-4" style="margin-bottom:10px;">
  187. <table class="<?php print $tablebackground_nolines;?>" border="0">
  188. <td style="padding-left:10px; padding-right:10px;"><div align="center" class="plaindark customfont">Yesterdays Graph</div></td><tr>
  189. <td>
  190. <div style="width:100%">
  191. <div><canvas id="canvas_yesterday" height="250" width="<?php print $tablewidth;?>"></canvas></div>
  192. </div>
  193. </td>
  194. </table>
  195. </div>
  196. <div class="col-md-4">
  197. <table class="<?php print $tablebackground_nolines;?>" border="0" width="<?php print $tablewidth;?>">
  198. <td style="padding-left:10px; padding-right:10px;"><div align="center" class="plaindark customfont">Todays Graph</div></td><tr>
  199. <td>
  200. <div style="width:100%;">
  201. <div>
  202. <canvas id="canvas_today" height="250" width="<?php print $tablewidth;?>"></canvas>
  203. </div>
  204. </div>
  205. </td>
  206. </table>
  207. </div>
  208. </div>
  209. </div>
  210. </body>
  211. </html>