示例#1
0
def show_game_board():
    """[When a non-post request is recieved on this page, it will just render the play-game template
          which will show the game board. If post request is sent (i.e. submit words button) the server
          will grab the json data that is sent from the javascript axios post request and respond with a 
          python dictionary of data]
    """
    if request.method == "POST":
        session["score"] = ''
        data = request.get_json()
        print(data)
        session["plays"] += 1
        session["missing-dict"] = functions.not_in_dictionary(data)
        session["missing-board"] = functions.not_on_board(data)
        session["on-board"] = functions.compare_to_board(
            functions.compare_to_dictionary(data))
        session["score"] = functions.calculate_score(
            functions.compare_to_board(functions.compare_to_dictionary(data)))
        #this next function determines top score
        functions.determine_top_score(session["score"])
        jsonObj = {
            "game_board": session.get("board"),
            "missing_dict": session.get("missing-dict"),
            "missing_board": session.get("missing-board"),
            "on_board": session.get("on-board"),
            "score": session.get("score")
        }
        return jsonObj
    #The below code stops a user from jumping straight to /play page
    # without first getting to the landing page and creating a board
    else:
        if session.get("board"):
            board = session.get('board')
            return render_template("play-game.html", board=board)
        else:
            return redirect("/")
示例#2
0
    def test_calculate_score(self):
        """[Tests the calculate_score function in functions.py]
        """

        test_list = ["word", "self", "has"]

        self.assertEqual(functions.calculate_score(test_list), 11)
def test_bballbot():
    assert callable(remove_star)
    assert remove_star('Golden State Warriors') == 'Golden State Warriors'
    assert remove_star('Golden State Warriors*') == 'Golden State Warriors'

    assert callable(standardize_team)
    assert standardize_team('the chicago bulls') == 'Chicago Bulls'
    assert standardize_team('CHICAGO BULLS') == 'Chicago Bulls'

    assert callable(year_input)
    a, b = year_input('2018')
    assert a == '2018'
    assert isinstance(b, pd.DataFrame)

    assert callable(team_input)
    c, d = team_input(a, b, 'Golden State Warriors')
    assert c == 'Golden State Warriors'
    assert isinstance(d, pd.DataFrame)

    assert callable(check_teams)
    a1, b1 = year_input('2017')
    c1, d1 = team_input(a1, b1, 'Chicago Bulls')
    assert check_teams(a, a, c, c) == True
    assert check_teams(a, a1, c, c1) == False

    assert callable(append_and_drop)
    e = append_and_drop(c, d, c1, d1)
    assert isinstance(e, pd.DataFrame)

    assert callable(calculate_score)
    f = calculate_score(e, c, c1)
    assert isinstance(f, int)

    assert callable(check_calculate_score)
    g = check_calculate_score(e, c, a, c1, a1)
    assert isinstance(g, int)

    assert callable(calculate_prediction)
    h = calculate_prediction(g, c, a, c1, a1)
    assert isinstance(h, str)
示例#4
0
def main():
    # read the file with elements, strip unnecessary pieces of strings, close the file
    file = open("elements.txt", "r")
    element_list = file.readlines()

    for index in range(len(element_list)):
        element_list[index] = element_list[index].strip("\n").lower()

    file.close()

    print("Greetings! It is time to check your knowledge of ATOMIC ELEMENTS.")
    print(
        "Enter any 5 of the first 20 atomic elements from Period Table and I will give you a grade."
    )

    user_input = input("Are you ready (y/n)?\n")

    if user_input.lower() == "y" or user_input.lower() == "yes":
        # get user input collected in a list
        answer_list = get_names()

        # distribute correct and incorrect answers in 2 separate lists
        correct_answers = []
        incorrect_answers = []

        for answer in answer_list:
            if answer in element_list:
                correct_answers.append(answer)
            else:
                incorrect_answers.append(answer)

        # calculate points
        points = calculate_score(correct_answers)

        # print results
        print_results(points, correct_answers, incorrect_answers)
    else:
        print("Sorry to see you go :(")
