Context-detection API for Android developed as a university project
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.

data.php 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?PHP
  2. require('common.php');
  3. if (isset($_GET['graph'])) {
  4. $sql = 'SELECT log_data FROM sensorlogger WHERE log_id = ' . ((int) $_GET['graph']);
  5. $res = mysql_query($sql);
  6. $row = mysql_fetch_assoc($res);
  7. $datax = array();
  8. $datay = array();
  9. $dataz = array();
  10. foreach (explode("\n", $row['log_data']) as $line) {
  11. if (preg_match('/([0-9]+):(?:.*?,.*?,.*?,){'.($_GET['ds']-1).'}([0-9\.\-]+),([0-9\.\-]+),([0-9\.\-]+)/', $line, $m)) {
  12. $datax[] = (double) $m[2];
  13. $datay[] = (double) $m[3];
  14. $dataz[] = (double) $m[4];
  15. }
  16. }
  17. $im = imagecreatetruecolor(count($datax) * 2, 330);
  18. $w = imagecolorallocate($im, 255, 255, 255);
  19. imagefill($im, 0, 0, $w);
  20. $r = imagecolorallocate($im, 255, 0, 0);
  21. $g = imagecolorallocate($im, 0, 255, 0);
  22. $b = imagecolorallocate($im, 0, 0, 255);
  23. $grey = imagecolorallocate($im, 200, 200, 200);
  24. $lgrey = imagecolorallocate($im, 230, 230, 230);
  25. $minx = min($datax); $maxx = max($datax); $rangex = max(0.01, $maxx - $minx);
  26. $miny = min($datay); $maxy = max($datay); $rangey = max(0.01, $maxy - $miny);
  27. $minz = min($dataz); $maxz = max($dataz); $rangez = max(0.01, $maxz - $minz);
  28. $lastx = $lasty = $lastz = -0;
  29. imagestring($im, 1, 2, 6, 'Min: ' . $minx . '; Max: ' . $maxx . '; Range: ' . $rangex, $grey);
  30. imagestring($im, 1, 2, 116, 'Min: ' . $miny . '; Max: ' . $maxy . '; Range: ' . $rangey, $grey);
  31. imagestring($im, 1, 2, 226, 'Min: ' . $minz . '; Max: ' . $maxz . '; Range: ' . $rangez, $grey);
  32. imageline($im, 0, 5, count($datax) * 2, 5, $grey);
  33. imageline($im, 0, 105, count($datax) * 2, 105, $grey);
  34. imageline($im, 0, 115, count($datax) * 2, 115, $grey);
  35. imageline($im, 0, 215, count($datax) * 2, 215, $grey);
  36. imageline($im, 0, 225, count($datax) * 2, 225, $grey);
  37. imageline($im, 0, 325, count($datax) * 2, 325, $grey);
  38. for ($i = 0; $i < count($datax); $i++) {
  39. $x = ($datax[$i] - $minx) * 100 / $rangex + 5;
  40. $y = ($datay[$i] - $miny) * 100 / $rangey + 115;
  41. $z = ($dataz[$i] - $minz) * 100 / $rangez + 225;
  42. if ($i > 0) {
  43. imageline($im, 2 * $i - 2, $lastx, $i * 2, $x, $r);
  44. imageline($im, 2 * $i - 2, $lasty, $i * 2, $y, $g);
  45. imageline($im, 2 * $i - 2, $lastz, $i * 2, $z, $b);
  46. }
  47. $lastx = $x; $lasty = $y; $lastz = $z;
  48. }
  49. header('Content-type: image/png');
  50. imagepng($im);
  51. return;
  52. }
  53. $sql = 'SELECT log_id, log_imei, log_version, log_time, log_activity, log_data FROM sensorlogger WHERE log_statuscode = 1';
  54. $res = mysql_query($sql);
  55. echo '<table border="1">';
  56. $first = true;
  57. while ($row = mysql_fetch_assoc($res)) {
  58. if ($first) {
  59. echo '<tr>';
  60. foreach ($row as $k => $v) { echo '<th>', $k, '</th>'; }
  61. echo '</tr>';
  62. $first = false;
  63. }
  64. echo '<tr>';
  65. foreach ($row as $k => $v) { echo '<td>', $k == 'log_data' ? count(explode("\n", $v)) . ' line(s)' : nl2br(htmlentities($v)), '</td>'; }
  66. echo '<td>';
  67. echo '<img src="data.php?graph=', $row['log_id'], '&amp;ds=1" height="330">';
  68. echo '<br><img src="data.php?graph=', $row['log_id'], '&amp;ds=2" height="330">';
  69. echo '</td>';
  70. echo '</tr>';
  71. }
  72. echo '</table>';
  73. ?>