Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace AppBundle\DataFixtures\ORM\OwloScenario1;
- use AppBundle\DataFixtures\AbstractOwloFixture;
- use AppBundle\Entity\RouteMatrix;
- use DateTime;
- use Doctrine\Common\DataFixtures\FixtureInterface;
- use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
- use Doctrine\Common\Persistence\ObjectManager;
- use Kugaudo\GraphHopperBundle\API\Routing\Request\RoutingRequest;
- use Kugaudo\GraphHopperBundle\API\Routing\Response\RoutingResponse;
- use Kugaudo\GraphHopperBundle\API\Routing\RoutingAPI;
- use Symfony\Component\DependencyInjection\ContainerAwareInterface;
- use Symfony\Component\DependencyInjection\ContainerInterface;
- class LoadRouteMatrixes extends AbstractOwloFixture implements FixtureInterface, OrderedFixtureInterface, ContainerAwareInterface
- {
- public function getOrder() {
- return 4;
- }
- /**
- * @var ContainerInterface
- */
- private $container;
- public function setContainer(ContainerInterface $container = null)
- {
- $this->container = $container;
- }
- public function load(ObjectManager $manager)
- {
- /** @var RoutingAPI $routingAPI */
- $routingAPI = $this->container->get('kugaudo.graphhopper.routingapi');
- $request = new RoutingRequest();
- $request
- ->addDestination('56.868141', '24.278851')
- ->addDestination('56.991073', '24.122267')
- ->setStartTime(\DateTime::createFromFormat('Y-m-d H:i:s', '2017-01-18 20:00:00'));
- $response = $routingAPI->fetchTrackingPoints($request);
- // do stuff with tracking points...
- foreach ($response->getTrackingPoints() as $tp) {
- echo $tp->getLatitude() . ', ' . $tp->getLongitude() . ': ' . $tp->getTime()->format('Y-m-d H:i:s') . "\n";
- }
- $gpx = $response->getTrackingPoints();
- $matrixPoints = 288;
- $lastChecked = 1;
- $timenow = new DateTime();
- var_dump($timenow->getTimestamp());
- for ($j = 0; $j < $matrixPoints; $j++) {
- $time = var_dump($timenow->getTimestamp()) + 600 * $j;
- if ($time < $gpx[0]->getTime() || $time > end($gpx)->getTime()) {
- $lat = 0; $lng =0;
- echo $lng.' '. $lat;
- }
- while ($gpx[$lastChecked]->getTime() < $time) {
- $lastChecked++;
- }
- $tp0 = $gpx[$lastChecked - 1];
- $tp1 = $gpx[$lastChecked];
- $lat0 = $tp0->getLatitude();
- $lng0 = $tp0->getLongitude();
- $lat1 = $tp1->getLatitude();
- $lng1 = $tp1->getLongitude();
- $t0 = $tp0->getTime();
- $t1 = $tp1->getTime();
- $length = $t1->diff($t0, true)->s;
- $mod = $time->diff($t0, true)->s;
- echo $mod . ", " . $length . "\n";
- $part = $mod / $length;
- $lat = floatval($lat0) + $part * (floatval($lat1) - floatval($lat0));
- $lng = floatval($lng0) + $part * (floatval($lng1) - floatval($lng0));
- // echo '('.$lat.' '.$lng.') ';
- }
- $manager->flush();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement