Beispiel #1
0
        /// <summary>
        /// Reads the athlete season details xml from file and decodes it.
        /// </summary>
        /// <param name="seasonName">season name</param>
        /// <param name="eventName">event name</param>
        /// <param name="date">event date</param>
        /// <returns>decoded athlete's details</returns>
        public IEventResults LoadResultsTable(
            string seasonName,
            string eventName,
            DateType date)
        {
            IEventResults    resultsTable = new EventResults();
            ResultsTableRoot deserialisedResultTable;
            string           resultsPath =
                ResultsTableReader.GetPath(
                    seasonName,
                    eventName);

            try
            {
                deserialisedResultTable =
                    XmlFileIo.ReadXml <ResultsTableRoot>(
                        resultsPath);
            }
            catch (XmlException ex)
            {
                this.logger.WriteLog(
                    $"Error reading the results table; {ex.XmlMessage}");

                return(resultsTable);
            }

            foreach (Row row in deserialisedResultTable)
            {
                RaceTimeType time =
                    new RaceTimeType(
                        row.Time);
                RaceTimeType handicap =
                    new RaceTimeType(
                        row.Handicap);
                CommonPoints points =
                    new CommonPoints(
                        row.Points,
                        date);
                int position = resultsTable.Entries.Count + 1;

                ResultsTableEntry rowEntry =
                    new ResultsTableEntry(
                        row.Key,
                        row.Name,
                        time,
                        row.Order,
                        row.RunningOrder,
                        handicap,
                        row.Club,
                        row.Sex,
                        row.Number,
                        points,
                        row.HarmonyPoints,
                        row.IsPersonalBest,
                        row.IsYearBest,
                        row.Notes,
                        row.ExtraInformation,
                        position);
                resultsTable.AddEntry(rowEntry);
            }

            return(resultsTable);
        }
Beispiel #2
0
        /// <summary>
        /// Generate the results table from the raw results and return it.
        /// </summary>
        /// <param name="rawResults">raw results</param>
        /// <returns>event results table</returns>
        private EventResults GenerateResultsTable(
            List <IRaw> rawResults)
        {
            EventResults resultsTable = new EventResults();
            DateType     eventDate    = this.Model.CurrentEvent.Date;

            foreach (Raw raw in rawResults)
            {
                CommonPoints pointsEarned = new CommonPoints(eventDate);

                // Get athlete key.
                int key = this.Model.Athletes.GetAthleteKey(raw.RaceNumber) ?? 0;

                // Note the current handicap.
                RaceTimeType athleteHandicap =
                    this.GetAthleteHandicap(
                        key);

                // Loop through all the entries in the raw results.
                ResultsTableEntry singleResult =
                    new ResultsTableEntry(
                        key,
                        this.Model.Athletes.GetAthleteName(key),
                        raw.TotalTime,
                        raw.Order,
                        athleteHandicap,
                        this.Model.Athletes.GetAthleteClub(key),
                        this.Model.Athletes.GetAthleteSex(key),
                        raw.RaceNumber,
                        this.Model.CurrentEvent.Date,
                        this.Model.Athletes.GetAthleteAge(key),
                        resultsTable.Entries.Count + 1,
                        999999);

                if (!raw.TotalTime.DNF && !raw.TotalTime.Unknown)
                {
                    if (this.Model.Athletes.IsFirstTimer(key))
                    {
                        singleResult.FirstTimer = true;
                    }

                    pointsEarned.FinishingPoints = this.resultsConfiguration.ResultsConfigurationDetails.FinishingPoints;

                    // Work out the season best information
                    if (this.Model.CurrentSeason.GetSB(key) > singleResult.RunningTime)
                    {
                        // Can only count as season best if one time has been set.
                        if (this.Model.CurrentSeason.GetAthleteAppearancesCount(key) > 0)
                        {
                            pointsEarned.BestPoints = this.resultsConfiguration.ResultsConfigurationDetails.SeasonBestPoints;
                            singleResult.SB         = true;
                            this.RecordNewSB();
                        }
                    }

                    singleResult.Points = pointsEarned;

                    // Work out the personal best information.
                    if (this.Model.Athletes.GetPB(key) > singleResult.RunningTime)
                    {
                        // Only not as PB if not the first run.
                        if (!singleResult.FirstTimer)
                        {
                            singleResult.PB = true;
                            this.RecordNewPB();
                        }
                    }

                    this.CheckForFastestTime(this.Model.Athletes.GetAthleteSex(key),
                                             key,
                                             this.Model.Athletes.GetAthleteName(key),
                                             raw.TotalTime - athleteHandicap,
                                             eventDate);
                    this.UpdateNumberStatistics(this.Model.Athletes.GetAthleteSex(key),
                                                singleResult.FirstTimer);
                }

                this.Model.Athletes.AddNewTime(key, new Appearances(singleResult.RunningTime, eventDate));
                this.Model.CurrentSeason.AddNewTime(key, new Appearances(singleResult.RunningTime, eventDate));
                this.Model.CurrentSeason.AddNewPoints(key, pointsEarned);

                // End loop through all the entries in the raw results.
                resultsTable.AddEntry(singleResult);
            }

            return(resultsTable);
        }