Esempio n. 1
0
function getData($startStop, $endStop, $startDistance, $endDistance)
{
    $showOnlyIndirectRoutes = 1;
    // find out the buses that pass through these stops
    $checkString = findDistanceBetweenSourceDestination($startStop, $endStop);
    $arr = array();
    $arr = split(":", $checkString);
    $strRoute1 = '';
    $strRoute2 = '';
    $strRoute3 = '';
    $strRoute4 = '';
    $minimalDistanceOption7 = 10000;
    $minimalDistanceOption8 = 10000;
    //print_r($arr);
    if ($arr[4] < 0.7) {
        $strRoute = '';
        $routeDetails = htmlentities($startStop) . ":" . $arr[0] . ":" . $arr[1] . ":" . htmlentities($endStop) . ":" . $arr[2] . ":" . $arr[3] . ":" . $arr[4];
        //$st='sdsd';
        $strRoute = '<Routes>';
        $strRoute = $strRoute . '<Route>';
        $strRoute = $strRoute . '<IsDirectRoute>N</IsDirectRoute>';
        $strRoute = $strRoute . '<ErrorCode>5</ErrorCode>';
        $strRoute = $strRoute . '<RouteDetails>' . $routeDetails . '</RouteDetails>';
        $strRoute = $strRoute . '</Route>';
        $strRoute = $strRoute . '</Routes>';
        return $strRoute;
        //echo "The distance is walkable";
    } else {
        $startBuses = explode(",", getBusesForStopWithFrequency($startStop));
        $endBuses = explode(",", getBusesForStopWithFrequency($endStop));
        //print_r($startBuses);
        //print_r($endBuses);
        // for now pick the first entry as the bus number but we need to do some optimization on choosing the buses based on their frequency, the stop number etc
        //$arrCommonBuses=getCommonBuses($startBuses,$endBuses,$showOnlyIndirectRoutes);
        // print_r($arrCommonBuses);
        //echo getJunctionsForIndirectBuses($arrCommonBuses,$startStop,$endStop,$startDistance,$endDistance);
        $status = getJunctionsForIndirectBusesRevamp3($startStop, $endStop, $startBuses, $endBuses, $startDistance, $endDistance, 0);
        //echo "normal status".$status."<br/>";
        // this should not be the case now but just for the sake of eror handling
        if ($status == "404" || $status == "405") {
            list($endStopDepotName, $endStopDepotDistance) = explode(":", getDepotName($endStop));
            list($startStopDepotName, $startStopDepotDistance) = explode(":", getDepotName($startStop));
            $startStopStartDepotDistance = $startStopDepotDistance;
            $endDepotEndStopDistance = $endStopDepotDistance;
            // echo "StartStop=>".$startStop.":".$startStopDepotName.",".$startStopDepotDistance."<br/>EndStop=>".$endStop.":".$endStopDepotName.",".$endStopDepotDistance;
            $totalDistanceForCase1 = 10000;
            $totalDistanceForCase2 = 10000;
            // intension is that it is possible to take only one detour, starting from the start depot
            if ($startStopDepotDistance < (double) 7) {
                //get the direct buses between the startStop and depot
                //echo "first case";
                //find direct bus between start stop and start depot + distance
                $startStopStartDepotCommonBuses = getBusesCommonBetweenTwoStops($startStop, $startStopDepotName);
                if (sizeof($startStopStartDepotCommonBuses) > 0) {
                    $startStopStartDepotDistance = $startStopDepotDistance;
                    $startDepotEndStopCommonBuses = getBusesCommonBetweenTwoStops($startStopDepotName, $endStop);
                    //print_r($startDepotEndStopCommonBuses);
                    //echo sizeof($startDepotEndStopCommonBuses);
                    if (sizeof($startDepotEndStopCommonBuses) > 0) {
                        $startDepotEndStopDistance = distanceBetweenStops($startStopDepotName, $endStop);
                        $totalDistanceForCase1 = $startDistance + $startStopStartDepotDistance + $startDepotEndStopDistance + $endDistance;
                        $routeInfoString = "There is no direct or indirect bus availalble between " . $startStop . " and " . $endStop . " We have tried to find a route that takes you to a stop where you can find a bus to your destination. However you might have to travel little offroute to reach to the intermediate stop";
                        $strRoute1 = '<Routes>';
                        $strRoute1 = $strRoute1 . '<Route>';
                        $strRoute1 = $strRoute1 . '<IsDirectRoute>N</IsDirectRoute>';
                        $strRoute1 = $strRoute1 . '<ErrorCode>7</ErrorCode>';
                        $strRoute1 = $strRoute1 . "<RouteInfo>" . $routeInfoString . "</RouteInfo>";
                        $routeDetail = "<StartStop>" . htmlentities($startStop) . "</StartStop>";
                        $routeDetail = $routeDetail . "<EndStop>" . htmlentities($endStop) . "</EndStop>";
                        $routeDetail = $routeDetail . "<Depot>" . htmlentities($startStopDepotName) . ":" . getLatitudeLongitude($startStopDepotName) . ":" . getBusesForStop($startStopDepotName) . "</Depot>";
                        $routeDetail = $routeDetail . "<BusesStartStopAndDepot>" . implode(",", $startStopStartDepotCommonBuses) . "</BusesStartStopAndDepot>";
                        $routeDetail = $routeDetail . "<BusesEndStopAndDepot>" . implode(",", $startDepotEndStopCommonBuses) . "</BusesEndStopAndDepot>";
                        $routeDetail = $routeDetail . "<DistanceBetweenDepotAndStartStop>" . $startStopStartDepotDistance . "</DistanceBetweenDepotAndStartStop>";
                        $routeDetail = $routeDetail . "<DistanceBetweenDepotAndEndStop>" . $startDepotEndStopDistance . "</DistanceBetweenDepotAndEndStop>";
                        $routeDetail = $routeDetail . "<TotalRouteDistance>" . $totalDistanceForCase1 . "</TotalRouteDistance>";
                        $routeDetail = $routeDetail . "<UseDepot>1</UseDepot>";
                        $strRoute1 = $strRoute1 . '<RouteDetails>' . $routeDetail . '</RouteDetails>';
                        $strRoute1 = $strRoute1 . '</Route>';
                        $strRoute1 = $strRoute1 . '</Routes>';
                        // echo $strRoute1;
                    }
                }
            }
            // check if the detour is from the endpoint side
            //2. possible to have startStop->EndDepot->endpoint using Bus1, Bus2
            if ($endStopDepotDistance < (double) 7) {
                //echo "second case";
                //find the direct bus between start stop and end depot +distance
                $startStopEndDepotCommonBuses = getBusesCommonBetweenTwoStops($startStop, $endStopDepotName);
                //print_r($startStopEndDepotCommonBuses);
                if (sizeof($startStopEndDepotCommonBuses) > 0) {
                    //echo "first condifition";
                    $startStopEndDepotDistance = distanceBetweenStops($startStop, $endStopDepotName);
                    $endDepotEndStopCommonBuses = getBusesCommonBetweenTwoStops($endStopDepotName, $endStop);
                    if (sizeof($endDepotEndStopCommonBuses) > 0) {
                        //find the direct bus between end depot and the end stop + distnace
                        $endDepotEndStopDistance = $endStopDepotDistance;
                        $totalDistanceForCase2 = $startDistance + $startStopEndDepotDistance + $endDepotEndStopDistance + $endDistance;
                        $routeInfoString = "There is no direct or indirect bus availalble between " . $startStop . " and " . $endStop . ". We have tried to find a route that takes you to a stop where you can find a bus to your destination. However you might have to travel little offroute to reach to the intermediate stop";
                        $strRoute2 = '<Routes>';
                        $strRoute2 = $strRoute2 . '<Route>';
                        $strRoute2 = $strRoute2 . '<IsDirectRoute>N</IsDirectRoute>';
                        $strRoute2 = $strRoute2 . '<ErrorCode>8</ErrorCode>';
                        $strRoute2 = $strRoute2 . "<RouteInfo>" . $routeInfoString . "</RouteInfo>";
                        $routeDetail = "<StartStop>" . htmlentities($startStop) . "</StartStop>";
                        $routeDetail = $routeDetail . "<EndStop>" . htmlentities($endStop) . "</EndStop>";
                        $routeDetail = $routeDetail . "<Depot>" . htmlentities($endStopDepotName) . ":" . getLatitudeLongitude($endStopDepotName) . ":" . getBusesForStop($endStopDepotName) . "</Depot>";
                        $routeDetail = $routeDetail . "<BusesStartStopAndDepot>" . implode(",", $startStopEndDepotCommonBuses) . "</BusesStartStopAndDepot>";
                        $routeDetail = $routeDetail . "<BusesEndStopAndDepot>" . implode(",", $endDepotEndStopCommonBuses) . "</BusesEndStopAndDepot>";
                        $routeDetail = $routeDetail . "<DistanceBetweenDepotAndStartStop>" . $startStopEndDepotDistance . "</DistanceBetweenDepotAndStartStop>";
                        $routeDetail = $routeDetail . "<DistanceBetweenDepotAndEndStop>" . $endDepotEndStopDistance . "</DistanceBetweenDepotAndEndStop>";
                        $routeDetail = $routeDetail . "<TotalRouteDistance>" . $totalDistanceForCase2 . "</TotalRouteDistance>";
                        $routeDetail = $routeDetail . "<UseDepot>1</UseDepot>";
                        $strRoute2 = $strRoute2 . '<RouteDetails>' . $routeDetail . '</RouteDetails>';
                        $strRoute2 = $strRoute2 . '</Route>';
                        $strRoute2 = $strRoute2 . '</Routes>';
                    }
                }
            }
            //echo "tt".$totalDistanceForCase1.",".$totalDistanceForCase2;
            if ($totalDistanceForCase1 > $totalDistanceForCase2) {
                return $strRoute2;
            } else {
                if ($totalDistanceForCase1 < $totalDistanceForCase2) {
                    return $strRoute1;
                }
            }
            // if both the start poit detour and the endpoint detour failed that means you dont have the buses either from the
            // detour to the endpoint or between the start point and the detour
            if ($totalDistanceForCase1 == 10000 && $totalDistanceForCase2 == 10000) {
                if ($startStopDepotDistance < (double) 7) {
                    //echo "hi";
                    $routeInfoString = "There is no direct or indirect bus availalble between " . $startStop . " and " . $endStop . ". We have tried to find a route that takes you to a stop where you can find a bus to your destination. However you might have to travel little offroute to reach to the intermediate stop";
                    $startStopStartDepotCommonBuses = getBusesCommonBetweenTwoStops($startStop, $startStopDepotName);
                    $strRoute3 = '<Routes>';
                    //$strRoute2=$strRoute2.'<Route>';
                    $strRoute3 = $strRoute3 . '<IsDirectRoute>N</IsDirectRoute>';
                    $strRoute3 = $strRoute3 . '<ErrorCode>9</ErrorCode>';
                    $strRoute3 = $strRoute3 . "<RouteInfo>" . $routeInfoString . "</RouteInfo>";
                    $routeDetail = "<StartStop>" . htmlentities($startStop) . "</StartStop>";
                    $routeDetail = $routeDetail . "<EndStop>" . htmlentities($endStop) . "</EndStop>";
                    $routeDetail = $routeDetail . "<Depot>" . htmlentities($startStopDepotName) . ":" . getLatitudeLongitude($startStopDepotName) . ":" . getBusesForStop($startStopDepotName) . "</Depot>";
                    $routeDetail = $routeDetail . "<BusesBetweenStopAndDepot>" . implode(",", $startStopStartDepotCommonBuses) . "</BusesBetweenStopAndDepot>";
                    $routeDetail = $routeDetail . "<DistanceBetweenDepotAndStop>" . $startStopStartDepotDistance . "</DistanceBetweenDepotAndStop>";
                    //  echo "==================";
                    $startDepotBuses = explode(",", getBusesForStopWithFrequency($startStopDepotName));
                    $totalDistanceBeforeReachingToDepot = $startDistance + $startStopStartDepotDistance;
                    $indirectRoutesDetails = getJunctionsForIndirectBusesRevamp3($startStopDepotName, $endStop, $startDepotBuses, $endBuses, 0, $endDistance, $showOnlyIndirectRoutes, 1, $totalDistanceBeforeReachingToDepot);
                    if ($indirectRoutesDetails != "404" && $indirectRoutesDetails != "405") {
                        list($indirectBusesBetweenDepotAndEndpoint, $minimalDistanceOption7) = explode("^", $indirectRoutesDetails);
                        $routeDetail = $routeDetail . "<indirectRoutes>" . $indirectBusesBetweenDepotAndEndpoint . "</indirectRoutes>";
                        //$routeDetail=$routeDetail."<UseDepot>1</UseDepot>";
                        $strRoute3 = $strRoute3 . '<RouteDetails>' . $routeDetail . '</RouteDetails>';
                        //$strRoute2=$strRoute2.'</Route>';
                        $strRoute3 = $strRoute3 . '</Routes>';
                        //echo $strRoute3;
                    } else {
                        $minimalDistanceOption7 = 10000;
                    }
                }
                if ($endStopDepotDistance < (double) 7) {
                    $routeInfoString = "There is no direct or indirect bus availalble between " . $startStop . " and " . $endStop . ". We have tried to find a route that takes you to a stop where you can find a bus to your destination. However you might have to travel little offroute to reach to the intermediate stop";
                    $strRoute4 = '<Routes>';
                    $strRoute4 = $strRoute4 . '<IsDirectRoute>N</IsDirectRoute>';
                    $strRoute4 = $strRoute4 . '<ErrorCode>10</ErrorCode>';
                    $strRoute4 = $strRoute4 . "<RouteInfo>" . $routeInfoString . "</RouteInfo>";
                    $routeDetail = "<StartStop>" . htmlentities($startStop) . "</StartStop>";
                    $routeDetail = $routeDetail . "<EndStop>" . htmlentities($endStop) . "</EndStop>";
                    $endDepotEndStopCommonBuses = getBusesCommonBetweenTwoStops($endStopDepotName, $endStop);
                    $routeDetail = $routeDetail . "<Depot>" . htmlentities($endStopDepotName) . ":" . getLatitudeLongitude($endStopDepotName) . ":" . getBusesForStop($endStopDepotName) . "</Depot>";
                    $routeDetail = $routeDetail . "<BusesBetweenStopAndDepot>" . implode(",", $endDepotEndStopCommonBuses) . "</BusesBetweenStopAndDepot>";
                    $routeDetail = $routeDetail . "<DistanceBetweenDepotAndStop>" . $endDepotEndStopDistance . "</DistanceBetweenDepotAndStop>";
                    //  echo "==================";
                    $endDepotBuses = explode(",", getBusesForStopWithFrequency($endStopDepotName));
                    $totalDistanceBeforeReachingToDepot = $endDistance + $endDepotEndStopDistance;
                    $indirectRoutesDetails = getJunctionsForIndirectBusesRevamp3($startStop, $endStopDepotName, $startBuses, $endDepotBuses, $startDistance, 0, $showOnlyIndirectRoutes, 1, $totalDistanceBeforeReachingToDepot);
                    if ($indirectRoutesDetails != "404" && $indirectRoutesDetails != "405") {
                        list($indirectBusesBetweenDepotAndEndpoint, $minimalDistanceOption8) = explode("^", $indirectRoutesDetails);
                        $routeDetail = $routeDetail . "<indirectRoutes>" . $indirectBusesBetweenDepotAndEndpoint . "</indirectRoutes>";
                        //$routeDetail=$routeDetail."<UseDepot>1</UseDepot>";
                        $strRoute4 = $strRoute4 . '<RouteDetails>' . $routeDetail . '</RouteDetails>';
                        //$strRoute2=$strRoute2.'</Route>';
                        $strRoute4 = $strRoute4 . '</Routes>';
                        //echo $strRoute3;
                    } else {
                        $minimalDistanceOption8 = 10000;
                    }
                } else {
                    $minimalDistanceOption7 = 10000;
                    $minimalDistanceOption8 = 10000;
                }
            }
            //echo $minimalDistanceOption7.",".$minimalDistanceOption8;
            if ($minimalDistanceOption7 == 10000 && $minimalDistanceOption8 == 10000) {
                //the depots are too far away
                $strRoute = '<Routes>';
                $strRoute = $strRoute . '<Route>';
                $strRoute = $strRoute . '<IsDirectRoute>N</IsDirectRoute>';
                $strRoute = $strRoute . '<ErrorCode>411</ErrorCode>';
                $strRoute = $strRoute . '<StartStop>' . $startStop . '</StartStop>';
                $strRoute = $strRoute . '<EndStop>' . $endStop . '</EndStop>';
                $strRoute = $strRoute . '</Route>';
                $strRoute = $strRoute . '</Routes>';
                return $strRoute;
            } else {
                if ($minimalDistanceOption7 < $minimalDistanceOption8) {
                    return $strRoute3;
                } else {
                    return $strRoute4;
                }
            }
        } else {
            $strRoute = '<Routes>' . $status . '</Routes>';
            return $strRoute;
        }
    }
    //echo "<sample>hhhh</sample>";
}
function distanceBetweenStops($stop1, $stop2)
{
    list($lat1, $lon1) = explode(":", getLatitudeLongitude($stop1));
    list($lat2, $lon2) = explode(":", getLatitudeLongitude($stop2));
    $dist = distance($lat1, $lon1, $lat2, $lon2, "K");
    //echo "distance between".$stop1."and".$stop2."is".$dist;
    return $dist;
}
Esempio n. 3
0
/**
* getJunctionsForIndirectBuses: function to find the junction. The junction is same as the stop only difference is that some
* of the stops have mulitple names we need to normalize them. It will combine the buses that are passing to the same 
* junction. The function is mailnly to control the way the informatioin is displayed to the user

change: 27Dec2011
In case when either the bus from the start stop to first junction is not present or the bus from the second jucntion to the end stop is not present
I am removing that particular entry (error code6) but we can as well say in the javascript that this is the case when the user can just walk to/from the 
junction .. Need to chekc on this

The error codes
0: Direct buses are found
1: only one jucntion found same as search" Bellandur" to Forum Mall
2.: One junction but then the user needs to walk to the endpoint. no need to take a bus: search string abhi yaad nahin aa rahi
3: two junctions. User needs to walk between the junction search "Bellandur" "Meanee Avenue Road"
4: No route was found ....give some junk values
5: Distance is walkable no bus to take search Bellandur and Accenture
6: Ignore this particular enetry


**/
function getJunctionsForIndirectBuses($arrBuses, $startStop, $endStop, $startOffsetDistance, $endOffsetDistance)
{
    //print_r($arrBuses);
    $array_size = sizeof($arrBuses);
    // check if the buses are direct buses
    list($firstBus, $secondBus) = split(":", $arrBuses[0]);
    if ($array_size > 0 && strcmp($firstBus, $secondBus) == 0) {
        return displayDirectBuses($arrBuses);
    } else {
        $arrFirstJunctions = array();
        $arrSecondJunctions = array();
        $arrFirstBuses = array();
        $arrSecondBuses = array();
        for ($i = 0; $i < $array_size; $i++) {
            list($firstBus, $secondBus) = split(":", $arrBuses[$i]);
            array_push($arrFirstBuses, $firstBus);
            array_push($arrSecondBuses, $secondBus);
        }
        //print_r($arrFirstBuses);
        $arrayUniqueJunctions = array();
        for ($i = 0; $i < $array_size; $i++) {
            list($firstBus, $secondBus) = split(":", $arrBuses[$i]);
            list($firstBus, $firstBusRouteNumber, $firstJunction, $secondBus, $secondBusRouteNumber, $secondJunction, $distance) = split(":", getIntermediateStopsAndDistance($firstBus, $secondBus));
            if (strlen($firstBus) == 0) {
                continue;
            }
            // this is the case of wrong combinations
            //  echo getIntermediateStopsAndDistance($firstBus,$secondBus)."<br/>";
            // find the uniue combinations of fisrt and second junctions
            if ($distance < 0.6) {
                if (checkUniqueJunctions($arrayUniqueJunctions, $firstJunction, $secondJunction, $distance) == 0) {
                    // also chekc that the endstop or the start stop is not same as the juntion as in case of marathahalli bridge and multiplex
                    if (strcmp(getNormalizedStopName($firstJunction), $startStop) == 0 || strcmp(getNormalizedStopName($firstJunction), $endStop) == 0 || strcmp(getNormalizedStopName($secondJunction), $startStop) == 0 || strcmp(getNormalizedStopName($secondJunction), $endStop) == 0) {
                        continue;
                    } else {
                        $element = getNormalizedStopName($firstJunction) . ":" . getNormalizedStopName($secondJunction) . ":" . $distance;
                        array_push($arrayUniqueJunctions, $element);
                    }
                }
            }
        }
        //print_r($arrayUniqueJunctions);
        // module to sort the results on the basids of the total distance
        $displayJunctionsDataArray = array();
        for ($i = 0; $i < sizeof($arrayUniqueJunctions); $i++) {
            $tempJunctionString = $arrayUniqueJunctions[$i];
            list($firstJnName, $secondJnName, $distanceJn) = split(":", $arrayUniqueJunctions[$i]);
            $tot = getTotalRouteDistance($startStop, $firstJnName, $secondJnName, $distanceJn, $endStop, $startOffsetDistance, $endOffsetDistance);
            $element = new DisplayJunctionsData($tempJunctionString, $tot);
            array_push($displayJunctionsDataArray, $element);
        }
        $SortedJunctionsDataArray = prioritizeAndSortJunctionArray(BubbleSort($displayJunctionsDataArray, sizeof($displayJunctionsDataArray)));
        //echo "sdsd";
        //print_r($SortedJunctionsDataArray);
        // display the results
        $strRoute = '';
        if (sizeof($SortedJunctionsDataArray) == 0) {
            $strRoute = '<Routes>';
            $strRoute = $strRoute . '<Route>';
            $strRoute = $strRoute . '<IsDirectRoute>N</IsDirectRoute>';
            $strRoute = $strRoute . '<ErrorCode>4</ErrorCode>';
            $strRoute = $strRoute . '</Route>';
            $strRoute = $strRoute . '</Routes>';
        } else {
            $strRoute = '<Routes>';
            // there can be chances that when we are filling the xml all the details are not properly found. In that case we need to
            // remove that entry. If at the end this check counter becomes equals to the sizeof($SortedJunctionsDataArray). It means every entry had a problem
            // and we will return the error code 4
            $FalseAlarmCounter = 0;
            for ($i = 0; $i < sizeof($SortedJunctionsDataArray); $i++) {
                $isCorrectEntry = 1;
                // check if this particular entry is correct. Since the node need to be removed otherwise
                if ($i > 2) {
                    // this will restrict the indirect results to 3
                    break;
                }
                list($firstJnName, $secondJnName, $distanceJn) = split(":", $SortedJunctionsDataArray[$i]->getJunctionString());
                //get all the buses for firstJn
                $strRoute = $strRoute . '<Route>';
                $strRoute = $strRoute . '<IsDirectRoute>N</IsDirectRoute>';
                //get all the buses for second jun
                if ($distanceJn == 0 && strcmp(getNormalizedStopName($firstJnName), $startStop) != 0) {
                    $getCommonBusesForFirstJunction = getCommonBusesForNormalizedStopName($firstJnName, $arrFirstBuses);
                    $getCommonBusesForSecondJunction = getCommonBusesForNormalizedStopName($secondJnName, $arrSecondBuses);
                    if (strlen($getCommonBusesForFirstJunction) > 0 && strlen($getCommonBusesForSecondJunction) > 0) {
                        $strRoute = $strRoute . '<ErrorCode>1</ErrorCode>';
                        $routeDetail = htmlentities($startStop) . ":" . $getCommonBusesForFirstJunction . ":";
                        $routeDetail = $routeDetail . htmlentities(getNormalizedStopName($firstJnName)) . ":" . getLatitudeLongitude(getNormalizedStopName($firstJnName)) . ":0:";
                        $routeDetail = $routeDetail . htmlentities(getNormalizedStopName($firstJnName)) . ":" . getLatitudeLongitude(getNormalizedStopName($firstJnName)) . ":" . $getCommonBusesForSecondJunction . ":";
                        $routeDetail = $routeDetail . htmlentities($endStop);
                    } else {
                        $strRoute = $strRoute . '<ErrorCode>6</ErrorCode>';
                        $FalseAlarmCounter++;
                    }
                } else {
                    // if the end point is same as the second junction it may happend that you juct have to walk from the first junction to the end point
                    if (strcmp(getNormalizedStopName($secondJnName), $endStop) == 0) {
                        $strRoute = $strRoute . '<ErrorCode>2</ErrorCode>';
                        $routeDetail = htmlentities($startStop) . ":" . getCommonBusesForNormalizedStopName($firstJnName, $arrFirstBuses) . ":";
                        $routeDetail = $routeDetail . htmlentities(getNormalizedStopName($firstJnName)) . ":" . getLatitudeLongitude(getNormalizedStopName($firstJnName)) . ":" . $distanceJn . ":";
                        $routeDetail = $routeDetail . htmlentities(getNormalizedStopName($firstJnName)) . ":" . getLatitudeLongitude(getNormalizedStopName($firstJnName)) . ":" . getCommonBusesForNormalizedStopName($secondJnName, $arrSecondBuses) . ":";
                        $routeDetail = $routeDetail . htmlentities($endStop);
                    } else {
                        $getCommonBusesForFirstJunction = getCommonBusesForNormalizedStopName($firstJnName, $arrFirstBuses);
                        $getCommonBusesForSecondJunction = getCommonBusesForNormalizedStopName($secondJnName, $arrSecondBuses);
                        if (strlen($getCommonBusesForFirstJunction) > 0 && strlen($getCommonBusesForSecondJunction) > 0) {
                            $strRoute = $strRoute . '<ErrorCode>3</ErrorCode>';
                            $routeDetail = htmlentities($startStop) . ":" . getCommonBusesForNormalizedStopName($firstJnName, $arrFirstBuses) . ":";
                            $routeDetail = $routeDetail . htmlentities(getNormalizedStopName($firstJnName)) . ":" . getLatitudeLongitude(getNormalizedStopName($firstJnName)) . ":" . $distanceJn . ":";
                            $routeDetail = $routeDetail . htmlentities(getNormalizedStopName($secondJnName)) . ":" . getLatitudeLongitude(getNormalizedStopName($secondJnName)) . ":" . getCommonBusesForNormalizedStopName($secondJnName, $arrSecondBuses) . ":";
                            $routeDetail = $routeDetail . htmlentities($endStop);
                        } else {
                            $FalseAlarmCounter++;
                        }
                    }
                }
                //echo "The approximate route distance="."<b>".$SortedJunctionsDataArray[$i]->getDistance()."KM</b>";
                $routeDetail = $routeDetail . ":" . $SortedJunctionsDataArray[$i]->getDistance();
                $strRoute = $strRoute . '<RouteDetails>' . $routeDetail . '</RouteDetails>';
                //echo "<hr/>";
                $strRoute = $strRoute . '</Route>';
                //echo $strRoute;
            }
            $strRoute = $strRoute . '</Routes>';
            // check if every thing was wrong that means we need to send the erro codes.
            if ($FalseAlarmCounter == sizeof($SortedJunctionsDataArray)) {
                $strRoute = '<Routes>';
                $strRoute = $strRoute . '<Route>';
                $strRoute = $strRoute . '<IsDirectRoute>N</IsDirectRoute>';
                $strRoute = $strRoute . '<ErrorCode>4</ErrorCode>';
                $strRoute = $strRoute . '</Route>';
                $strRoute = $strRoute . '</Routes>';
            }
        }
        return $strRoute;
    }
}
Esempio n. 4
0
						
						if(sizeof($endDepotEndStopCommonBuses)>0)
						{
							//find the direct bus between end depot and the end stop + distnace
							$endDepotEndStopDistance=$endStopDepotDistance;
							$totalDistanceForCase2=$startDistance+$startStopEndDepotDistance+$endDepotEndStopDistance+$endDistance;
							$routeInfoString="There is no direct or indirect bus availalble between ".$startStop." and ".$endStop.". We have tried to find a route that takes you to a stop where you can find a bus to your destination. However you might have to travel little offroute to reach to the intermediate stop";
							
							$strRoute2='<Routes>';
							 $strRoute2=$strRoute2.'<Route>';
							 $strRoute2=$strRoute2.'<IsDirectRoute>N</IsDirectRoute>';
							 $strRoute2=$strRoute2.'<ErrorCode>8</ErrorCode>';
							 $strRoute2=$strRoute2."<RouteInfo>".$routeInfoString."</RouteInfo>";							
							 $routeDetail="<StartStop>".htmlentities($startStop)."</StartStop>";
							 $routeDetail=$routeDetail."<EndStop>".htmlentities($endStop)."</EndStop>";
							 $routeDetail=$routeDetail."<Depot>".htmlentities($endStopDepotName).":".getLatitudeLongitude($endStopDepotName).":".getBusesForStop($endStopDepotName)."</Depot>";
							 $routeDetail=$routeDetail."<BusesStartStopAndDepot>".implode(",",$startStopEndDepotCommonBuses)."</BusesStartStopAndDepot>";
							 $routeDetail=$routeDetail."<BusesEndStopAndDepot>".implode(",",$endDepotEndStopCommonBuses)."</BusesEndStopAndDepot>";							 
							 $routeDetail=$routeDetail."<DistanceBetweenDepotAndStartStop>".$startStopEndDepotDistance."</DistanceBetweenDepotAndStartStop>";
							 $routeDetail=$routeDetail."<DistanceBetweenDepotAndEndStop>".$endDepotEndStopDistance."</DistanceBetweenDepotAndEndStop>";
							 $routeDetail=$routeDetail."<TotalRouteDistance>".$totalDistanceForCase2."</TotalRouteDistance>";
							 $routeDetail=$routeDetail."<UseDepot>1</UseDepot>";
							 $strRoute2=$strRoute2.'<RouteDetails>'.$routeDetail.'</RouteDetails>';
							 $strRoute2=$strRoute2.'</Route>';
							 $strRoute2=$strRoute2.'</Routes>';

							// echo $strRoute2;
						}					
					}
				}
