예제 #1
0
def getMaximumPrice(datas):
    """
    Given the dataset, return the maximum price in the dataset
    :param datas: input dataset(in QLearning and Neural Nets, it should have same departure date)
    :return: maximum price in the dataset
    """
    maximumPrice = util.getPrice(datas[0]["MinimumPrice"]) # in our json data files, MinimumPrice means the price in that day
    for data in datas:
        price = util.getPrice(data["MinimumPrice"])
        maximumPrice = price if price>maximumPrice else maximumPrice

    return maximumPrice
예제 #2
0
def getMaximumPrice(datas):
    """
    Given the dataset, return the maximum price in the dataset
    :param datas: input dataset(in QLearning and Neural Nets, it should have same departure date)
    :return: maximum price in the dataset
    """
    maximumPrice = util.getPrice(
        datas[0]["MinimumPrice"]
    )  # in our json data files, MinimumPrice means the price in that day
    for data in datas:
        price = util.getPrice(data["MinimumPrice"])
        maximumPrice = price if price > maximumPrice else maximumPrice

    return maximumPrice
예제 #3
0
def locationNamegetPrice():
    global uuid
    global categoryDescription
    global priceC
    global priceA
    global priceS
    global priceO
    resp = {}
    global loc_prop
    if "Get Fare" in loc_prop:
        loc_prop.remove("Get Fare")
    ticketed = util.getTicketed(cat_description[categoryDescription], uuid)
    if not ticketed:
        sug = response.suggesstions(loc_prop[:7])
        resp = response.responseSuggestions(
            f"Entry to {loc_dict[loc_dict['uuid']==uuid]['name'].iloc[0]} is free",
            sug)
    else:
        if util.getPrice(cat_description[categoryDescription], uuid):
            [priceC, priceA, priceS,
             priceO] = util.getPrice(cat_description[categoryDescription],
                                     uuid)
            if priceC != '':
                print(util.getPrice(cat_description[categoryDescription],
                                    uuid))
                if priceC.replace(".", "").isdigit():
                    priceC = float(priceC)
                    if priceA == '':
                        priceA = priceC
                    priceA = float(priceA)
                    sug = response.suggesstions(["Yes", "No"])
                    resp = response.responseSuggestions(
                        f"Would you like to share details about number of travellers with you?",
                        sug)
                else:
                    sug = response.suggesstions(loc_prop[:7])
                    resp = response.responseSuggestions(f"{priceC}", sug)
            else:
                sug = response.suggesstions(loc_prop[:7])
                resp = response.responseSuggestions(
                    f"Admission rates of {loc_dict[loc_dict['uuid']==uuid]['name'].iloc[0]} has recently changed.Details for the same can be checked by their management",
                    sug)

        else:
            sug = response.suggesstions(loc_prop[:7])
            resp = response.responseSuggestions(
                f"Entry to {loc_dict[loc_dict['uuid']==uuid]['name'].iloc[0]} is free",
                sug)
    print(resp)
    return resp
예제 #4
0
def getOptimalState(datas):
    """
    Given the dataset, return the state correspongding to minimum price in the dataset
    :param datas: input dataset(in QLearning and Neural Nets, it should have same departure date)
    :return: minimum price state in the dataset
    """
    optimalState = 0
    minimumPrice = util.getPrice(datas[0]["MinimumPrice"]) # in our json data files, MinimumPrice means the price in that day
    for data in datas:
        price = util.getPrice(data["MinimumPrice"])
        state = data["State"]
        optimalState = state if price<minimumPrice else optimalState
        minimumPrice = price if price<minimumPrice else minimumPrice

    return optimalState
예제 #5
0
def getOptimalState(datas):
    """
    Given the dataset, return the state correspongding to minimum price in the dataset
    :param datas: input dataset(in QLearning and Neural Nets, it should have same departure date)
    :return: minimum price state in the dataset
    """
    optimalState = 0
    minimumPrice = util.getPrice(
        datas[0]["MinimumPrice"]
    )  # in our json data files, MinimumPrice means the price in that day
    for data in datas:
        price = util.getPrice(data["MinimumPrice"])
        state = data["State"]
        optimalState = state if price < minimumPrice else optimalState
        minimumPrice = price if price < minimumPrice else minimumPrice

    return optimalState
