Beispiel #1
0
def editnetwork():
    while(True):
        isValid = False
        cityList = QueryData.citylist()
        while(not isValid):
            print "Type a valid city to edit, or type 0 or exit to quit"
            user_city = raw_input()
            isValid = user_city in cityList
            if user_city == "exit" or user_city == "quit" or user_city == "q" or user_city == "0":
                return

        while(True):

            s = "Type the number for corresponding options:\n" \
                "1. Edit current city's code\n" \
                "2. Edit current city's country\n" \
                "3. Edit current city's continent\n" \
                "4. Edit current city's timezone\n" \
                "5. Edit current city's region\n" \
                "6. Edit current city's population\n" \
                "0. Quit"

            print s

            i = raw_input("Enter the number.")
            i = int(i)

            if i == 1:
                newcode = raw_input("Type the new code of the city.")
                editcode(user_city, newcode)

            elif i == 2:
                newcountry = raw_input("Type the new country of the city.")
                editcountry(user_city, newcountry)

            elif i == 3:
                newcont = raw_input("Type the new continent of the city.")
                editcontinent(user_city, newcont)

            elif i == 4:
                newzone = raw_input("Type the new timezone of the city.")
                edittimezone(user_city, newzone)

            elif i == 5:
                newreg = raw_input("Type the new region of the city.")
                editregion(user_city, newreg)

            elif i == 6:
                newpop = raw_input("Type the new population of the city.")
                editpop(user_city, newpop)

            elif i == 0:
                break

            else:
                print "Invalid Number!"
Beispiel #2
0
def editnetwork():
    while (True):
        isValid = False
        cityList = QueryData.citylist()
        while (not isValid):
            print "Type a valid city to edit, or type 0 or exit to quit"
            user_city = raw_input()
            isValid = user_city in cityList
            if user_city == "exit" or user_city == "quit" or user_city == "q" or user_city == "0":
                return

        while (True):

            s = "Type the number for corresponding options:\n" \
                "1. Edit current city's code\n" \
                "2. Edit current city's country\n" \
                "3. Edit current city's continent\n" \
                "4. Edit current city's timezone\n" \
                "5. Edit current city's region\n" \
                "6. Edit current city's population\n" \
                "0. Quit"

            print s

            i = raw_input("Enter the number.")
            i = int(i)

            if i == 1:
                newcode = raw_input("Type the new code of the city.")
                editcode(user_city, newcode)

            elif i == 2:
                newcountry = raw_input("Type the new country of the city.")
                editcountry(user_city, newcountry)

            elif i == 3:
                newcont = raw_input("Type the new continent of the city.")
                editcontinent(user_city, newcont)

            elif i == 4:
                newzone = raw_input("Type the new timezone of the city.")
                edittimezone(user_city, newzone)

            elif i == 5:
                newreg = raw_input("Type the new region of the city.")
                editregion(user_city, newreg)

            elif i == 6:
                newpop = raw_input("Type the new population of the city.")
                editpop(user_city, newpop)

            elif i == 0:
                break

            else:
                print "Invalid Number!"
Beispiel #3
0
def routeinfo():

    cityList = QueryData.citylist()
    isValid = False
    while not isValid:
        print "Type the first valid city of new route."
        startcity = raw_input()
        isValid = startcity in cityList
        if startcity == "exit" or startcity == "quit" or startcity == "q" or startcity == "0":
            return

    legs = []
    stops = []

    # Gather dest city
    while (True):
        isValid = False
        while not isValid:
            endcity = raw_input(
                "Type the next valid city of route, or type exit to end")
            isValid = endcity in cityList or endcity == "exit" or endcity == "q"
            if not isValid:
                print "Wrong city. Not counted."

        if endcity == "exit" or endcity == "q":
            break

        stops.append(endcity)
        startcode = QueryData.nametocode(startcity)
        endcode = QueryData.nametocode(endcity)
        for route in GraphLibrary.route_list:

            if route.startportcode == startcode and \
            route.endportcode == endcode:

                dist = route.distance
                legs.append(dist)
                stops.append(endcode)
                break

        startcity = endcity

    # after getting all the list
    print "Total Distance = " + str(totaldistance(legs)) + " km"
    print "Total Cost = $" + str(totalcost(legs))
    print "Total Time = " + str(totaltime(legs, stops)) + " hrs"
