def removeCity(cityName):
    #Check if the city is in the city dictionary
    if cityName in QueryingData.cityDicationary:
        
        cityCode = UserQuerying.nameToCode(cityName)
        continentInfo = QueryingData.cityDicationary[cityName].continent
        #Remove from the cityDicationary
        del QueryingData.cityDicationary[cityName]
        #Remove the city from the take off port
        for route in QueryingData.routeList:
            if route.takeoffPortCode == cityCode:
                UserQuerying.minusHubCity(cityCode)
                QueryingData.routeList.remove(route)
                
        #Remove the city from the land port
        for route in QueryingData.routeList:
            if route.landPortCode == cityCode:
                UserQuerying.minusHubCity(route.takeoffPortCode)
                QueryingData.routeList.remove(route)
                
        
        
        
    else:
        print 'Cannot find ' + cityName 
def removeRoute():
    '''
    This function will remove a particular route,
    And update all the relevant data
    '''
    sourcePortName = raw_input("Please enter the source port you want to remove: \n")
    destPortName = raw_input("Please enter the destination port you want to remove: \n")
    sourcePortCode = UserQuerying.nameToCode(sourcePortName)
    destPortCode = UserQuerying.nameToCode(destPortName)
    
    for route in QueryingData.routeList:        #Remove source to destination
        if route.takeOffPortCode == sourcePortCode and route.landPortCode == destPortCode:
            QueryingData.routeList.remove(route)
            UserQuerying.minusHubCity(sourcePortCode)
            break
    for route in QueryingData.routeList:        #Remove destination to source
        if route.takeOffPortCode == destPortCode and route.landPortCode == sourcePortCode:
            QueryingData.routeList.remove(route)
            UserQuerying.minusHubCity(destPortCode)
            break
def addRoute():
    '''
    This function will add a new route between two existing cities
    And update all the relevant data
    '''
    sourcePortName = raw_input("Please enter the source port name: \n")
    destPortName = raw_input("Please enter the destination port name: \n")
    
    while True:
        distance = raw_input("Please enter the distance: \n")   #Check if the input is valid
        if int(distance) > 0:
            break
    
    sourcePortCode = UserQuerying.nameToCode(sourcePortName)
    destPortCode = UserQuerying.nameToCode(destPortName)
    
    newSourceToDestination = RouteInfo.RouteInfo(sourcePortCode, destPortCode, int(distance))
    newDestinationToSource = RouteInfo.RouteInfo(destPortCode, sourcePortCode, int(distance))
    
    QueryingData.routeList.append(newSourceToDestination)       #Append source to destination to route list
    QueryingData.routeList.append(newDestinationToSource)       #Append destination to source to route list
        
    UserQuerying.addHubCity(sourcePortCode)     #update hub city data
    UserQuerying.addHubCity(destPortCode)       #update hub city data
Beispiel #4
0
def calculateTime(cityList):
    flyingTime = 0.0
    layoverTime = 0.0
    acceleration = 750.0*750/(2*200)
    counter = len(cityList)
    i = 0
    while counter > 1:
        nextCity = cityList[i+1]
        flyToCityDic = UserQuerying.getFlyToCity(cityList[i])
        distanceToNextCity = flyToCityDic[nextCity]
        # calculate the flying time
        if distanceToNextCity >= 400:
            accTime = 200.0*2/750
            decTime = accTime
            cruisingTime = (distanceToNextCity - 400.0)/750
            flyingTime = flyingTime + accTime + decTime + cruisingTime
        else:
            accTime = math.sqrt(2*distanceToNextCity/acceleration)
            flyingTime = flyingTime + 2*accTime
        # calculate the layover time
        if i != 0:
            cityCode = UserQuerying.nameToCode(cityList[i])
            hubNumber = QueryingData.hubCity[cityCode]
            waitingTime = (120.0 - hubNumber*10)/60 
            layoverTime = layoverTime + waitingTime
        counter -= 1
        i += 1
      
    return (flyingTime + layoverTime)
            
            
    
    
    
    
    
    
    
    
def removeCity():
    '''
    This function will remove a city from existing cities,
    and update all the relevant data
    '''
    cityName = raw_input("Please enter the city you want to remove: \n")
    
    if cityName in QueryingData.cityDicationary:    #Check if the input city is valid or not
        
        cityCode = UserQuerying.nameToCode(cityName)
        del QueryingData.continent[cityName]        #Remove the city from the continent  
        del QueryingData.cityDicationary[cityName]  #Remove from the cityDicationary
    
        #Remove relevant routes including the remove city   
        deleteRoute = [route for route in QueryingData.routeList if route.takeOffPortCode == cityCode]
        QueryingData.routeList[:] = [route for route in QueryingData.routeList if route.landPortCode != cityCode and route.takeOffPortCode != cityCode]
        for route in deleteRoute:
            UserQuerying.minusHubCity(route.takeOffPortCode)
            UserQuerying.minusHubCity(route.landPortCode)
                   
    else:                       
        print 'Cannot find ' + cityName             #Invalid input