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 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?PHP
  2. require('common.php');
  3. if (isset($_GET['graph'])) {
  4. $sql = 'SELECT record_data FROM unprocessed WHERE record_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['record_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. $minx = min($datax); $maxx = max($datax); $rangex = max(1, $maxx - $minx);
  24. $miny = min($datay); $maxy = max($datay); $rangey = max(1, $maxy - $miny);
  25. $minz = min($dataz); $maxz = max($dataz); $rangez = max(1, $maxz - $minz);
  26. $lastx = $lasty = $lastz = -0;
  27. for ($i = 0; $i < count($datax); $i++) {
  28. $x = ($datax[$i] - $minx) * 200 / $rangex;
  29. $y = ($datay[$i] - $miny) * 200 / $rangey + 100;
  30. $z = ($dataz[$i] - $minz) * 200 / $rangez + 200;
  31. if ($i > 0) {
  32. imageline($im, 2 * $i - 2, $lastx, $i * 2, $x, $r);
  33. imageline($im, 2 * $i - 2, $lasty, $i * 2, $y, $g);
  34. imageline($im, 2 * $i - 2, $lastz, $i * 2, $z, $b);
  35. }
  36. $lastx = $x; $lasty = $y; $lastz = $z;
  37. }
  38. header('Content-type: image/png');
  39. imagepng($im);
  40. return;
  41. }
  42. $sql = 'SELECT * FROM unprocessed';
  43. $res = mysql_query($sql);
  44. echo '<table border="1">';
  45. $first = true;
  46. while ($row = mysql_fetch_assoc($res)) {
  47. if ($first) {
  48. echo '<tr>';
  49. foreach ($row as $k => $v) { echo '<th>', $k, '</th>'; }
  50. echo '</tr>';
  51. $first = false;
  52. }
  53. echo '<tr>';
  54. foreach ($row as $k => $v) { echo '<td>', $k == 'record_data' ? count(explode("\n", $v)) . ' line(s)' : nl2br(htmlentities($v)), '</td>'; }
  55. echo '<td>';
  56. echo '<img src="data.php?graph=', $row['record_id'], '&amp;ds=1"><br>';
  57. echo '<img src="data.php?graph=', $row['record_id'], '&amp;ds=2">';
  58. echo '</td>';
  59. echo '</tr>';
  60. }
  61. echo '</table>';
  62. ?>