Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. <?php
  2. namespace AppBundle\DataFixtures\ORM\OwloScenario1;
  3.  
  4. use AppBundle\DataFixtures\AbstractOwloFixture;
  5. use AppBundle\Entity\RouteMatrix;
  6. use DateTime;
  7. use Doctrine\Common\DataFixtures\FixtureInterface;
  8. use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
  9. use Doctrine\Common\Persistence\ObjectManager;
  10. use Kugaudo\GraphHopperBundle\API\Routing\Request\RoutingRequest;
  11. use Kugaudo\GraphHopperBundle\API\Routing\Response\RoutingResponse;
  12. use Kugaudo\GraphHopperBundle\API\Routing\RoutingAPI;
  13. use Symfony\Component\DependencyInjection\ContainerAwareInterface;
  14. use Symfony\Component\DependencyInjection\ContainerInterface;
  15.  
  16. class LoadRouteMatrixes extends AbstractOwloFixture implements FixtureInterface, OrderedFixtureInterface, ContainerAwareInterface
  17. {
  18. public function getOrder() {
  19. return 4;
  20. }
  21.  
  22. /**
  23. * @var ContainerInterface
  24. */
  25. private $container;
  26.  
  27. public function setContainer(ContainerInterface $container = null)
  28. {
  29. $this->container = $container;
  30. }
  31.  
  32. public function load(ObjectManager $manager)
  33. {
  34.  
  35. /** @var RoutingAPI $routingAPI */
  36. $routingAPI = $this->container->get('kugaudo.graphhopper.routingapi');
  37.  
  38. $request = new RoutingRequest();
  39. $request
  40. ->addDestination('56.868141', '24.278851')
  41. ->addDestination('56.991073', '24.122267')
  42. ->setStartTime(\DateTime::createFromFormat('Y-m-d H:i:s', '2017-01-18 20:00:00'));
  43.  
  44. $response = $routingAPI->fetchTrackingPoints($request);
  45.  
  46. // do stuff with tracking points...
  47. foreach ($response->getTrackingPoints() as $tp) {
  48. echo $tp->getLatitude() . ', ' . $tp->getLongitude() . ': ' . $tp->getTime()->format('Y-m-d H:i:s') . "\n";
  49. }
  50.  
  51. $gpx = $response->getTrackingPoints();
  52.  
  53.  
  54.  
  55. $matrixPoints = 288;
  56.  
  57. $lastChecked = 1;
  58.  
  59. $timenow = new DateTime();
  60.  
  61. var_dump($timenow->getTimestamp());
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68. for ($j = 0; $j < $matrixPoints; $j++) {
  69.  
  70. $time = var_dump($timenow->getTimestamp()) + 600 * $j;
  71.  
  72. if ($time < $gpx[0]->getTime() || $time > end($gpx)->getTime()) {
  73.  
  74. $lat = 0; $lng =0;
  75.  
  76. echo $lng.' '. $lat;
  77.  
  78. }
  79.  
  80.  
  81. while ($gpx[$lastChecked]->getTime() < $time) {
  82. $lastChecked++;
  83. }
  84.  
  85.  
  86. $tp0 = $gpx[$lastChecked - 1];
  87. $tp1 = $gpx[$lastChecked];
  88.  
  89.  
  90. $lat0 = $tp0->getLatitude();
  91. $lng0 = $tp0->getLongitude();
  92. $lat1 = $tp1->getLatitude();
  93. $lng1 = $tp1->getLongitude();
  94. $t0 = $tp0->getTime();
  95. $t1 = $tp1->getTime();
  96.  
  97. $length = $t1->diff($t0, true)->s;
  98. $mod = $time->diff($t0, true)->s;
  99.  
  100. echo $mod . ", " . $length . "\n";
  101. $part = $mod / $length;
  102.  
  103. $lat = floatval($lat0) + $part * (floatval($lat1) - floatval($lat0));
  104. $lng = floatval($lng0) + $part * (floatval($lng1) - floatval($lng0));
  105.  
  106. // echo '('.$lat.' '.$lng.') ';
  107.  
  108. }
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118. $manager->flush();
  119.  
  120.  
  121. }
  122.  
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement