Пример #1
0
        public static void Update(StandingsEntry source, NonRaceStanding target)
        {
            Update(source, target as Standing);

            target.OfficialBestTime  = source.Time;
            target.OfficialLapNumber = source.Lap;
        }
Пример #2
0
        private static void AddEntryValuesForTeam(Dictionary <long, StandingsEntry> standingsEntries, Score score, Team team)
        {
            StandingsEntry standingsEntry = StandingsCalculation.GetStandingsEntryForTeam(standingsEntries, team);

            standingsEntry.GamesPlayed++;
            standingsEntry.GoalsScored        = standingsEntry.GoalsScored + score.Goals;
            standingsEntry.GoalsScoredAgainst = standingsEntry.GoalsScoredAgainst + score.GoalsAgainst;
            standingsEntry.Points             = standingsEntry.Points + score.Points;
            switch (score.Result)
            {
            case EScoreResult.Win:
                standingsEntry.Wins++;
                break;

            case EScoreResult.OTWin:
            case EScoreResult.PSWin:
                standingsEntry.OTWins++;
                break;

            case EScoreResult.OTLoss:
            case EScoreResult.PSLoss:
                standingsEntry.OTLosses++;
                break;

            case EScoreResult.Loss:
                standingsEntry.Losses++;
                break;
            }
        }
Пример #3
0
        public List <StandingsEntry <PlayerReference> > FindProblematiclyTyingPlayers()
        {
            bool notAllMatchesHasBeenPlayed = !AllMatchesPlayStatesAre(PlayStateEnum.Finished);

            if (notAllMatchesHasBeenPlayed)
            {
                return(new List <StandingsEntry <PlayerReference> >());
            }

            PlayerStandingsSolver playerStandingsSolver = new PlayerStandingsSolver();
            List <StandingsEntry <PlayerReference> > playerStandings    = playerStandingsSolver.FetchFrom(this);
            List <StandingsEntry <PlayerReference> > problematicPlayers = new List <StandingsEntry <PlayerReference> >();

            StandingsEntry <PlayerReference> aboveThresholdPlayer = playerStandings[Round.AdvancingPerGroupCount - 1];
            StandingsEntry <PlayerReference> belowThresholdPlayer = playerStandings[Round.AdvancingPerGroupCount];

            bool playersPartOfProblematicTie = aboveThresholdPlayer.Points == belowThresholdPlayer.Points;

            if (playersPartOfProblematicTie)
            {
                foreach (StandingsEntry <PlayerReference> entry in playerStandings)
                {
                    bool isPartOfTie = entry.Points == aboveThresholdPlayer.Points;

                    if (isPartOfTie)
                    {
                        problematicPlayers.Add(entry);
                    }
                }
            }

            return(problematicPlayers);
        }
Пример #4
0
        private static void SetPosition(List <StandingsEntry> sortedEntries)
        {
            int position = 0;

            for (int i = 0; i < sortedEntries.Count(); i++)
            {
                StandingsEntry entry = sortedEntries.ElementAt(i);
                if (i == 0)
                {
                    position = i + 1;
                }
                else
                {
                    StandingsEntry previousEntry = sortedEntries.ElementAt(i - 1);
                    if ((previousEntry.Points != entry.Points) ||
                        ((previousEntry.GoalsScored - previousEntry.GoalsScoredAgainst) != (entry.GoalsScored - entry.GoalsScoredAgainst)) ||
                        (previousEntry.GoalsScored != entry.GoalsScored) ||
                        (previousEntry.GamesPlayed != entry.GamesPlayed))
                    {
                        position = i + 1;
                    }
                }

                entry.Position = position;
            }
        }
Пример #5
0
        private static void Update(StandingsEntry source, Standing target)
        {
            Contract.Requires(source.CarIdx == target.Driver.CarIdx, "CarIdx does not match.");

            target.Incidents = source.Incidents;
            if (target is RaceStanding)
            {
                (target as RaceStanding).Status = GetStatusFor(source.ReasonOut);
            }
        }
 private static void UpdateStanding(Standing s, StandingsEntry se)
 {
     if (s is NonRaceStanding)
     {
         StandingsEntryUpdater.Update(se, s as NonRaceStanding);
     }
     else
     {
         StandingsEntryUpdater.Update(se, s as RaceStanding);
     }
 }
        public void BallsRatio_NoWonNoLost_RatioNull()
        {
            // Arrange
            var entry = new StandingsEntry {
                BallsWon  = 0,
                BallsLost = 0
            };

            // Act
            var actual = entry.BallsRatio;

            // Assert
            actual.Should().BeNull("Balls ratio should be null when no won no lost balls");
        }
        public void SetsRatio_NoWonNoLost_RatioNull()
        {
            // Arrange
            var entry = new StandingsEntry {
                SetsWon  = 0,
                SetsLost = 0
            };

            // Act
            var actual = entry.SetsRatio;

            // Assert
            actual.Should().BeNull("Sets ratio should be null when no won no lost sets");
        }
        public void BallsRatio_HasWonButNoLost_RatioIsInfinity()
        {
            // Arrange
            var entry = new StandingsEntry {
                BallsWon  = 3,
                BallsLost = 0
            };

            // Act
            var actual = entry.BallsRatio;

            // Assert
            Assert.True(actual.HasValue, "Ratio should not be null");
            Assert.True(float.IsInfinity(actual.GetValueOrDefault()), "Balls ratio should be Infinity when there are no lost balls");
        }
        public void BallsRatio_HasWonAndLost_RatioIsCalculatedProperly()
        {
            // Arrange
            var entry = new StandingsEntry {
                BallsWon  = 3,
                BallsLost = 1
            };

            float expected = 3;

            // Act
            var actual = entry.BallsRatio;

            // Assert
            Assert.True(actual.HasValue, "Ratio should not be null");
            actual.GetValueOrDefault().Should().BeApproximately(expected, 0.001f, "Balls ratio should be properly calculated");
        }
