Repositorio del curso CCOM4030 el semestre B91 del proyecto Trolley

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. $file = file("db.txt");
  3. $sum_of_lat = 0;
  4. $sum_of_long = 0;
  5. $array_sum_of_time = array(0,0,0);
  6. $array_inTime = 0;
  7. $average = new stdClass();
  8. $average->latitude = 0;
  9. $average->longitude = 0;
  10. $average->inTime = 0;
  11. $encoded_average = '';
  12. $count_loc = count($file);
  13. for ($i = 0; $i < $count_loc; $i++)
  14. {
  15. $decoded_location = json_decode($file[$i]);
  16. $array_inTime = array_map('intval',explode(':',$decoded_location->inTime));
  17. $array_sum_of_time[0] = $array_sum_of_time[0] + $array_inTime[0];
  18. $array_sum_of_time[1] = $array_sum_of_time[1] + $array_inTime[1];
  19. $array_sum_of_time[2] = $array_sum_of_time[2] + $array_inTime[2];
  20. $sum_of_lat = $sum_of_lat + $decoded_location->latitude;
  21. $sum_of_long = $sum_of_long + $decoded_location->longitude;
  22. if ($i+1 == $count_loc)
  23. {
  24. $average->latitude = $sum_of_lat/$count_loc;
  25. $average->longitude = $sum_of_long/$count_loc;
  26. $average->inTime = strval(floor($array_sum_of_time[0]/$count_loc)) . ":" . strval(floor($array_sum_of_time[1]/$count_loc)) . ":" . strval(floor($array_sum_of_time[2]/$count_loc));
  27. $encoded_average = json_encode($average);
  28. }
  29. }
  30. //echo $average->latitude. "<br>". $average->longitude. "<br>". $average->inTime . "<br>". $encoded_average;
  31. header('Content-Type: application/json');
  32. echo $encoded_average;