Context-detection API for Android developed as a university project
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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('Expires: ' . date(DateTime::RFC822, strtotime('+10 years')));
  54. header('Cache-control: public');
  55. header('Content-type: image/png');
  56. imagecolortransparent($im, $w);
  57. imagepng($im);
  58. return;
  59. }
  60. ?>