import pandas as pd from FuzzySystemFunctions import * from numpy import inf, nan, nan_to_num names_to_shortcuts = { "Evil Geniuses": "EG", "TSM": "TSM", "Cloud9": "C9", "Immortals Progressive": "IMT", "100 Thieves": "100", "Dignitas": "DIG", "CLG": "CLG", "FlyQuest": "FLY", "Team Liquid Honda": "TL", "Golden Guardians": "GG", "EXCEL": "XL", "G2 Esports": "G2", "Fnatic": "FNC", "Astralis": "AST", "Schalke 04 Esports": "S04", "SK Gaming": "SK", "Rogue": "RGE", "MAD Lions": "MAD", "Misfits Gaming": "MSF", "Team Vitality": "VIT", "Maturalni Forsaken": "FSK", "AGO Rogue": "RGO", "Illuminar Gaming": "IHG", "Devils.One": "DV1", "Komil&Friends": "KNF", "Zero Tenacity": "Z10", "Gentlemen's Gaming": "GGM", "Goskilla": "GSK", "Topo Centras Iron Wolves": "WOLF", "Team ESCA Gaming": "ESCA" } def get_win_team_name(row): if row["blueTeam_result"] == "loss": return row["redTeam_name"] else: return row["blueTeam_name"] def get_win_ratio(df, team_name, number_of_games): df = df[(df["blueTeam_name"] == team_name) | (df["redTeam_name"] == team_name)] df = df.head(number_of_games) return len(df[df["winTeam_name"] == team_name]) / len(df) def get_last_5_games_win_ratio(df, team_name, number_of_games): df = df[(df["blueTeam_name"] == team_name) | (df["redTeam_name"] == team_name)] df = df.head(number_of_games) df = df.tail(5) return len(df[df["winTeam_name"] == team_name]) / len(df) def get_games_ids(df, team_name, number_of_games): df = df[(df["blueTeam_name"] == team_name) | (df["redTeam_name"] == team_name)] df = df.head(number_of_games) return df["id"] def get_kdas(df_player_stats, games_ids, team_name): team_name_shortcut = names_to_shortcuts[team_name] kda = [] for game_id in games_ids: game_info = df_player_stats[df_player_stats["game_id"] == game_id] game_info = game_info[game_info["summonerName"].str.startswith(team_name_shortcut)] players_kdas = (game_info["kills"] + game_info["assists"]) / game_info["deaths"] players_kdas = players_kdas.values players_kdas[players_kdas == inf] = 10 players_kdas = nan_to_num(players_kdas, nan=1) players_kdas = players_kdas.mean() kda.append(players_kdas) return sum(kda) / len(kda) def get_prediction(team_A, team_B, number_of_games_A, number_of_games_B, league, fuzzy_system, team_a_win, verbose): df_lol = pd.read_csv(f"matchHistory.csv") df_lol = df_lol[df_lol["tournament"] == league] df_lol["gameStarted"] = pd.to_datetime(df_lol["gameStarted"]) df_lol.sort_values(by="gameStarted", inplace=True) df_lol["winTeam_name"] = df_lol.apply(get_win_team_name, axis=1) df_player_stats = pd.read_csv(f"statsGame.csv") df_player_stats = df_player_stats[df_player_stats["tournament"] == league] team_A_games_ids = get_games_ids(df_lol, team_A, number_of_games_A) team_B_games_ids = get_games_ids(df_lol, team_B, number_of_games_B) kda_team_A = get_kdas(df_player_stats, team_A_games_ids, team_A) kda_team_B = get_kdas(df_player_stats, team_B_games_ids, team_B) kda_proportion = kda_team_A / kda_team_B team_A_standings = get_win_ratio(df_lol, team_A, number_of_games_A) * 100 team_B_standings = get_win_ratio(df_lol, team_B, number_of_games_B) * 100 team_A_form = get_last_5_games_win_ratio(df_lol, team_A, number_of_games_A) * 100 team_B_form = get_last_5_games_win_ratio(df_lol, team_B, number_of_games_B) * 100 adv_standings = (team_A_standings - team_B_standings) / 2 + 50 adv_form = (team_A_form - team_B_form) / 2 + 50 adv_performance = (1 - (1 / (1 + kda_proportion))) * 100 if verbose is True: print("\n########## PREDICTION ##########") print(f"Advantage standings: {adv_standings}") print(f"Advantage form: {adv_form}") print(f"Advantage performance: {adv_performance}") res = make_inference(fuzzy_system, adv_standings, adv_form, adv_performance)["RESULT"] return res