示例#5
0
#print the instructions for a user
print("Greetings! It is time to check your knowledge about ATOMIC ELEMENTS.")
print(
    "Enter any 5 of the first 20 atomic elements from Period Table and I will give you a grade."
)

user_input = input("Are you ready (y/n)?\n")
print("******************************************************************")

if user_input.lower() == "y" or user_input.lower() == "yes":
    # get user input collected in a list
    answer_list = get_names()

    # distribute correct and incorrect answers in 2 separate lists
    correct_answers = []
    incorrect_answers = []

    for answer in answer_list:
        if answer in element_list:
            correct_answers.append(answer)
        else:
            incorrect_answers.append(answer)

    # calculate points
    points = calculate_score(correct_answers)

    # print results
    print_results(points, correct_answers, incorrect_answers)
else:
    print("Sorry to see you go :(")
示例#6
0
 def calc_individuals_score(self):
     for individual in self.individuals:
         individual['score'] = calculate_score(
             get_route_from_individual(individual)
         )
示例#7
0
def result():
    if request.method == "GET":
        # GET으로 받은 정보들을 딕셔너리에 담음. 그리고 먼저 필수 정보들을 수집하면서 삭제함. 남은 정보들은 안 되는 시간에 대한 정보
        info = request.args.to_dict()
        required = [
            'major1', 'major2', 'homework_value', 'teamwork_value',
            'grade_value', 'numoftest_value'
        ]
        for menu in required:
            if menu not in info:
                return render_template("result_error.html")
        major1 = info['major1']
        del info['major1']
        major2 = info['major2']
        del info['major2']
        homework = info['homework_value']
        del info['homework_value']
        teamwork = info['teamwork_value']
        del info['teamwork_value']
        grade = info['grade_value']
        del info['grade_value']
        numoftest = info['numoftest_value']
        del info['numoftest_value']
        if 'emptylecture_value' in info:
            empty = True
            del info['emptylecture_value']
        else:
            empty = False
        time = []
        index = 0
        while info:
            index += 1
            day = "timeban-day" + str(index)
            start = "timeban-start" + str(index)
            end = "timeban-end" + str(index)
            tmp_list = []
            if day in info:
                tmp_list.append(info[day])
                del info[day]
            if start in info:
                tmp_list.append(info[start])
                del info[start]
            if end in info:
                tmp_list.append(info[end])
                del info[end]
            if len(tmp_list) == 3:
                check_time = [
                    tuple(map(int, tmp_list[1].split(":"))),
                    tuple(map(int, tmp_list[2].split(":")))
                ]
                if (check_time[1][0] - check_time[0][0]) * 60 + (
                        check_time[1][1] - check_time[0][1]) > 0:
                    time.append((tmp_list[0] + " " + tmp_list[1],
                                 tmp_list[0] + " " + tmp_list[2]))
        pandas_result, new_result = functions.calculate_score(
            major1, major2, homework, teamwork, grade, numoftest, empty, time)
        if new_result is None:
            new_result = pd.DataFrame()
        length = len(pandas_result)
        new_length = len(new_result)
        return render_template("result.html",
                               df=pandas_result,
                               new_df=new_result,
                               length=length,
                               new_length=new_length)
示例#8
0
#       It is ok to have an offline algorithm

from functions import load_json, calculate_score, get_related_products

PRODUCT_FILE = "products.txt"
LISTING_FILE = "listings.txt"
THRESHOLD = 0

listings = load_json(LISTING_FILE)
products = load_json(PRODUCT_FILE)

matches = {}

for listing in listings:
    related_products = get_related_products(listing, products)
    potential_matches = [];
    for product in related_products:
        score = calculate_score(listing, product)
        potential_matches.append({"score": score, "product": product})
    if potential_matches:
        best_match = max(potential_matches, key=lambda x: x["score"])
        if best_match["score"] >= THRESHOLD:
            product_name = best_match["product"]["product_name"];
            matches.setdefault(product_name, {}).setdefault("listings", []).append(listing)

#correctly format matches
#results_file = open("result.txt", "w+")
#for key, value in matches.iteritems():
#    results_file.write()
print(matches)