예제 #6
0
def getMaximumPreviousPrice(departureDate, state, datas):
    """
    Get the maximum previous price, corresponding to the departure date and the observed date
    :param departureDate: departure date
    :param state: observed date
    :param datas: datasets
    :return: maximum previous price
    """
    specificDatas = []
    specificDatas = [data for data in datas if data["Date"]==departureDate]

    maximumPreviousPrice = util.getPrice(specificDatas[0]["MinimumPrice"])
    for data in specificDatas:
        if util.getPrice(data["MinimumPrice"]) > maximumPreviousPrice and data["State"]>=state:
            maximumPreviousPrice = util.getPrice(data["MinimumPrice"])

    return maximumPreviousPrice
예제 #7
0
def getMaximumPreviousPrice(departureDate, state, datas):
    """
    Get the maximum previous price, corresponding to the departure date and the observed date
    :param departureDate: departure date
    :param state: observed date
    :param datas: datasets
    :return: maximum previous price
    """
    specificDatas = []
    specificDatas = [data for data in datas if data["Date"] == departureDate]

    maximumPreviousPrice = util.getPrice(specificDatas[0]["MinimumPrice"])
    for data in specificDatas:
        if util.getPrice(data["MinimumPrice"]
                         ) > maximumPreviousPrice and data["State"] >= state:
            maximumPreviousPrice = util.getPrice(data["MinimumPrice"])

    return maximumPreviousPrice
예제 #8
0
def getChosenPrice(state, datas):
    """
    Given the state, i.e. the days before departure, and the dataset, return the price
    :param state: the days before departure
    :param datas: input dataset(in QLearning, it should have same departure date)
    :return: the chosen price
    """
    for data in datas:
        if data["State"] == state:
            return util.getPrice(data["MinimumPrice"])
예제 #9
0
def getChosenPrice(state, datas):
    """
    Given the state, i.e. the days before departure, and the dataset, return the price
    :param state: the days before departure
    :param datas: input dataset(in QLearning, it should have same departure date)
    :return: the chosen price
    """
    for data in datas:
        if data["State"] == state:
            return util.getPrice(data["MinimumPrice"])
예제 #10
0
def getPrice():
    total_sqft = float(request.form['total_sqft'])
    location = request.form['location']
    bhk = int(request.form['bhk'])
    bath = int(request.form['bath'])

    response = jsonify({
        'estimated_price': util.getPrice(location, total_sqft, bhk, bath)
    })
    response.headers.add('Access-Control-Allow-Origin', '*')
    return response
예제 #11
0
def load_for_classification_for_General(dataset="General",
                                        routes=routes_general):
    """
    Load the data for classification
    :param dataset: dataset name('Specific' or 'General')
    :return: X_train, y_train, X_test, y_test
    """
    isOneOptimalState = False
    # Construct the input data
    dim = routes.__len__() + 4
    X_train = np.empty(shape=(0, dim))
    y_train = np.empty(shape=(0, 1))
    y_train_price = np.empty(shape=(0, 1))

    for filePrefix in routes:
        print filePrefix
        datas = load_data_with_prefix_and_dataset(filePrefix, dataset)
        for data in datas:
            print "Construct route {}, State {}, departureDate {}...".format(
                filePrefix, data["State"], data["Date"])
            x_i = []
            # feature 1: flight number -> dummy variables
            for i in range(len(routes)):
                """
                !!!need to change!
                """
                if i == routes.index(filePrefix):
                    x_i.append(1)
                else:
                    x_i.append(0)

            # feature 2: departure date interval from "20151109", because the first observed date is 20151109
            departureDate = data["Date"]
            """
            !!!maybe need to change the first observed date
            """
            departureDateGap = util.days_between(departureDate, "20151109")
            x_i.append(departureDateGap)

            # feature 3: observed days before departure date
            state = data["State"]
            x_i.append(state)

            # feature 4: minimum price before the observed date
            minimumPreviousPrice = getMinimumPreviousPrice(
                data["Date"], state, datas)
            x_i.append(minimumPreviousPrice)

            # feature 5: maximum price before the observed date
            maximumPreviousPrice = getMaximumPreviousPrice(
                data["Date"], state, datas)
            x_i.append(maximumPreviousPrice)

            # output
            y_i = [0]
            specificDatas = []
            specificDatas = [
                data2 for data2 in datas if data2["Date"] == departureDate
            ]

            minPrice = getMinimumPrice(specificDatas)
            if util.getPrice(data["MinimumPrice"]) == minPrice:
                y_i = [1]

            # keep price info
            y_price = [util.getPrice(data["MinimumPrice"])]

            X_train = np.concatenate((X_train, [x_i]), axis=0)
            y_train = np.concatenate((y_train, [y_i]), axis=0)
            y_train_price = np.concatenate((y_train_price, [y_price]), axis=0)

        # end of for datas
    # end of for routes
    """
    remove duplicate rows
    """
    tmp = np.concatenate((X_train, y_train, y_train_price), axis=1)
    new_array = [tuple(row) for row in tmp]
    tmp = np.unique(new_array)

    # # get the result
    # X_train = tmp[:, 0:16]
    # y_train = tmp[:, 16]
    # y_train_price = tmp[:, 17]

    # save the result
    np.save('inputGeneralRaw/X_train', X_train)
    np.save('inputGeneralRaw/y_train', y_train)
    np.save('inputGeneralRaw/y_train_price', y_train_price)
    np.save('inputGeneralRaw/tmp', tmp)

    return X_train, y_train, y_train_price
