Exemplo n.º 1
0
        private void CalculateSeriesDependentScores(
            SeriesResults resultsWorkInProgress,
            SeriesCompetitorResults compResults)
        {
            // first pass to make sure series based DNC's are filled in.
            foreach (var race in resultsWorkInProgress.SailedRaces)
            {
                var score     = compResults.CalculatedScores[race];
                var scoreCode = GetScoreCode(score.RawScore);
                if (IsSeriesBasedScore(scoreCode) && !IsAverage(score.RawScore.Code))
                {
                    score.ScoreValue = CalculateSeriesBasedValue(
                        resultsWorkInProgress,
                        compResults,
                        race);
                }
            }

            // second pass to get averages.
            foreach (var race in resultsWorkInProgress.SailedRaces)
            {
                var score     = compResults.CalculatedScores[race];
                var scoreCode = GetScoreCode(score.RawScore);
                if (IsSeriesBasedScore(scoreCode) && IsAverage(score.RawScore.Code))
                {
                    score.ScoreValue = CalculateSeriesBasedValue(
                        resultsWorkInProgress,
                        compResults,
                        race);
                }
            }
        }
Exemplo n.º 2
0
        private Decimal?CalculateSeriesBasedValue(
            SeriesResults resultsWorkInProgress,
            SeriesCompetitorResults compResults,
            Race race)
        {
            var score     = compResults.CalculatedScores[race];
            var scoreCode = GetScoreCode(score.RawScore);

            return((scoreCode.Formula.ToUpperInvariant()) switch
            {
                AVERAGE_FORMULANAME => CalculateAverage(compResults),
                AVE_AFTER_DISCARDS_FORMULANAME => CalculateAverageNoDiscards(compResults),
                AVE_PRIOR_RACES_FORMULANAME => CalculateAverageOfPrior(compResults, race),
                SERIESCOMPETITORS_FORMULANAME => GetNumberOfCompetitors(resultsWorkInProgress) + (scoreCode.FormulaValue ?? 0),
                _ => null,
            });
        protected override void DiscardScores(
            SeriesResults resultsWorkInProgress,
            SeriesCompetitorResults compResults)
        {
            int numOfDiscards = GetNumberOfDiscards(resultsWorkInProgress);

            var compResultsOrdered = compResults.CalculatedScores.Values.OrderBy(s => s.ScoreValue)
                                     .ThenBy(s => s.RawScore.Race.Date)
                                     .ThenBy(s => s.RawScore.Race.Order)
                                     .Where(s => GetScoreCode(s.RawScore)?.Discardable ?? true);

            foreach (var score in compResultsOrdered.Take(numOfDiscards))
            {
                score.Discard = true;
            }
        }
Exemplo n.º 4
0
 protected void SetScores(SeriesResults resultsWorkInProgress, IEnumerable <Score> scores)
 {
     ValidateSeries(resultsWorkInProgress, scores);
     ClearRawScores(scores);
     foreach (var comp in resultsWorkInProgress.Competitors)
     {
         SeriesCompetitorResults compResults = CalculateSimpleScores(comp, scores);
         AddDefaultScores(resultsWorkInProgress, compResults);
         CalculateRaceDependentScores(resultsWorkInProgress, compResults);
         CalculateSeriesDependentScores(resultsWorkInProgress, compResults);
         CalculateOverrides(resultsWorkInProgress, compResults);
         DiscardScores(resultsWorkInProgress, compResults);
         resultsWorkInProgress.Results[comp] = compResults;
     }
     CalculateTotals(resultsWorkInProgress, scores);
     CalculateRanks(resultsWorkInProgress);
     resultsWorkInProgress.Competitors = ReorderCompetitors(resultsWorkInProgress);
 }
Exemplo n.º 5
0
 private void AddDefaultScores(
     SeriesResults resultsWorkInProgress,
     SeriesCompetitorResults compResults)
 {
     //Fill in DNCs
     foreach (var race in resultsWorkInProgress.SailedRaces)
     {
         if (!compResults.CalculatedScores.ContainsKey(race))
         {
             compResults.CalculatedScores.Add(race,
                                              new CalculatedScore
             {
                 RawScore = new Score
                 {
                     Code       = DEFAULT_CODE,
                     Competitor = compResults.Competitor,
                     Race       = race
                 }
             });
         }
     }
 }
Exemplo n.º 6
0
 private void CalculateRaceDependentScores(SeriesResults resultsWorkInProgress, SeriesCompetitorResults compResults)
 {
     //calculate non-average codes first
     foreach (var race in resultsWorkInProgress.SailedRaces)
     {
         var score     = compResults.CalculatedScores[race];
         var scoreCode = GetScoreCode(score.RawScore);
         if (scoreCode != null)
         {
             if (IsTrivialCalculation(scoreCode))
             {
                 score.ScoreValue = GetTrivialScoreValue(score);
             }
             else if (IsRaceBasedValue(scoreCode))
             {
                 score.ScoreValue = CalculateRaceBasedValue(score, race);
             }
         }
     }
 }
 protected override void CalculateOverrides(SeriesResults resultsWorkInProgress, SeriesCompetitorResults compResults)
 {
     foreach (var race in resultsWorkInProgress.SailedRaces)
     {
         var score        = compResults.CalculatedScores[race];
         var defaultScore = GetDefaultScore(race, resultsWorkInProgress);
         if (score?.ScoreValue != null && score.ScoreValue < defaultScore)
         {
             score.ScoreValue = defaultScore;
         }
     }
 }