Esempio n. 5
0
function getData($startStop, $endStop, $startDistance, $endDistance)
{
    //$showOnlyIndirectRoutes=$_GET['onlyIndirectRoutes'];
    // find out the buses that pass through these stops
    $checkString = findDistanceBetweenSourceDestination($startStop, $endStop);
    $arr = array();
    $arr = explode(":", $checkString);
    //print_r($arr);
    if ($arr[4] < 0.7) {
        $strRoute = '';
        $routeDetails = htmlentities($startStop) . ":" . $arr[0] . ":" . $arr[1] . ":" . htmlentities($endStop) . ":" . $arr[2] . ":" . $arr[3] . ":" . $arr[4];
        //$st='sdsd';
        $strRoute = '<Routes>';
        $strRoute = $strRoute . '<Route>';
        $strRoute = $strRoute . '<IsDirectRoute>N</IsDirectRoute>';
        $strRoute = $strRoute . '<ErrorCode>5</ErrorCode>';
        $strRoute = $strRoute . '<RouteDetails>' . $routeDetails . '</RouteDetails>';
        $strRoute = $strRoute . '</Route>';
        $strRoute = $strRoute . '</Routes>';
        return $strRoute;
        //echo "The distance is walkable";
    } else {
        $startBuses = explode(",", getBusesForStopWithFrequency($startStop));
        $endBuses = explode(",", getBusesForStopWithFrequency($endStop));
        //removed the use of the showdirect buses form the helper
        $status = getJunctionsForIndirectBusesRevamp2($startStop, $endStop, $startBuses, $endBuses, $startDistance, $endDistance, 0);
        //echo "normal status".$status."<br/>";
        // this should not be the case now but just for the sake of eror handling
        if ($status == "404" || $status == "405") {
            list($endStopDepotName, $endStopDepotDistance) = explode(":", getDepotName($endStop));
            list($startStopDepotName, $startStopDepotDistance) = explode(":", getDepotName($startStop));
            $totalDistanceForCase1 = 10000;
            $totalDistanceForCase2 = 10000;
            if ($startStopDepotDistance < (double) 7) {
                //find direct bus between start stop and start depot + distance
                $startStopStartDepotCommonBuses = getBusesCommonBetweenTwoStops($startStop, $startStopDepotName);
                if (sizeof($startStopStartDepotCommonBuses) > 0) {
                    $startStopStartDepotDistance = $startStopDepotDistance;
                    $startDepotEndStopCommonBuses = getBusesCommonBetweenTwoStops($startStopDepotName, $endStop);
                    //print_r($startDepotEndStopCommonBuses);
                    //echo sizeof($startDepotEndStopCommonBuses);
                    if (sizeof($startDepotEndStopCommonBuses) > 0) {
                        $startDepotEndStopDistance = distanceBetweenStops($startStopDepotName, $endStop);
                        $totalDistanceForCase1 = $startDistance + $startStopStartDepotDistance + $startDepotEndStopDistance + $endDistance;
                        $routeInfoString = "There is no direct or indirect bus availalble between " . $startStop . " and " . $endStop . " We have tried to find a route that takes you to a stop where you can find a bus to your destination. However you might have to travel little offroute to reach to the intermediate stop";
                        $strRoute1 = '<Routes>';
                        $strRoute1 = $strRoute1 . '<Route>';
                        $strRoute1 = $strRoute1 . '<IsDirectRoute>N</IsDirectRoute>';
                        $strRoute1 = $strRoute1 . '<ErrorCode>7</ErrorCode>';
                        $strRoute1 = $strRoute1 . "<RouteInfo>" . $routeInfoString . "</RouteInfo>";
                        $routeDetail = "<StartStop>" . htmlentities($startStop) . "</StartStop>";
                        $routeDetail = $routeDetail . "<EndStop>" . htmlentities($endStop) . "</EndStop>";
                        $routeDetail = $routeDetail . "<Depot>" . htmlentities($startStopDepotName) . ":" . getLatitudeLongitude($startStopDepotName) . "</Depot>";
                        $routeDetail = $routeDetail . "<BusesStartStopAndDepot>" . implode(",", $startStopStartDepotCommonBuses) . "</BusesStartStopAndDepot>";
                        $routeDetail = $routeDetail . "<BusesEndStopAndDepot>" . implode(",", $startDepotEndStopCommonBuses) . "</BusesEndStopAndDepot>";
                        $routeDetail = $routeDetail . "<DistanceBetweenDepotAndStartStop>" . $startStopStartDepotDistance . "</DistanceBetweenDepotAndStartStop>";
                        $routeDetail = $routeDetail . "<DistanceBetweenDepotAndEndStop>" . $startDepotEndStopDistance . "</DistanceBetweenDepotAndEndStop>";
                        $routeDetail = $routeDetail . "<TotalRouteDistance>" . $totalDistanceForCase1 . "</TotalRouteDistance>";
                        $routeDetail = $routeDetail . "<UseDepot>1</UseDepot>";
                        $strRoute1 = $strRoute1 . '<RouteDetails>' . $routeDetail . '</RouteDetails>';
                        $strRoute1 = $strRoute1 . '</Route>';
                        $strRoute1 = $strRoute1 . '</Routes>';
                        // echo $strRoute1;
                    }
                }
            }
            // check if the detour is from the endpoint side
            //2. possible to have startStop->EndDepot->endpoint using Bus1, Bus2
            if ($endStopDepotDistance < (double) 7) {
                //echo "second case";
                //find the direct bus between start stop and end depot +distance
                $startStopEndDepotCommonBuses = getBusesCommonBetweenTwoStops($startStop, $endStopDepotName);
                //print_r($startStopEndDepotCommonBuses);
                if (sizeof($startStopEndDepotCommonBuses) > 0) {
                    //echo "first condifition";
                    $startStopEndDepotDistance = distanceBetweenStops($startStop, $endStopDepotName);
                    $endDepotEndStopCommonBuses = getBusesCommonBetweenTwoStops($endStopDepotName, $endStop);
                    if (sizeof($endDepotEndStopCommonBuses) > 0) {
                        //find the direct bus between end depot and the end stop + distnace
                        $endDepotEndStopDistance = $endStopDepotDistance;
                        $totalDistanceForCase2 = $startDistance + $startStopEndDepotDistance + $endDepotEndStopDistance + $endDistance;
                        $routeInfoString = "There is no direct or indirect bus availalble between " . $startStop . " and " . $endStop . ". We have tried to find a route that takes you to a stop where you can find a bus to your destination. However you might have to travel little offroute to reach to the intermediate stop";
                        $strRoute2 = '<Routes>';
                        $strRoute2 = $strRoute2 . '<Route>';
                        $strRoute2 = $strRoute2 . '<IsDirectRoute>N</IsDirectRoute>';
                        $strRoute2 = $strRoute2 . '<ErrorCode>8</ErrorCode>';
                        $strRoute1 = $strRoute1 . "<RouteInfo>" . $routeInfoString . "</RouteInfo>";
                        $routeDetail = "<StartStop>" . htmlentities($startStop) . "</StartStop>";
                        $routeDetail = $routeDetail . "<EndStop>" . htmlentities($endStop) . "</EndStop>";
                        $routeDetail = $routeDetail . "<Depot>" . htmlentities($endStopDepotName) . ":" . getLatitudeLongitude($endStopDepotName) . "</Depot>";
                        $routeDetail = $routeDetail . "<BusesStartStopAndDepot>" . implode(",", $startStopEndDepotCommonBuses) . "</BusesStartStopAndDepot>";
                        $routeDetail = $routeDetail . "<BusesEndStopAndDepot>" . implode(",", $endDepotEndStopCommonBuses) . "</BusesEndStopAndDepot>";
                        $routeDetail = $routeDetail . "<DistanceBetweenDepotAndStartStop>" . $startStopEndDepotDistance . "</DistanceBetweenDepotAndStartStop>";
                        $routeDetail = $routeDetail . "<DistanceBetweenDepotAndEndStop>" . $endDepotEndStopDistance . "</DistanceBetweenDepotAndEndStop>";
                        $routeDetail = $routeDetail . "<TotalRouteDistance>" . $totalDistanceForCase2 . "</TotalRouteDistance>";
                        $routeDetail = $routeDetail . "<UseDepot>1</UseDepot>";
                        $strRoute2 = $strRoute2 . '<RouteDetails>' . $routeDetail . '</RouteDetails>';
                        $strRoute2 = $strRoute2 . '</Route>';
                        $strRoute2 = $strRoute2 . '</Routes>';
                        // echo $strRoute2;
                    }
                }
            }
            if ($totalDistanceForCase1 < 10000 && $totalDistanceForCase2 < 10000) {
                if ($totalDistanceForCase1 > $totalDistanceForCase2) {
                    return $strRoute2;
                } else {
                    return $strRoute1;
                }
            } else {
                if ($totalDistanceForCase1 == 10000 && $totalDistanceForCase2 == 10000) {
                    if ($startStopDepotDistance < (double) 7 && $endStopDepotDistance < (double) 7) {
                        //find the direct bus between start stop and end depot +distance
                        $startStopStartDepotCommonBuses = getBusesCommonBetweenTwoStops($startStop, $startStopDepotName);
                        //print_r($startStopStartDepotCommonBuses);
                        $endDepotEndStopCommonBuses = getBusesCommonBetweenTwoStops($endStopDepotName, $endStop);
                        //print_r($endDepotEndStopCommonBuses);
                        if (sizeof($startStopStartDepotCommonBuses) > 0 && sizeof($endDepotEndStopCommonBuses) > 0) {
                            //echo "hhh";
                            //get the buses between the two depots
                            $busesForStartDepot = explode(",", getBusesForStopWithFrequency($startStopDepotName));
                            $busesForEndDepot = explode(",", getBusesForStopWithFrequency($endStopDepotName));
                            $startStopOffsetDistance = $startDistance;
                            $endStopOffsetDistance = $endDistance;
                            $startStopStartDepotCommonBusesString = implode(",", $startStopStartDepotCommonBuses);
                            $endDepotEndStopCommonBusesString = implode(",", $endDepotEndStopCommonBuses);
                            $interDepotStatus = getJunctionsForInterDepotTravel($startStop, $endStop, $startStopDepotName, $endStopDepotName, $busesForStartDepot, $busesForEndDepot, $startStopOffsetDistance, $endStopOffsetDistance, $startStopStartDepotCommonBusesString, $endDepotEndStopCommonBusesString, $startStopDepotDistance, $endStopDepotDistance, 0);
                            //need to add the bus info between the startstop and depot+last depot and end point
                            if ($interDepotStatus == "409" || $interDepotStatus == "410") {
                                // buses not found between the depots using a single or no hop
                                $strRoute = '<Routes>';
                                $strRoute = $strRoute . '<Route>';
                                $strRoute = $strRoute . '<IsDirectRoute>N</IsDirectRoute>';
                                $strRoute = $strRoute . '<ErrorCode>' . $interDepotStatus . '</ErrorCode>';
                                $strRoute = $strRoute . '</Route>';
                                $strRoute = $strRoute . '</Routes>';
                                return $strRoute;
                            } else {
                                $strRoute = $interDepotStatus;
                                return $strRoute;
                            }
                        }
                    } else {
                        //the depots are too far away
                        $strRoute = '<Routes>';
                        $strRoute = $strRoute . '<Route>';
                        $strRoute = $strRoute . '<IsDirectRoute>N</IsDirectRoute>';
                        $strRoute = $strRoute . '<ErrorCode>411</ErrorCode>';
                        $strRoute = $strRoute . '</Route>';
                        $strRoute = $strRoute . '</Routes>';
                        return $strRoute;
                    }
                }
            }
        } else {
            return $status;
        }
    }
    //echo "<sample>hhhh</sample>";
}
Esempio n. 6
0
            exit;
        }
    }
}
/*$b = $a = $aSearchProp;
	function cmp($a, $b) {
		if($a['distance'] == $b['distance']) {
			return 0;
		}
		return ($a['distance'] < $b['distance']) ? -1 : 1;
	}

	uasort($a, 'cmp');
	$aSearchProp = $a;*/
$adr = preg_replace("@\\s+@", "+", $address);
$main = getLatitudeLongitude($adr);
$markers = array();
$markers[] = array('id' => 'C', 'address' => $address, 'latitude' => $main['latitude'], 'longitude' => $main['longitude']);
?>


<?php 
$locstring = '';
$c = 1;
foreach ($markers as $m) {
    if ($c == 1) {
        $color = "red";
    } else {
        if ($c % 2 == 0) {
            $color = "green";
        } else {