Beispiel #4
0
def routeinfo():

    cityList = QueryData.citylist()
    isValid = False
    while not isValid:
        print "Type the first valid city of new route."
        startcity = raw_input()
        isValid = startcity in cityList
        if startcity == "exit" or startcity == "quit" or startcity == "q" or startcity == "0":
            return

    legs = []
    stops = []

    # Gather dest city
    while(True):
        isValid = False
        while not isValid:
            endcity = raw_input("Type the next valid city of route, or type exit to end")
            isValid = endcity in cityList or endcity == "exit" or endcity == "q"
            if not isValid:
                print "Wrong city. Not counted."

        if endcity == "exit" or endcity == "q":
            break

        stops.append(endcity)
        startcode = QueryData.nametocode(startcity)
        endcode = QueryData.nametocode(endcity)
        for route in GraphLibrary.route_list:

            if route.startportcode == startcode and \
            route.endportcode == endcode:

                dist = route.distance
                legs.append(dist)
                stops.append(endcode)
                break

        startcity = endcity

    # after getting all the list
    print "Total Distance = " + str(totaldistance(legs)) + " km"
    print "Total Cost = $" + str(totalcost(legs))
    print "Total Time = " + str(totaltime(legs, stops)) + " hrs"
Beispiel #5
0
def shortestroute():

    start = ""
    finish = ""

    cityList = QueryData.citylist()
    isValid = False
    while not isValid:
        start = raw_input("Type a departing city or type exit to quit.")
        isValid = start in cityList
        if start == "q" or start == "exit":
            return

    isValid = False
    while not isValid:

        end = raw_input("Type an arriving city or type exit to quit.")
        isValid = start in cityList
        if start == "q" or start == "exit":
            return
Beispiel #6
0
def shortestroute():

    start = ""
    finish = ""

    cityList = QueryData.citylist()
    isValid = False
    while not isValid:
        start = raw_input("Type a departing city or type exit to quit.")
        isValid = start in cityList
        if start == "q" or start == "exit":
            return

    isValid = False
    while not isValid:

        end = raw_input("Type an arriving city or type exit to quit.")
        isValid = start in cityList
        if start == "q" or start == "exit":
            return
Beispiel #7
0
def addnetwork():

    while(True):

        cityList = QueryData.citylist()
        s = "Type the number for corresponding options:\n" \
            "1. Remove a city\n" \
            "2. Remove a route\n" \
            "3. Add a city\n" \
            "4. Add a route\n" \
            "0. Quit"

        print s

        i = raw_input("Enter the number.")
        i = int(i)

        if i == 1:

            isValid = False
            while(not isValid):
                print "Type a valid city to remove, or type 0 or exit to quit"
                user_city = raw_input()
                isValid = user_city in cityList
                if user_city == "exit" or user_city == "quit" or user_city == "q" or user_city == "0":
                    return

            removecity(user_city)

        elif i == 2:

            isValid = False
            while(not isValid):
                print "Type the first valid city of route."
                user_city = raw_input()
                isValid = user_city in cityList
                if user_city == "exit" or user_city == "quit" or user_city == "q" or user_city == "0":
                    return
            isValid = False
            while(not isValid):
                city2 = raw_input("Type the second valid city of route.")
                isValid = city2 in cityList


            removeroute(user_city, city2)

        elif i == 3:
            newcode = raw_input("Type the new code of city.")
            newname = raw_input("Type the new name of city.")
            newcountry = raw_input("Type the new country of city.")
            newcont = raw_input("Type the new continent of city.")
            newzone = raw_input("Type the new timezone of city.")
            newcoord1 = raw_input("Type the Latitude of city.")
            newcoord2 = raw_input("Type the longitude of city.")
            newpop = raw_input("Type the population of city.")
            newdist = raw_input("Type the distance of city.")
            newreg = raw_input("Type the region of city.")

            newpop = int(newpop)
            newdist = int(newdist)
            newreg = int(newreg)
            if newpop > 0 and newdist > 0 and newreg > 0:
                addcity(newcode, newname, newcountry, newcont, newzone, newcoord1, newcoord2, newpop, newreg)
            else:
                print "Invalid info on population/distance/region."

        elif i == 4:
            isValid = False
            while not isValid:
                print "Type the first valid city of new route, or type exit to quit."
                city1 = raw_input()
                isValid = city1 in cityList
                if city1 == "exit" or city1 == "quit" or city1 == "q" or city1 == "0":
                    return

            isValid = False
            while not isValid:
                city2 = raw_input("Type the second valid city of route.")
                isValid = city2 in cityList
                if city2 == "q" or city2 == "exit":
                    return


            newdist = raw_input("Type the distance of city.")
            newdist = int(newdist)
            newstart = QueryData.nametocode(city1)
            newend = QueryData.codetoname(city2)

            if newdist > 0:
                addroute(newstart, newend, newdist)
            else:
                print "Invalid distance."

        elif i == 0:
            break

        else:
            print "Invalid Number!"
