Ejemplo n.º 1
0
        public async Task <ExitCode> ExecuteAsync()
        {
            var league = new League(
                Conversions.ToNation(this.options.Nation),
                this.options.Tier,
                Conversions.ToStartingYear(this.options.StartingYear, this.clock));

            if (this.options.Update)
            {
                await UpdateCommand.UpdateFromServer(league);

                Console.WriteLine();
            }

            var seasonSoFar = TableCommand.CalculateAndDisplayLeagueTable(league, Conversions.ToDate(this.options.On));

            Console.WriteLine();
            Console.WriteLine($"Simulating {this.options.Times:N0} times ...");

            var stopwatch = new Stopwatch();

            stopwatch.Start();

            var seasonSimulator = new SeasonSimulator();
            var result          = seasonSimulator.Simulate(this.options.Resim, this.options.Times, seasonSoFar);

            stopwatch.Stop();

            Console.WriteLine();
            Console.WriteLine(CreateSimulationGrid(result.Teams, league.PositionGroupings));

            Console.WriteLine();
            Console.WriteLine($"Elapsed time: {stopwatch.Elapsed}");

            if (this.options.Csv != null)
            {
                await OutputToCsv(result.Teams, league.PositionGroupings, this.options.Csv);

                Console.WriteLine();
                Console.WriteLine($"Results output to {this.options.Csv}");
            }

            return(ExitCode.Success);
        }
Ejemplo n.º 2
0
        public Task <ExitCode> ExecuteAsync()
        {
            var league = new League(
                Conversions.ToNation(this.options.Nation),
                this.options.Tier,
                Conversions.ToStartingYear(this.options.StartingYear, this.clock));

            var season = TableCommand.CalculateAndDisplayLeagueTable(league, on: null);

            Console.WriteLine();

            var homeConstant = Calculator.CalculateHomeConstant(season);
            var awayConstant = Calculator.CalculateAwayConstant(season);

            // TODO: cope with null
            var homeTablePlacing = season.Table.SingleOrDefault(tp => tp.TeamName == this.options.Home);
            var awayTablePlacing = season.Table.SingleOrDefault(tp => tp.TeamName == this.options.Away);

            var expectedScore = Calculator.CalculateExpectedScore(homeTablePlacing, awayTablePlacing, homeConstant, awayConstant);

            Console.WriteLine($"{homeTablePlacing.TeamName} v {awayTablePlacing.TeamName}");
            Console.WriteLine($"Expected: {expectedScore.Home:N2} - {expectedScore.Away:N2}");
            Console.WriteLine();

            var distribution = new ExpectedScoreDistribution(expectedScore);

            var sampleScores = distribution
                               .TakeSamples(this.options.Times);

            var probabilities = CalculateProbabilities(sampleScores);

            Console.WriteLine($"{homeTablePlacing.TeamName}: {probabilities[Result.HomeWin]:N2}%");
            Console.WriteLine($"Draw: {probabilities[Result.Draw]:N2}%");
            Console.WriteLine($"{awayTablePlacing.TeamName}: {probabilities[Result.AwayWin]:N2}%");

            return(Task.FromResult(ExitCode.Success));
        }