Example #1
0
class SimulationRunner:
    def __init__(self):
        configuration = SimulationConfiguration.base_configuration()

        self.league_results = self._load_league_results("../Data/FD_Outcomes/FD_League_Results.csv")
        self.player_stats = self._load_player_stats("../Stats_2012_15.pkl")

        self.enricher = FantasyStatsEnricher()
        self.enricher.enrich_player_stats(self.player_stats, self.league_results)

        self.base_efppg = SimulationBuilder.base_efppg_from_configuration(configuration)
        self.league_simulator = SimulationBuilder.league_simulator_from_configuration(configuration)

        self._append_league_csv_names()

        self.summarizer = SimulationSummarizer(self.league_results.copy())

    def run_simulation(self):
        self.player_stats = self.base_efppg.run_base_efppg()
        self._simulate_all_leagues()

    def _simulate_all_leagues(self):
        league_results_grouped = self.league_results.groupby(["Cost_CSV"]).first()
        league_results_grouped = league_results_grouped.reset_index()

        league_results_grouped.apply(self._simulate_league, axis=1)
        self.summarizer.write_result_to_pickle()

    def _load_league_results(self, league_results_file):
        result = pd.read_csv(league_results_file)
        result["Date"] = result.apply(self._formatted_date, axis=1)
        return result

    def _load_player_stats(self, player_stats_file):
        return pd.read_pickle(player_stats_file)

    def _formatted_date(self, row):
        return time.strptime(row["Date"], "%m/%d/%y")

    def _append_league_csv_names(self):
        self.league_results["Cost_CSV"] = self.league_results.apply(self._league_csv_from_row, axis=1)

    def _league_csv_from_row(self, row):
        csv_date = time.strftime("%m-%d-%Y", row["Date"])
        return "FD_" + row["Type"] + "_" + csv_date + ".csv"

    def _simulate_league(self, row):
        cost_csv = row["Cost_CSV"]
        player_costs = pd.read_csv("../Data/FD_Player_Costs/" + cost_csv)
        league_results = self.league_simulator.simulate_league(
            self.player_stats, player_costs, row["Type"], row["Date"]
        )
        print league_results
        self.summarizer.append_league_statistics(league_results)
Example #2
0
    def __init__(self):
        configuration = SimulationConfiguration.base_configuration()

        self.league_results = self._load_league_results("../Data/FD_Outcomes/FD_League_Results.csv")
        self.player_stats = self._load_player_stats("../Stats_2012_15.pkl")

        self.enricher = FantasyStatsEnricher()
        self.enricher.enrich_player_stats(self.player_stats, self.league_results)

        self.base_efppg = SimulationBuilder.base_efppg_from_configuration(configuration)
        self.league_simulator = SimulationBuilder.league_simulator_from_configuration(configuration)

        self._append_league_csv_names()

        self.summarizer = SimulationSummarizer(self.league_results.copy())