Beispiel #8
0
    "5. Edit the current city's information\n" \
    "6. Add/Remove cities and routes\n" \
    "7. Save the changed list to JSON File\n" \
    "8. Calculuate the total flight\n" \
    "9. Update CSAir with new Champaign hub town\n" \
    "10. Calculate the shortest route between to cities.\n" \
    "0. Exit the program"

while True:

    print s

    i = raw_input("Enter the number.")
    i = int(i)
    if i == 1:
        cityList = QueryData.citylist()
        print "Here are the lists!"
        for city in cityList:
            print city

    elif i == 2:
        city_name = raw_input("Enter the city name.")

        valid = QueryData.getcitydata(city_name)

        if valid == False:
            print "No such city."

    elif i == 3:
        QueryData.getstat()
Beispiel #9
0
    def start(self):
        MapParser.MapParser()
        s = "Type the number for corresponding options:\n" \
            "1. Get all the cities from CSAir\n" \
            "2. Get a specific information about one city\n" \
            "3. Get all kinds of stats\n" \
            "4. Get a specific route\n" \
            "5. Edit the current city's information\n" \
            "6. Add/Remove cities and routes\n" \
            "7. Save the changed list to JSON File\n" \
            "8. Calculuate the total flight\n" \
            "9. Update CSAir with new Champaign hub town\n" \
            "10. Calculate the shortest route between to cities.\n" \
            "0. Exit the program"

        while True:

            print s

            i = raw_input("Enter the number.")
            i = int(i)
            if i == 1:
                cityList = QueryData.citylist()
                print "Here are the lists!"
                for city in cityList:
                    print city

            elif i == 2:
                city_name = raw_input("Enter the city name.")

                valid = QueryData.getcitydata(city_name)

                if valid == False :
                    print "No such city."

            elif i == 3:
                QueryData.getstat()

            elif i == 4:
                city_code = raw_input("Enter the city code.")

                valid = QueryData.getroute(city_code)

                if valid == False :
                    print "No such code."

            elif i == 5:
                EditRoute.editnetwork()

            elif i == 6:
                EditRoute.addnetwork()

            elif i == 7:
                SaveFile.saveFile()

            elif i == 8:
                RouteInfo.routeinfo()

            elif i == 9:
                MapParser.newMapParser()

            elif i == 10:
                self.routeInfo.shortestroute()

            elif i == 0:
                print "See ya!"
                break

            else:
                print "Invalid Number!"
