コード例 #1
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;
    }
}
コード例 #2
0
ファイル: HelperFunctions.php プロジェクト: rohdimp24/test
/**
* 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
**/
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(strcmp($firstBus,$secondBus)==0)
		displayDirectBuses($arrBuses);
	
	// indirect buses
	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<1)// make suere that the distance between the junctions is not more than 1 km.
			{
				if(checkUniqueJunctions($arrayUniqueJunctions,$firstJunction,$secondJunction,$distance)==0)
				{
					$element=getNormalizedStopName($firstJunction).":".getNormalizedStopName($secondJunction).":".$distance;
					array_push($arrayUniqueJunctions,$element);
				}
			}
		}
		
		//echo "the unique ones are "."<br/>";
		//print_r($arrayUniqueJunctions);
		echo "<br/>";
		
		// 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=BubbleSort($displayJunctionsDataArray,sizeof($displayJunctionsDataArray));
		//print_r($SortedJunctionsDataArray);
		// print the buses
		/*for($i=0;$i<sizeof($arrayUniqueJunctions);$i++)
		{
			list($firstJnName,$secondJnName,$distanceJn)=split(":",$arrayUniqueJunctions[$i]);
			//get all the buses for firstJn
			echo "From "."<b>".$startStop." (Starting Point)</b> take ". getCommonBusesForNormalizedStopName($firstJnName,$arrFirstBuses)." and go to ". "<b>".getNormalizedStopName($firstJnName)."</b><br/>" ;

			//get all the buses for second jun
			if($distanceJn==0)
			{
				echo "Now from ". "<b>".getNormalizedStopName($firstJnName)."</b>". " take one of the". getCommonBusesForNormalizedStopName($secondJnName,$arrSecondBuses)." buses to go to ". "<b>".$endStop. " (Your Destination)</b><br/>";
				//echo "The distance between the junction is ". $distanceJn ."<br/>";
			}
			else
			{
				echo "You need to walk to  "."<b>".getNormalizedStopName($secondJnName)."</b>" ." which is ".$distanceJn. "KM from ". "<b>".$firstJnName."</b><br/>";
				echo "Now from ". "<b>".getNormalizedStopName($secondJnName)."</b>"."take one of the". getCommonBusesForNormalizedStopName($secondJnName,$arrSecondBuses)." buses to go to ". "<b>".$endStop. "(Your Destination)</b><br/>";
			}
			
			echo "The approximate route distance="."<b>".getTotalRouteDistance($startStop,$firstJnName,$secondJnName,$distanceJn,$endStop,$startOffsetDistance,$endOffsetDistance)."KM</b>";
			echo "<hr/>";
			
			
		}*/
		for($i=0;$i<sizeof($SortedJunctionsDataArray);$i++)
		{
			list($firstJnName,$secondJnName,$distanceJn)=split(":",$SortedJunctionsDataArray[$i]->getJunctionString());
			//get all the buses for firstJn
			echo "From "."<b>".$startStop." (Starting Point)</b> take ". getCommonBusesForNormalizedStopName($firstJnName,$arrFirstBuses)." and go to ". "<b>".getNormalizedStopName($firstJnName)."</b><br/>" ;

			//get all the buses for second jun
			if($distanceJn==0)
			{
				echo "Now from ". "<b>".getNormalizedStopName($firstJnName)."</b>". " take one of the". getCommonBusesForNormalizedStopName($secondJnName,$arrSecondBuses)." buses to go to ". "<b>".$endStop. " (Your Destination)</b><br/>";
				//echo "The distance between the junction is ". $distanceJn ."<br/>";
			}
			else
			{
				if(strcmp(getNormalizedStopName($secondJnName),$endStop)==0)
				{
					echo "You need to walk from  "."<b>".getNormalizedStopName($firstJnName)."</b>" ." which is ".$distanceJn. "KM from ". "<b>".$endStop."</b><br/>";
				

				}
				else
				{
				echo "You need to walk to  "."<b>".getNormalizedStopName($secondJnName)."</b>" ." which is ".$distanceJn. "KM from ". "<b>".$firstJnName."</b><br/>";
				echo "Now from ". "<b>".getNormalizedStopName($secondJnName)."</b>"."take one of the". getCommonBusesForNormalizedStopName($secondJnName,$arrSecondBuses)." buses to go to ". "<b>".$endStop. "(Your Destination)</b><br/>";
				}
			}
			
			echo "The approximate route distance="."<b>".$SortedJunctionsDataArray[$i]->getDistance()."KM</b>";
			echo "<hr/>";
			
			
		}

	}
}