public function testWorkingMonthDriverAssignment() { $monthDate = new \DateTime('2014-07-01'); $workingMonth = $this->init->workingMonthRepo->findWorkingMonthByDate($monthDate); if ($workingMonth === null) { $workingMonth = WorkingMonth::registerWorkingMonth($monthDate); $workingMonth->setMemo('Test'); $workingMonth->createWorkingDaysForThisMonth(); $this->init->workingMonthRepo->store($workingMonth); $workingDays = $workingMonth->getWorkingDays(); $shiftTypes = $this->init->shiftTypeRepo->findAllActive(); //create workingDays shifts, assign them drivingpools, get amount of needed drivers /** @var $workingDay WorkingDay */ foreach ($workingDays as $workingDay) { /** @var $shiftType ShiftType */ foreach ($shiftTypes as $shiftType) { $shift = Shift::registerShift($workingDay, $shiftType); $shift->setAmountOfDrivers(rand(12, 20)); $workingDay->assignShift($shift); for ($i = 1; $i <= $shift->getAmountOfDrivers(); $i++) { $drivingPool = DrivingPool::registerDrivingPool($shift); $shift->assignDrivingPool($drivingPool); $this->init->drivingPoolRepo->store($drivingPool); } $this->init->shiftRepo->store($shift); } $this->init->workingDayRepo->store($workingDay); } $this->init->em->flush(); } }
public function testDrivingOrderCRUD() { $addressFrom = $this->init->createTestAddressBaar(); $addressTo = $this->init->createTestAddressGoldau(); $passenger = Passenger::registerPassenger('m', 'Arthuro', 'Benatone', '+418182930', $addressFrom); $this->init->passengerRepo->store($passenger); $date = $this->init->dateTimeService->convertDateTimeStringToUTCDateTime('20.05.2014 00:00'); $time = $this->init->dateTimeService->convertDateTimeStringToUTCDateTime('20.05.2014 15:05'); $route = Route::registerRoute($addressFrom, $addressTo, 0, 0); $route->setDuration(15); $route->setDistance(6); $this->init->routeRepo->store($route); $drivingOrder = DrivingOrder::registerDrivingOrder($passenger, $date, $time, 2, 'möchte nicht hinten sitzen'); $drivingOrder->assignRoute($route); $passenger->assignDrivingOrder($drivingOrder); $drivingOrder->assignPassenger($passenger); $this->init->drivingOrderRepo->store($drivingOrder); $this->init->em->flush(); $this->assertNotNull($this->init->drivingOrderRepo->find($drivingOrder->getId())); //TimePeriod from start day of month to next start day of month $monthsAgo = 3; $monthDate = new \DateTime('today'); $monthDate->modify('+' . $monthsAgo . ' month'); $monthDate->format('first day of this month'); $workingMonth = WorkingMonth::registerWorkingMonth($monthDate); $workingMonth->createWorkingDaysForThisMonth(); foreach ($workingMonth->getWorkingDays() as $wd) { $this->init->workingDayRepo->store($wd); } $this->init->workingMonthRepo->store($workingMonth); $workingDays = $workingMonth->getWorkingDays(); /**@var $shiftTypes ShiftType[] */ $shiftTypes = $this->init->shiftTypeRepo->findAllActive(); //create workingDays shifts, assign them drivingpools, get amount of needed drivers /** @var $workingDay WorkingDay */ foreach ($workingDays as $workingDay) { /** @var $shiftType ShiftType */ foreach ($shiftTypes as $shiftType) { $shift = Shift::registerShift($workingDay, $shiftType); $shift->setAmountOfDrivers(16); $workingDay->assignShift($shift); for ($i = 1; $i <= $shift->getAmountOfDrivers(); $i++) { $drivingPool = DrivingPool::registerDrivingPool($shift); $shift->assignDrivingPool($drivingPool); $this->init->drivingPoolRepo->store($drivingPool); } $this->init->shiftRepo->store($shift); } $this->init->workingDayRepo->store($workingDay); } $this->init->em->flush(); $this->assertNotNull($this->init->workingMonthRepo->find($workingMonth->getId())); $drivingAssertionPlans = $this->init->repeatedDrivingAssertionPlanRepo->findPlanForDate(new \DateTime()); $this->assertNotNull($drivingAssertionPlans); $drivingPools = array(); foreach ($workingMonth->getWorkingDays() as $wd) { foreach ($wd->getShifts() as $s) { foreach ($s->getDrivingPools() as $dp) { array_push($drivingPools, $dp); } } } foreach ($drivingAssertionPlans as $drivingAssertionPlan) { $assertions = $drivingAssertionPlan->getRepeatedDrivingAssertions(); foreach ($assertions as $assertion) { if ($assertion->matching($shift)) { echo "\nmatches\n"; $drivingPool = DrivingPool::registerDrivingPool($shift); $this->init->drivingPoolRepo->store($drivingPool); } } } $vehicles = $this->init->vehicleRepo->findAll(); /**@var $vehicle Vehicle */ foreach ($vehicles as $vehicle) { foreach ($vehicle->getServicePlans() as $sp) { } } }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ public function execute(InputInterface $input, OutputInterface $output) { $output->writeln('building variables...'); $month = $input->getArgument('month'); if (!$month) { $month = 1; } $em = $this->getContainer()->get('entity_manager'); $workingMonthRepo = $this->getContainer()->get('workingmonth_repository'); $workingDayRepo = $this->getContainer()->get('workingday_repository'); $shiftRepo = $this->getContainer()->get('shift_repository'); $shiftTypeRepo = $this->getContainer()->get('shifttype_repository'); $drivingPoolRepo = $this->getContainer()->get('drivingpool_repository'); $passengerRepo = $this->getContainer()->get('passenger_repository'); $driverRepo = $this->getContainer()->get('driver_repository'); $vehicleRepo = $this->getContainer()->get('vehicle_repository'); $addressRepo = $this->getContainer()->get('address_repository'); $poiRepo = $this->getContainer()->get('poi_repository'); $routeRepo = $this->getContainer()->get('route_repository'); $drivingMissionRepo = $this->getContainer()->get('drivingmission_repository'); $drivingOrderRepo = $this->getContainer()->get('drivingorder_repository'); $repeatedDrivingAssertionRepo = $this->getContainer()->get('repeateddrivingassertion_repository'); $repeatedDrivingAssertionPlanRepo = $this->getContainer()->get('repeateddrivingassertionplan_repository'); $repeatedDrivingOrderRepo = $this->getContainer()->get('repeateddrivingorder_repository.doctrine'); $repeatedDrivingOrderPlanRepo = $this->getContainer()->get('repeateddrivingorderplan_repository.doctrine'); $time = $this->getContainer()->get('tixi_api.datetimeservice'); $routingMachine = $this->getContainer()->get('tixi_app.routingmachine'); $routeManagement = $this->getContainer()->get('tixi_app.routemanagement'); $dispoManagement = $this->getContainer()->get('tixi_app.dispomanagement'); $this->zonePlanRepository = $this->getContainer()->get('zoneplan_repository'); $this->zoneRepository = $this->getContainer()->get('zone_repository'); $monthDate = new \DateTime('today'); $monthDate->modify('+' . $month . ' month'); // depreciated: $monthDate->modify('+ 10 year'); $monthDate->modify('first day of this month'); $shiftTypes = $shiftTypeRepo->findAllActive(); $output->writeln('target date is ' . $monthDate->format('d.m.Y')); $output->writeln('building driver assertion plans...'); $drivers = $driverRepo->findAllActive(); foreach ($drivers as $driver) { //no other assertion for zivis if ($driver->getDriverCategory()->getId() == 2) { continue; } $reDrivingAssertionPlan = RepeatedDrivingAssertionPlan::registerRepeatedAssertionPlan('test', new \DateTime('today'), 'weekly', rand(0, 1)); $reDrivingAssertionPlan->assignDriver($driver); $driver->assignRepeatedDrivingAssertionPlan($reDrivingAssertionPlan); $repeatedDrivingAssertionPlanRepo->store($reDrivingAssertionPlan); for ($i = 1; $i <= 7; $i++) { if (rand(0, 3) < 3) { $reDrivingWeeklyAssertion = new RepeatedWeeklyDrivingAssertion(); $reDrivingWeeklyAssertion->addShiftType($shiftTypes[rand(0, count($shiftTypes) - 1)]); $reDrivingWeeklyAssertion->addShiftType($shiftTypes[rand(0, count($shiftTypes) - 1)]); $reDrivingWeeklyAssertion->addShiftType($shiftTypes[rand(0, count($shiftTypes) - 1)]); $reDrivingWeeklyAssertion->setWeekday($i); $reDrivingWeeklyAssertion->setAssertionPlan($reDrivingAssertionPlan); $reDrivingAssertionPlan->assignRepeatedDrivingAssertion($reDrivingWeeklyAssertion); $repeatedDrivingAssertionRepo->store($reDrivingWeeklyAssertion); } } } $em->flush(); $output->writeln('building driving pools...'); $drivingPools = 0; $workingMonth = $workingMonthRepo->findWorkingMonthByDate($monthDate); if ($workingMonth !== null) { $output->writeln("WorkingMonth " . $monthDate->format('m') . " already exists"); } else { $workingMonth = $dispoManagement->openWorkingMonth($monthDate->format('Y'), $monthDate->format('m')); $workingDays = $workingMonth->getWorkingDays(); //create workingDays shifts, assign them drivingpools, get amount of needed drivers /** @var $workingDay WorkingDay */ foreach ($workingDays as $workingDay) { /** @var $shiftType ShiftType */ foreach ($workingDay->getShifts() as $shift) { $shift->setAmountOfDrivers(rand(12, 18)); for ($i = 1; $i <= $shift->getAmountOfDrivers(); $i++) { $drivingPool = DrivingPool::registerDrivingPool($shift); $shift->assignDrivingPool($drivingPool); $drivingPoolRepo->store($drivingPool); $drivingPools++; } } } } $em->flush(); $output->writeln('building unclassified zone...'); $this->unclassifiedZone = $this->getUnclassifiedZone(); if (is_null($this->unclassifiedZone)) { $output->writeln('error: cannot create unclassified zone!'); } $output->writeln('building driving orders...'); /**@var $pois POI[] */ $pois = $poiRepo->findAll(); $countPois = count($pois); $orders = array(); $routes = array(); //create Driving Orders $countOrders = 0; foreach ($shiftTypes as $shiftType) { $approxOrdersPerShift = rand(40, 60); for ($i = 0; $i < $approxOrdersPerShift; $i++) { /**@var $passenger Passenger */ $passenger = $passengerRepo->find(rand(100, 500)); $passenger->setIsInWheelChair(rand(0, 1)); /** WARNING: saving times in UTC on database, but minutesOfDay are from midnight, causing * wrong data if a time is UTC 23:30 but CET 00:30 (= 30 minutesOfDay) */ $stStart = $time->convertToLocalDateTime($shiftType->getStart()); $stEnd = $time->convertToLocalDateTime($shiftType->getEnd()); $stDuration = $stStart->diff($stEnd); $minutes = $stDuration->h * 60 + $stDuration->i; $pickupTime = clone $stStart; $pickupTime->add(new \DateInterval('PT' . rand(1, $minutes) . 'M')); $order = DrivingOrder::registerDrivingOrder($passenger, $monthDate, $pickupTime, rand(0, 1), null, 0, 0, 1); $start = $passenger->getAddress(); $target = $pois[rand(0, $countPois - 1)]->getAddress(); $route = Route::registerRoute($start, $target); $hashKey = hash('crc32', $start->getHashFromBigIntCoordinates() . $target->getHashFromBigIntCoordinates()); $routes[$hashKey] = $route; $route = $routeRepo->storeRouteIfNotExist($route); $order->assignRoute($route); $order->assignPassenger($passenger); $passenger->assignDrivingOrder($order); $drivingOrderRepo->store($order); array_push($orders, $order); } } $output->writeln('building driving missions and routes...'); $routingMachine->fillRoutingInformationForMultipleRoutes($routes); /**@var $order DrivingOrder */ foreach ($orders as $order) { $passenger = $order->getPassenger(); $route = $order->getRoute(); $boardingTime = DispositionVariables::BOARDING_TIME + DispositionVariables::DEBOARDING_TIME; $extraMinutesPassenger = $passenger->getExtraMinutes(); $additionalTimesOnRide = $boardingTime + $extraMinutesPassenger; $serviceMinuteOfDay = $time->getMinutesOfDay($order->getPickUpTime()); $serviceDuration = $route->getDurationInMinutes() + $additionalTimesOnRide; $serviceDistance = $route->getDistanceInMeters(); //DrivingMission <-> DrivingOrder $drivingMission = DrivingMission::registerDrivingMission(rand(0, 1), $serviceMinuteOfDay, $serviceDuration, $serviceDistance); $drivingMission->assignDrivingOrder($order); $order->assignDrivingMission($drivingMission); $drivingMissionRepo->store($drivingMission); // DrivingOrder <-> Zone $cities = array($route->getStartAddress()->getCity(), $route->getTargetAddress()->getCity()); $zone = $this->getZoneWithHighestPriorityForCities($cities); $order->assignZone($zone); $countOrders++; } $em->flush(); $output->writeln("\n--------------------------------------------\n" . "Testdata created for month: " . $monthDate->format('m.Y') . " with:\n" . $drivingPools . " DrivingPools \n" . "And orders for one day: " . $monthDate->format('d.m.Y') . " with:\n" . $countOrders . " DrivingOrders and Routes \n"); }
/** * Open (build) a new working month and associated working days (~30), * shifts (~90) , and driving pools (~1800). * * @param $year * @param $month * @return array|null|WorkingMonth */ public function openWorkingMonth($year, $month) { /** @var WorkingMonthRepository $workingMonthRepository */ $workingMonthRepository = $this->container->get('workingmonth_repository'); /** @var WorkingDayRepository $workingDayRepository */ $workingDayRepository = $this->container->get('workingday_repository'); /** @var ShiftRepository $shiftRepository */ $shiftRepository = $this->container->get('shift_repository'); /** @var ShiftTypeRepository $shiftTypeRepository */ $shiftTypeRepository = $this->container->get('shifttype_repository'); /** @var VehicleRepository $vehicleRepository */ $vehicleRepository = $this->container->get('vehicle_repository'); /** @var DrivingPoolRepository $drivingPoolRepository */ $drivingPoolRepository = $this->container->get('drivingpool_repository'); try { $date = new \DateTime(); $date->setDate($year, $month, 1); } catch (\Exception $e) { $logger = $this->container->get('logger'); $logger->error('DispositionManagementImpl->openWorkingMonth: ' . 'illegal date, ' . $e->getMessage()); return null; } $workingMonth = WorkingMonth::registerWorkingMonth($date); $workingMonth->createWorkingDaysForThisMonth(); $shiftTypes = $shiftTypeRepository->findAllActive(); $workingDays = $workingMonth->getWorkingDays(); /** @var WorkingDay $workingDay */ foreach ($workingDays as $workingDay) { $workingDayRepository->store($workingDay); foreach ($shiftTypes as $shiftType) { /* make shifts for working day */ $shift = Shift::registerShift($workingDay, $shiftType, $vehicleRepository->getAmountOfCompanyOwnedVehicles()); $workingDay->assignShift($shift); $shiftRepository->store($shift); /* make driving pools for shift */ $pools = $shift->getAmountOfDrivers(); for ($i = 0; $i < $pools; $i++) { $drivingPoolRepository->store(DrivingPool::registerDrivingPool($shift)); } } } $workingMonthRepository->store($workingMonth); return $workingMonth; }