예제 #12
0
def load_for_classification_for_Specific(dataset="Specific",
                                         routes=routes_specific):
    """
    Load the data for classification
    :param dataset: dataset name('Specific' or 'General')
    :return: X_train, y_train, X_test, y_test
    """
    isOneOptimalState = False
    # Construct the input data
    dim = routes.__len__() + 4
    X_train = np.empty(shape=(0, dim))
    y_train = np.empty(shape=(0, 1))
    y_train_price = np.empty(shape=(0, 1))
    X_test = np.empty(shape=(0, dim))
    y_test = np.empty(shape=(0, 1))
    y_test_price = np.empty(shape=(0, 1))

    for filePrefix in routes:
        datas = load_data_with_prefix_and_dataset(filePrefix, dataset)
        for data in datas:
            print "Construct route {}, State {}, departureDate {}...".format(
                filePrefix, data["State"], data["Date"])
            x_i = []
            # feature 1: flight number -> dummy variables
            for i in range(len(routes)):
                """
                !!!need to change!
                """
                if i == routes.index(filePrefix):
                    x_i.append(1)
                else:
                    x_i.append(0)

            # feature 2: departure date interval from "20151109", because the first observed date is 20151109
            departureDate = data["Date"]
            """
            !!!maybe need to change the first observed date
            """
            departureDateGap = util.days_between(departureDate, "20151109")
            x_i.append(departureDateGap)

            # feature 3: observed days before departure date
            state = data["State"]
            x_i.append(state)

            # feature 4: minimum price before the observed date
            minimumPreviousPrice = getMinimumPreviousPrice(
                data["Date"], state, datas)
            x_i.append(minimumPreviousPrice)

            # feature 5: maximum price before the observed date
            maximumPreviousPrice = getMaximumPreviousPrice(
                data["Date"], state, datas)
            x_i.append(maximumPreviousPrice)

            # output
            y_i = [0]
            specificDatas = []
            specificDatas = [
                data2 for data2 in datas if data2["Date"] == departureDate
            ]

            # if isOneOptimalState:
            #     # Method 1: only 1 entry is buy
            #     optimalState = getOptimalState(specificDatas)
            #     if data["State"] == optimalState:
            #        y_i = [1]
            # else:
            #     # Method 2: multiple entries can be buy
            #     minPrice = getMinimumPrice(specificDatas)
            #     if util.getPrice(data["MinimumPrice"]) == minPrice:
            #         y_i = [1]

            #Method 2: multiple entries can be buy
            minPrice = getMinimumPrice(specificDatas)
            if util.getPrice(data["MinimumPrice"]) == minPrice:
                y_i = [1]

            # keep price info
            y_price = [util.getPrice(data["MinimumPrice"])]

            if int(departureDate) < 20160229 and int(
                    departureDate
            ) >= 20151129:  # choose date between "20151129-20160229(20160115)" as training data
                X_train = np.concatenate((X_train, [x_i]), axis=0)
                y_train = np.concatenate((y_train, [y_i]), axis=0)
                y_train_price = np.concatenate((y_train_price, [y_price]),
                                               axis=0)
            elif int(departureDate) < 20160508 and int(
                    departureDate
            ) >= 20160229:  # choose date before "20160508(20160220)" as test data
                X_test = np.concatenate((X_test, [x_i]), axis=0)
                y_test = np.concatenate((y_test, [y_i]), axis=0)
                y_test_price = np.concatenate((y_test_price, [y_price]),
                                              axis=0)
            else:
                pass

            # X_train = np.concatenate((X_train, [x_i]), axis=0)
            # y_train = np.concatenate((y_train, [y_i]), axis=0)
            # y_train_price = np.concatenate((y_train_price, [y_price]), axis=0)

        # end of for datas
    # end of for routes
    """
    remove duplicate rows for train
    """
    tmp_train = np.concatenate((X_train, y_train, y_train_price), axis=1)
    new_array = [tuple(row) for row in tmp_train]
    tmp_train = np.unique(new_array)

    # get the result
    X_train = tmp_train[:, 0:12]
    y_train = tmp_train[:, 12]
    y_train_price = tmp_train[:, 13]
    """
    remove duplicate rows for test
    """
    tmp_test = np.concatenate((X_test, y_test, y_test_price), axis=1)
    new_array = [tuple(row) for row in tmp_test]
    tmp_test = np.unique(new_array)

    # get the result
    X_test = tmp_test[:, 0:12]
    y_test = tmp_test[:, 12]
    y_test_price = tmp_test[:, 13]

    # save the result
    np.save('inputSpecificRaw/X_train', X_train)
    np.save('inputSpecificRaw/y_train', y_train)
    np.save('inputSpecificRaw/y_train_price', y_train_price)
    np.save('inputSpecificRaw/X_test', X_test)
    np.save('inputSpecificRaw/y_test', y_test)
    np.save('inputSpecificRaw/y_test_price', y_test_price)

    return X_train, y_train, X_test, y_test
