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.3KB

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