Ejemplo n.º 1
0
 private int Compare(ResultsListReportEntrySubresult x, ResultsListReportEntrySubresult y)
 {
     if (comparer == null)
     {
         return(-Comparer <double?> .Default.Compare(x.FinalPoints, y.FinalPoints));    // descending by default
     }
     else
     {
         return(comparer.Compare(x, y));
     }
 }
Ejemplo n.º 2
0
            private ResultsListReportEntrySubresult BuildCompositeSubresult(Athlete athlete)
            {
                double       finalPoints          = 0f;
                Performance  combinedAnnouncement = new Performance();
                ActualResult combinedResult       = new ActualResult();

                combinedResult.Performance      = new Performance();
                combinedResult.FinalPerformance = new Performance();
                combinedResult.Penalizations    = new List <Penalization>();
                combinedResult.CardResult       = CardResult.None;

                foreach (var component in components)
                {
                    var disciplineId = component.Discipline.DisciplineId;
                    var announcement = athlete.Announcements.FirstOrDefault(a => a.DisciplineId == disciplineId);
                    var actualResult = athlete.ActualResults.LastOrDefault(a => a.DisciplineId == disciplineId);

                    if (announcement != null)
                    {
                        MergePerformance(combinedAnnouncement, announcement.Performance);
                    }
                    if (actualResult != null)
                    {
                        MergePerformance(combinedResult.Performance, actualResult.Performance);
                        MergePerformance(combinedResult.FinalPerformance, actualResult.FinalPerformance);
                        combinedResult.CardResult = CombineCards(combinedResult.CardResult, actualResult.CardResult);
                        combinedResult.Penalizations.AddRange(actualResult.Penalizations);
                        finalPoints += component.CalculateFinalPoints(actualResult) ?? 0.0;
                    }
                }
                var subresult = new ResultsListReportEntrySubresult();

                if (hasFinalPoints && allowResults)
                {
                    subresult.FinalPoints = finalPoints;
                }
                if (primaryComponent != PerformanceComponent.None)
                {
                    if (allowAnnouncements)
                    {
                        subresult.Announcement = BuildReportAnnouncement(new Announcement {
                            Performance = combinedAnnouncement
                        });
                    }
                    if (allowResults)
                    {
                        subresult.CurrentResult = BuildReportActualResult(combinedResult, null);
                    }
                }
                return(subresult);
            }
Ejemplo n.º 3
0
            private ResultsListReportEntrySubresult BuildSingleSubresult(Models.Athlete athlete)
            {
                var disciplineId = components[0].Discipline.DisciplineId;
                var announcement = athlete.Announcements.FirstOrDefault(a => a.DisciplineId == disciplineId);
                var actualResult = athlete.ActualResults.LastOrDefault(a => a.DisciplineId == disciplineId);

                var subresult = new ResultsListReportEntrySubresult();

                if (allowAnnouncements)
                {
                    subresult.Announcement = BuildReportAnnouncement(announcement);
                }
                if (allowResults)
                {
                    subresult.CurrentResult = BuildReportActualResult(actualResult, null);
                    subresult.FinalPoints   = components[0].CalculateFinalPoints(actualResult);
                }
                return(subresult);
            }
Ejemplo n.º 4
0
        public ResultsListReport GetReportDisciplineResults(string raceId, string disciplineId, JudgePrincipal principal)
        {
            if (string.IsNullOrEmpty(raceId))
            {
                throw new ArgumentNullException("Missing RaceId");
            }
            if (string.IsNullOrEmpty(disciplineId))
            {
                throw new ArgumentNullException("Missing DisciplineId");
            }
            IRepositorySet repositorySet = repositorySetProvider.GetRepositorySet(raceId);

            var discipline = repositorySet.Disciplines.FindDiscipline(disciplineId);

            if (discipline == null)
            {
                throw new ArgumentOutOfRangeException("Unknown DisciplineId " + disciplineId);
            }

            var rules = rulesProvider.Get(discipline.Rules);

            if (rules == null)
            {
                throw new ArgumentOutOfRangeException("Unknown DisciplineRules " + discipline.Rules);
            }

            var athletes = repositorySet.Athletes.GetAthletes();
            var judges   = repositorySet.Judges.GetJudges();

            var allowAnnouncement = principal != null || discipline.AnnouncementsPublic;
            var allowResult       = principal != null || discipline.ResultsPublic;

            var entries = new List <ResultsListReportEntry>();

            foreach (var athlete in athletes)
            {
                var announcement = athlete.Announcements.FirstOrDefault(a => a.DisciplineId == disciplineId);
                var actualResult = athlete.ActualResults.LastOrDefault(r => r.DisciplineId == disciplineId);
                if (announcement == null)
                {
                    continue;                           // does not compete in this discipline, skip
                }
                var judge = actualResult == null ? null : judges.FirstOrDefault(j => j.JudgeId == actualResult.JudgeId);

                var entry = new ResultsListReportEntry();
                entry.Athlete    = ApiAthlete.BuildProfile(athlete);
                entry.Subresults = new List <ResultsListReportEntrySubresult>();
                var subresult = new ResultsListReportEntrySubresult();
                if (allowAnnouncement)
                {
                    subresult.Announcement = BuildReportAnnouncement(announcement);
                }
                if (allowResult)
                {
                    subresult.CurrentResult = BuildReportActualResult(actualResult, judge);
                    subresult.FinalPoints   = subresult.CurrentResult?.FinalPerformance?.Points;
                }
                entry.Subresults.Add(subresult);

                entries.Add(entry);
            }

            entries.Sort(new ResultsListReportEntryComparer(rules.ResultsComparer, 0));

            return(new ResultsListReport
            {
                Metadata = BuildDisciplineReportMetadata(discipline, rules),
                Results = entries
            });
        }