예제 #13
0
def load_for_classification_for_General(dataset="General", routes=routes_general):
    """
    Load the data for classification
    :param dataset: dataset name('Specific' or 'General')
    :return: X_train, y_train, X_test, y_test
    """
    isOneOptimalState = False
    # Construct the input data
    dim = routes.__len__() + 4
    X_train = np.empty(shape=(0, dim))
    y_train = np.empty(shape=(0,1))
    y_train_price = np.empty(shape=(0,1))

    for filePrefix in routes:
        print filePrefix
        datas = load_data_with_prefix_and_dataset(filePrefix, dataset)
        for data in datas:
            print "Construct route {}, State {}, departureDate {}...".format(filePrefix, data["State"], data["Date"])
            x_i = []
            # feature 1: flight number -> dummy variables
            for i in range(len(routes)):
                """
                !!!need to change!
                """
                if i == routes.index(filePrefix):
                    x_i.append(1)
                else:
                    x_i.append(0)

            # feature 2: departure date interval from "20151109", because the first observed date is 20151109
            departureDate = data["Date"]
            """
            !!!maybe need to change the first observed date
            """
            departureDateGap = util.days_between(departureDate, "20151109")
            x_i.append(departureDateGap)

            # feature 3: observed days before departure date
            state = data["State"]
            x_i.append(state)

            # feature 4: minimum price before the observed date
            minimumPreviousPrice = getMinimumPreviousPrice(data["Date"], state, datas)
            x_i.append(minimumPreviousPrice)

            # feature 5: maximum price before the observed date
            maximumPreviousPrice = getMaximumPreviousPrice(data["Date"], state, datas)
            x_i.append(maximumPreviousPrice)

            # output
            y_i = [0]
            specificDatas = []
            specificDatas = [data2 for data2 in datas if data2["Date"]==departureDate]

            minPrice = getMinimumPrice(specificDatas)
            if util.getPrice(data["MinimumPrice"]) == minPrice:
                y_i = [1]


            # keep price info
            y_price = [util.getPrice(data["MinimumPrice"])]

            X_train = np.concatenate((X_train, [x_i]), axis=0)
            y_train = np.concatenate((y_train, [y_i]), axis=0)
            y_train_price = np.concatenate((y_train_price, [y_price]), axis=0)

        # end of for datas
    # end of for routes


    """
    remove duplicate rows
    """
    tmp = np.concatenate((X_train, y_train, y_train_price), axis=1)
    new_array = [tuple(row) for row in tmp]
    tmp = np.unique(new_array)

    # # get the result
    # X_train = tmp[:, 0:16]
    # y_train = tmp[:, 16]
    # y_train_price = tmp[:, 17]

    # save the result
    np.save('inputGeneralRaw/X_train', X_train)
    np.save('inputGeneralRaw/y_train', y_train)
    np.save('inputGeneralRaw/y_train_price', y_train_price)
    np.save('inputGeneralRaw/tmp', tmp)

    return X_train, y_train, y_train_price
