Beispiel #1
0
        public async Task Calculate(Entities.Match.Match match)
        {
            await this.CalculateByGames(match);

            if (match.IsDraw())
            {
                await this.CalculateByChalks(match);
            }
        }
        protected virtual void CalculateMatch(PlayerFixture fixture, Entities.Match.Match match)
        {
            this.CalculateChalks(fixture, match);
            this.CalculateGames(fixture, match);
            this.CalculateBonusPoints(fixture, match);
            this.CalculateResultType(fixture, match);

            fixture.Entrant1Walkover = match.HomeWalkover;
            fixture.Entrant2Walkover = match.AwayWalkover;
        }
        public async Task Calculate(Entities.Match.Match match)
        {
            await this.CalculateByGames(match);

            if (match.IsDraw())
            {
                await this.CalculateByChalks(match);

                if (match.IsDraw())
                {
                    await this.CalculateByBestIndividualWinner(match);
                }
            }
        }
Beispiel #4
0
        protected Task CalculateByChalks(Entities.Match.Match match)
        {
            match.HomeResultTypeID = ResultType.Draw;
            match.AwayResultTypeID = ResultType.Draw;

            if (match.HomeChalkScore > match.AwayChalkScore)
            {
                match.HomeResultTypeID = ResultType.Win;
                match.AwayResultTypeID = ResultType.Lose;
            }
            else if (match.HomeChalkScore < match.AwayChalkScore)
            {
                match.HomeResultTypeID = ResultType.Lose;
                match.AwayResultTypeID = ResultType.Win;
            }

            return(Task.CompletedTask);
        }
Beispiel #5
0
        protected Task CalculateByGames(Entities.Match.Match match)
        {
            var totalHome = match.HomeGameScore + (match.HomeBonusScore ?? 0);
            var totalAway = match.AwayGameScore + (match.AwayBonusScore ?? 0);

            match.HomeResultTypeID = ResultType.Draw;
            match.AwayResultTypeID = ResultType.Draw;

            if (totalHome > totalAway)
            {
                match.HomeResultTypeID = ResultType.Win;
                match.AwayResultTypeID = ResultType.Lose;
            }
            else if (totalHome < totalAway)
            {
                match.HomeResultTypeID = ResultType.Lose;
                match.AwayResultTypeID = ResultType.Win;
            }

            return(Task.CompletedTask);
        }
        private Task CalculateByBestIndividualWinner(Entities.Match.Match match)
        {
            var teamMatch = match.CastEntity <TeamMatch>();

            IEnumerable <Entities.Game.Game> homeWinResults = teamMatch.Games.Where(x => x.Game.HomeResultTypeID == ResultType.Win).OrderBy(x => x.Game.AwayScore).Select(xx => xx.Game);
            IEnumerable <Entities.Game.Game> awayWinResults = teamMatch.Games.Where(x => x.Game.AwayResultTypeID == ResultType.Win).OrderBy(x => x.Game.HomeScore).Select(xx => xx.Game);

            while (teamMatch.HomeResultTypeID == ResultType.Draw)
            {
                var home = homeWinResults.First();
                var away = awayWinResults.First();

                if (home.AwayScore < away.HomeScore)
                {
                    teamMatch.HomeResultTypeID = ResultType.Win;
                    teamMatch.AwayResultTypeID = ResultType.Lose;

                    teamMatch.Comment = $"{teamMatch.Home.Name} {Message}";
                }
                else if (home.AwayScore > away.HomeScore)
                {
                    teamMatch.HomeResultTypeID = ResultType.Win;
                    teamMatch.AwayResultTypeID = ResultType.Lose;

                    teamMatch.Comment = $"{teamMatch.Away.Name} {Message}";
                }
                else if (home.AwayScore == away.HomeScore)
                {
                    throw new InvalidOperationException("Not sure this logic is right, should pop next not do a where?");
                    homeWinResults = homeWinResults.Where(x => x.AwayScore != home.AwayScore);
                    awayWinResults = awayWinResults.Where(x => x.HomeScore != home.HomeScore);
                }
            }

            return(Task.CompletedTask);
        }
 protected void CalculateBonusPoints(PlayerFixture fixture, Entities.Match.Match match)
 {
     fixture.Entrant1BonusScore = match.HomeBonusScore;
     fixture.Entrant2BonusScore = match.AwayBonusScore;
 }
 protected void CalculateResultType(PlayerFixture fixture, Entities.Match.Match match)
 {
     fixture.Entrant1ResultTypeID = match.HomeResultTypeID;
     fixture.Entrant2ResultTypeID = match.AwayResultTypeID;
 }
 protected void CalculateGames(PlayerFixture fixture, Entities.Match.Match match)
 {
     fixture.Entrant1GameScore = match.HomeGameScore;
     fixture.Entrant2GameScore = match.AwayGameScore;
 }
 protected void CalculateChalks(PlayerFixture fixture, Entities.Match.Match match)
 {
     fixture.Entrant1ChalkScore = match.HomeChalkScore;
     fixture.Entrant2ChalkScore = match.AwayChalkScore;
 }
Beispiel #11
0
 private static void CalculateResultType(TeamFixture fixture, Entities.Match.Match match)
 {
     fixture.Entrant1ResultTypeID = match.HomeResultTypeID;
     fixture.Entrant2ResultTypeID = match.AwayResultTypeID;
 }
Beispiel #12
0
 private static void CalculateBonusPoints(TeamFixture fixture, Entities.Match.Match match)
 {
     fixture.Entrant1BonusScore = match.HomeBonusScore;
     fixture.Entrant2BonusScore = match.AwayBonusScore;
 }
Beispiel #13
0
 private static void CalculateGames(TeamFixture fixture, Entities.Match.Match match)
 {
     fixture.Entrant1GameScore = match.HomeGameScore;
     fixture.Entrant2GameScore = match.AwayGameScore;
 }
Beispiel #14
0
 private static void CalculateChalks(TeamFixture fixture, Entities.Match.Match match)
 {
     fixture.Entrant1ChalkScore = match.HomeChalkScore;
     fixture.Entrant2ChalkScore = match.AwayChalkScore;
 }
 public Task Calculate(Entities.Match.Match match)
 {
     return(this.CalculateByChalks(match));
 }