Beispiel #10
0
def addnetwork():

    while (True):

        cityList = QueryData.citylist()
        s = "Type the number for corresponding options:\n" \
            "1. Remove a city\n" \
            "2. Remove a route\n" \
            "3. Add a city\n" \
            "4. Add a route\n" \
            "0. Quit"

        print s

        i = raw_input("Enter the number.")
        i = int(i)

        if i == 1:

            isValid = False
            while (not isValid):
                print "Type a valid city to remove, or type 0 or exit to quit"
                user_city = raw_input()
                isValid = user_city in cityList
                if user_city == "exit" or user_city == "quit" or user_city == "q" or user_city == "0":
                    return

            removecity(user_city)

        elif i == 2:

            isValid = False
            while (not isValid):
                print "Type the first valid city of route."
                user_city = raw_input()
                isValid = user_city in cityList
                if user_city == "exit" or user_city == "quit" or user_city == "q" or user_city == "0":
                    return
            isValid = False
            while (not isValid):
                city2 = raw_input("Type the second valid city of route.")
                isValid = city2 in cityList

            removeroute(user_city, city2)

        elif i == 3:
            newcode = raw_input("Type the new code of city.")
            newname = raw_input("Type the new name of city.")
            newcountry = raw_input("Type the new country of city.")
            newcont = raw_input("Type the new continent of city.")
            newzone = raw_input("Type the new timezone of city.")
            newcoord1 = raw_input("Type the Latitude of city.")
            newcoord2 = raw_input("Type the longitude of city.")
            newpop = raw_input("Type the population of city.")
            newdist = raw_input("Type the distance of city.")
            newreg = raw_input("Type the region of city.")

            newpop = int(newpop)
            newdist = int(newdist)
            newreg = int(newreg)
            if newpop > 0 and newdist > 0 and newreg > 0:
                addcity(newcode, newname, newcountry, newcont, newzone,
                        newcoord1, newcoord2, newpop, newreg)
            else:
                print "Invalid info on population/distance/region."

        elif i == 4:
            isValid = False
            while not isValid:
                print "Type the first valid city of new route, or type exit to quit."
                city1 = raw_input()
                isValid = city1 in cityList
                if city1 == "exit" or city1 == "quit" or city1 == "q" or city1 == "0":
                    return

            isValid = False
            while not isValid:
                city2 = raw_input("Type the second valid city of route.")
                isValid = city2 in cityList
                if city2 == "q" or city2 == "exit":
                    return

            newdist = raw_input("Type the distance of city.")
            newdist = int(newdist)
            newstart = QueryData.nametocode(city1)
            newend = QueryData.codetoname(city2)

            if newdist > 0:
                addroute(newstart, newend, newdist)
            else:
                print "Invalid distance."

        elif i == 0:
            break

        else:
            print "Invalid Number!"
Beispiel #11
0
    def start(self):
        MapParser.MapParser()
        s = "Type the number for corresponding options:\n" \
            "1. Get all the cities from CSAir\n" \
            "2. Get a specific information about one city\n" \
            "3. Get all kinds of stats\n" \
            "4. Get a specific route\n" \
            "5. Edit the current city's information\n" \
            "6. Add/Remove cities and routes\n" \
            "7. Save the changed list to JSON File\n" \
            "8. Calculuate the total flight\n" \
            "9. Update CSAir with new Champaign hub town\n" \
            "10. Calculate the shortest route between to cities.\n" \
            "0. Exit the program"

        while True:

            print s

            i = raw_input("Enter the number.")
            i = int(i)
            if i == 1:
                cityList = QueryData.citylist()
                print "Here are the lists!"
                for city in cityList:
                    print city

            elif i == 2:
                city_name = raw_input("Enter the city name.")

                valid = QueryData.getcitydata(city_name)

                if valid == False:
                    print "No such city."

            elif i == 3:
                QueryData.getstat()

            elif i == 4:
                city_code = raw_input("Enter the city code.")

                valid = QueryData.getroute(city_code)

                if valid == False:
                    print "No such code."

            elif i == 5:
                EditRoute.editnetwork()

            elif i == 6:
                EditRoute.addnetwork()

            elif i == 7:
                SaveFile.saveFile()

            elif i == 8:
                RouteInfo.routeinfo()

            elif i == 9:
                MapParser.newMapParser()

            elif i == 10:
                self.routeInfo.shortestroute()

            elif i == 0:
                print "See ya!"
                break

            else:
                print "Invalid Number!"
Beispiel #12
0
    "5. Edit the current city's information\n" \
    "6. Add/Remove cities and routes\n" \
    "7. Save the changed list to JSON File\n" \
    "8. Calculuate the total flight\n" \
    "9. Update CSAir with new Champaign hub town\n" \
    "10. Calculate the shortest route between to cities.\n" \
    "0. Exit the program"

while True:

    print s

    i = raw_input("Enter the number.")
    i = int(i)
    if i == 1:
        cityList = QueryData.citylist()
        print "Here are the lists!"
        for city in cityList:
            print city

    elif i == 2:
        city_name = raw_input("Enter the city name.")

        valid = QueryData.getcitydata(city_name)

        if valid == False :
            print "No such city."

    elif i == 3:
        QueryData.getstat()