Пример #11
0
        public void SetsRatio_HasWonAndLost_RatioIsCalculatedProperly()
        {
            // Arrange
            var entry = new StandingsEntry
            {
                SetsWon  = 3,
                SetsLost = 1
            };

            float expected = 3;

            // Act
            var actual = entry.SetsRatio;

            // Assert
            Assert.IsTrue(actual.HasValue, "Ratio should not be null");
            Assert.AreEqual(expected, actual.GetValueOrDefault(), 0.001f, "Sets ratio should be properly calculated");
        }
Пример #12
0
 /// <summary>
 /// Maps domain model of <see cref="StandingsEntry"/> to view model of <see cref="StandingsEntry"/>.
 /// </summary>
 /// <param name="standingsEntry">Domain model of <see cref="StandingsEntry"/>.</param>
 /// <returns>View model of <see cref="StandingsEntry"/>.</returns>
 public static StandingsEntryViewModel Map(StandingsEntry standingsEntry)
 {
     return(new StandingsEntryViewModel {
         TeamName = standingsEntry.TeamName,
         Points = standingsEntry.Points,
         GamesTotal = standingsEntry.GamesTotal,
         GamesWon = standingsEntry.GamesWon,
         GamesLost = standingsEntry.GamesLost,
         GamesWithScoreThreeNil = standingsEntry.GamesWithScoreThreeNil,
         GamesWithScoreThreeOne = standingsEntry.GamesWithScoreThreeOne,
         GamesWithScoreThreeTwo = standingsEntry.GamesWithScoreThreeTwo,
         GamesWithScoreTwoThree = standingsEntry.GamesWithScoreTwoThree,
         GamesWithScoreOneThree = standingsEntry.GamesWithScoreOneThree,
         GamesWithScoreNilThree = standingsEntry.GamesWithScoreNilThree,
         SetsWon = standingsEntry.SetsWon,
         SetsLost = standingsEntry.SetsLost,
         SetsRatio = standingsEntry.SetsRatio,
         BallsWon = standingsEntry.BallsWon,
         BallsLost = standingsEntry.BallsLost,
         BallsRatio = standingsEntry.BallsRatio
     });
 }
        private static void CalculateGamesStatistics(StandingsEntry homeTeamEntry, StandingsEntry awayTeamEntry, GameResultDto gameResult)
        {
            homeTeamEntry.GamesTotal++;
            awayTeamEntry.GamesTotal++;

            switch (gameResult.Result.GameScore.Home - gameResult.Result.GameScore.Away)
            {
            case 3:     // sets score - 3:0
                homeTeamEntry.Points += 3;
                homeTeamEntry.GamesWon++;
                homeTeamEntry.GamesWithScoreThreeNil++;
                awayTeamEntry.GamesLost++;
                awayTeamEntry.GamesWithScoreNilThree++;
                break;

            case 2:     // sets score - 3:1
                homeTeamEntry.Points += 3;
                homeTeamEntry.GamesWon++;
                homeTeamEntry.GamesWithScoreThreeOne++;
                awayTeamEntry.GamesLost++;
                awayTeamEntry.GamesWithScoreOneThree++;
                break;

            case 1:     // sets score - 3:2
                homeTeamEntry.Points += 2;
                homeTeamEntry.GamesWon++;
                homeTeamEntry.GamesWithScoreThreeTwo++;
                awayTeamEntry.Points++;
                awayTeamEntry.GamesLost++;
                awayTeamEntry.GamesWithScoreTwoThree++;
                break;

            case -1:     // sets score - 2:3
                homeTeamEntry.Points++;
                homeTeamEntry.GamesLost++;
                homeTeamEntry.GamesWithScoreTwoThree++;
                awayTeamEntry.Points += 2;
                awayTeamEntry.GamesWon++;
                awayTeamEntry.GamesWithScoreThreeTwo++;
                break;

            case -2:     // sets score - 1:3
                homeTeamEntry.GamesLost++;
                homeTeamEntry.GamesWithScoreOneThree++;
                awayTeamEntry.Points += 3;
                awayTeamEntry.GamesWon++;
                awayTeamEntry.GamesWithScoreThreeOne++;
                break;

            case -3:     // sets score - 0:3
                homeTeamEntry.GamesLost++;
                homeTeamEntry.GamesWithScoreNilThree++;
                awayTeamEntry.Points += 3;
                awayTeamEntry.GamesWon++;
                awayTeamEntry.GamesWithScoreThreeNil++;
                break;
            }

            var penalty = gameResult.Result.Penalty;

            if (penalty != null)
            {
                if (penalty.IsHomeTeam)
                {
                    homeTeamEntry.Points -= penalty.Amount;
                }
                else
                {
                    awayTeamEntry.Points -= penalty.Amount;
                }
            }
        }
Пример #14
0
 public static void Update(StandingsEntry source, RaceStanding target)
 {
     Update(source, target as Standing);
 }