def parseCities(data): ''' This function will parse all the cities' information from provided Json file And add parsed city information into city dictionary Also update continent dictionary ''' for city in data["metros"]: portCity = CityInfo.CityInfo(city["code"], city["name"], city["country"], city["continent"], city["timezone"], city["coordinates"], city["population"], city["region"]) QueryingData.cityDicationary[city["name"]] = portCity #add city to city dictionary QueryingData.codeToName[city["code"]] = city["name"] UserQuerying.cityToContinent(city["name"], city["continent"]) #classic cities based on continent
def parseRoutes(data): for route in data["routes"]: sourceToDestination = RouteInfo.RouteInfo(route["ports"][0], route["ports"][1], route["distance"]) destinationToSource = RouteInfo.RouteInfo(route["ports"][1], route["ports"][0], route["distance"]) QueryingData.routeList.append(sourceToDestination) QueryingData.routeList.append(destinationToSource) UserQuerying.addHubCity(route["ports"][0]) UserQuerying.addHubCity(route["ports"][1])
def parseRoutes(data): ''' This function will parse all the routes' information from provided Json file And append parse routes information into route list Also update hub city dictionary ''' for route in data["routes"]: sourceToDestination = RouteInfo.RouteInfo(route["ports"][0], route["ports"][1], route["distance"]) destinationToSource = RouteInfo.RouteInfo(route["ports"][1], route["ports"][0], route["distance"]) QueryingData.routeList.append(sourceToDestination) QueryingData.routeList.append(destinationToSource) UserQuerying.addHubCity(route["ports"][0]) UserQuerying.addHubCity(route["ports"][1])
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 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 testLongestFlight(self): key = UserQuerying.longestFlight() self.assertEqual(key, 12051)
def testBiggestCity(self): key = UserQuerying.biggestCity() self.assertEqual(key, 34000000)
def testShorestFlight(self): key = UserQuerying.shortestFlight() self.assertEqual(key, 334)
import Parser import UserQuerying queryString = "1.Type 1 to get all the cities that CSAir flies to.\n2.Type 2 to get special information about a special city.\n3.Type 3 to get statical information about CSAir's route network.\n4.Type 4 to map your route.\n5.Type 5 to Exit." Parser.Parser() while True: print '-----------------------------------------------------------------------' print queryString n = raw_input("Please choose a number: \n") if n.strip() == '1': cityList = UserQuerying.getCityList() print 'Here is all cities that CSAir flies to...' for city in cityList: print city print '\n' elif n.strip() == '2': cityName = raw_input("Please type querying city name: \n") if UserQuerying.getQueryCity(cityName) == False: print 'Sorry, CSAir does not fly to ' + cityName print '\n' elif n.strip() == '3': UserQuerying.getStaticalInfomation() print '\n' elif n.strip() == '4': cityCode1 = raw_input("Please type the first city's code: \n")