示例#1
0
def get_match_data(match_id):
    try:
        navbar_status = ["","","active"]
        from match_extraction import popflash_scraper as ps
        match = ps.get_match_data(match_id)
        return render_template("tenman/match_page.html",match=match,navbar_status=navbar_status)
    except Exception as e:
        return str(e)
示例#2
0
def get_match_data(match_id):
    try:
        from match_extraction import popflash_scraper as ps
        from database_management import db_interaction as dbi
        from match_extraction.Match import Match
        from match_extraction.Team import Team
        from match_extraction.Player import Player

        navbar_status = [""] * NUM_TABS
        navbar_status[2] = "active"
        match = ps.get_match_data(match_id)

        # Get team balance ratings
        team1 = match.get_team_1()
        team2 = match.get_team_2()

        team1_total = 0
        team2_total = 0

        his_avg_team_1 = Team()
        his_avg_team_2 = Team()

        for player in team1:
            p1 = dbi.get_player_data(int(player.get_pop_id()))
            team1_total += p1.get_hltv_rating()
            his_avg_team_1.add_player(p1)

        for player in team2:
            p2 = dbi.get_player_data(int(player.get_pop_id()))
            team2_total += p2.get_hltv_rating()
            his_avg_team_2.add_player(p2)

        team1_avg_rating = float(team1_total) / 5.0
        team2_avg_rating = float(team2_total) / 5.0

        team1_percentage = 100 * (team1_avg_rating /
                                  (team1_avg_rating + team2_avg_rating))
        team2_percentage = 100 * (team2_avg_rating /
                                  (team1_avg_rating + team2_avg_rating))

        return render_template("tenman/match_page.html",
                               match=match,
                               navbar_status=navbar_status,
                               team1_avg_rating=team1_avg_rating,
                               team2_avg_rating=team2_avg_rating,
                               team1_percentage=team1_percentage,
                               team2_percentage=team2_percentage,
                               his_avg_team_1=his_avg_team_1,
                               his_avg_team_2=his_avg_team_2)
    except Exception as e:
        return handle_error(e)
示例#3
0
def update_matches(startmatch=0):
    conn = dbi.get_database_connection()
    matches = dbi.get_table_data(conn, "matches")
    count = 0
    for row in matches:
        if count < startmatch:
            count += 1
            continue
        match_id = int(row[0])
        print("Getting data for match", match_id)
        m = ps.get_match_data(match_id)
        print("Updating data for match", match_id)
        dbi.update_match_data(m)

    print("Done!")
示例#4
0
def add_match_after_flag(match_id):
    from database_management import db_interaction as dbi
    from match_extraction import popflash_scraper as ps
    conn = dbi.get_database_connection()

    # To protect against users entering url not from add match page
    if not dbi.exists_in_table(conn, "matches", int(match_id)):
        pop_match = ps.get_match_data(match_id)
        dbi.add_match_data(conn, pop_match)

        if not pop_match.is_tie():
            dbi.update_season_player_data(conn, pop_match)

        flash_str = "Successfully added match " + str(
            match_id) + " and updated player data."
        flash(flash_str)
        conn.close()
        dbi.relase_database_flag()
        return redirect("/tenman")
示例#5
0
def add_pop_match():
    try:
        if request.method == "GET":
            return "Dissallowed, GET"
        elif request.method == "POST":
            
            try:
                from database_management import db_interaction as dbi
            except Exception as e:
                return "db_interaction Import failed: " +  str(e)
            
            try:
                from match_extraction import popflash_scraper as ps
            except Exception as e:
                return "ps Import failed: " +  str(e)           
            
            try:
                
                pop_id = request.form["pop_id"]
                conn = dbi.get_database_connection()
                if dbi.exists_in_table(conn,"matches",int(pop_id)):
                    flash_str = "Match " + str(pop_id) + " has already been added to the database! Player data has not been updated."
                    flash(flash_str) 
                    return redirect("/tenman")        
                else:
                    pop_match = ps.get_match_data(pop_id)            
                    dbi.add_match_data(conn,pop_match)

                    flash_str = "Successfully added match " + str(pop_id) + " and updated player data."
                    flash(flash_str)                   
                    return redirect("/tenman")                
                
            except Exception as e:
                return str(e)
            
            
    except Exception as e:
        return str(e)
示例#6
0
from database_management import db_interaction as dbi
from match_extraction.Match import Match
from match_extraction import popflash_scraper as ps


def update_matches(startmatch=0):
    conn = dbi.get_database_connection()
    matches = dbi.get_table_data(conn, "matches")
    count = 0
    for row in matches:
        if count < startmatch:
            count += 1
            continue
        match_id = int(row[0])
        print("Getting data for match", match_id)
        m = ps.get_match_data(match_id)
        print("Updating data for match", match_id)
        dbi.update_match_data(m)

    print("Done!")


# Remove weekday from match date column
def update_match_dates():
    pass


if __name__ == "__main__":
    #update_matches()
    m = ps.get_match_data(1125941)
    dbi.update_match_data(m)