예제 #14
0
def load_for_classification_for_Specific(dataset="Specific", routes=routes_specific):
    """
    Load the data for classification
    :param dataset: dataset name('Specific' or 'General')
    :return: X_train, y_train, X_test, y_test
    """
    isOneOptimalState = False
    # Construct the input data
    dim = routes.__len__() + 4
    X_train = np.empty(shape=(0, dim))
    y_train = np.empty(shape=(0,1))
    y_train_price = np.empty(shape=(0,1))
    X_test = np.empty(shape=(0,dim))
    y_test = np.empty(shape=(0,1))
    y_test_price = np.empty(shape=(0,1))

    for filePrefix in routes:
        datas = load_data_with_prefix_and_dataset(filePrefix, dataset)
        for data in datas:
            print "Construct route {}, State {}, departureDate {}...".format(filePrefix, data["State"], data["Date"])
            x_i = []
            # feature 1: flight number -> dummy variables
            for i in range(len(routes)):
                """
                !!!need to change!
                """
                if i == routes.index(filePrefix):
                    x_i.append(1)
                else:
                    x_i.append(0)

            # feature 2: departure date interval from "20151109", because the first observed date is 20151109
            departureDate = data["Date"]
            """
            !!!maybe need to change the first observed date
            """
            departureDateGap = util.days_between(departureDate, "20151109")
            x_i.append(departureDateGap)

            # feature 3: observed days before departure date
            state = data["State"]
            x_i.append(state)

            # feature 4: minimum price before the observed date
            minimumPreviousPrice = getMinimumPreviousPrice(data["Date"], state, datas)
            x_i.append(minimumPreviousPrice)

            # feature 5: maximum price before the observed date
            maximumPreviousPrice = getMaximumPreviousPrice(data["Date"], state, datas)
            x_i.append(maximumPreviousPrice)

            # output
            y_i = [0]
            specificDatas = []
            specificDatas = [data2 for data2 in datas if data2["Date"]==departureDate]

            # if isOneOptimalState:
            #     # Method 1: only 1 entry is buy
            #     optimalState = getOptimalState(specificDatas)
            #     if data["State"] == optimalState:
            #        y_i = [1]
            # else:
            #     # Method 2: multiple entries can be buy
            #     minPrice = getMinimumPrice(specificDatas)
            #     if util.getPrice(data["MinimumPrice"]) == minPrice:
            #         y_i = [1]

            #Method 2: multiple entries can be buy
            minPrice = getMinimumPrice(specificDatas)
            if util.getPrice(data["MinimumPrice"]) == minPrice:
                y_i = [1]


            # keep price info
            y_price = [util.getPrice(data["MinimumPrice"])]

            if int(departureDate) < 20160229 and int(departureDate) >= 20151129: # choose date between "20151129-20160229(20160115)" as training data
                X_train = np.concatenate((X_train, [x_i]), axis=0)
                y_train = np.concatenate((y_train, [y_i]), axis=0)
                y_train_price = np.concatenate((y_train_price, [y_price]), axis=0)
            elif int(departureDate) < 20160508 and int(departureDate) >= 20160229: # choose date before "20160508(20160220)" as test data
                X_test = np.concatenate((X_test, [x_i]), axis=0)
                y_test = np.concatenate((y_test, [y_i]), axis=0)
                y_test_price = np.concatenate((y_test_price, [y_price]), axis=0)
            else:
                pass

            # X_train = np.concatenate((X_train, [x_i]), axis=0)
            # y_train = np.concatenate((y_train, [y_i]), axis=0)
            # y_train_price = np.concatenate((y_train_price, [y_price]), axis=0)

        # end of for datas
    # end of for routes


    """
    remove duplicate rows for train
    """
    tmp_train = np.concatenate((X_train, y_train, y_train_price), axis=1)
    new_array = [tuple(row) for row in tmp_train]
    tmp_train = np.unique(new_array)

    # get the result
    X_train = tmp_train[:, 0:12]
    y_train = tmp_train[:, 12]
    y_train_price = tmp_train[:, 13]

    """
    remove duplicate rows for test
    """
    tmp_test = np.concatenate((X_test, y_test, y_test_price), axis=1)
    new_array = [tuple(row) for row in tmp_test]
    tmp_test = np.unique(new_array)

    # get the result
    X_test = tmp_test[:, 0:12]
    y_test = tmp_test[:, 12]
    y_test_price = tmp_test[:, 13]

    # save the result
    np.save('inputSpecificRaw/X_train', X_train)
    np.save('inputSpecificRaw/y_train', y_train)
    np.save('inputSpecificRaw/y_train_price', y_train_price)
    np.save('inputSpecificRaw/X_test', X_test)
    np.save('inputSpecificRaw/y_test', y_test)
    np.save('inputSpecificRaw/y_test_price', y_test_price)

    return X_train, y_train, X_test, y_test