Beispiel #1
0
        /// <summary>
        /// Import the times from <paramref name="fileName"/>
        /// </summary>
        /// <param name="fileName">file containing times</param>
        /// <param name="commonIo">common Io manager</param>
        /// <returns>collection of race times.</returns>
        public static List <RaceTimeType> Import(
            string fileName,
            ICommonIo commonIo)
        {
            List <RaceTimeType> rawImportedTimes = new List <RaceTimeType>();
            List <string>       rawTimes         = commonIo.ReadFile(fileName);

            if (rawTimes == null ||
                rawTimes.Count < 3)
            {
                return(rawImportedTimes);
            }

            char splitChar = ',';

            for (int index = 2; index < rawTimes.Count; ++index)
            {
                string[] resultLine = rawTimes[index].Split(splitChar);
                if (resultLine.Length == 3)
                {
                    RaceTimeType time = new RaceTimeType(resultLine[2]);
                    rawImportedTimes.Add(time);
                }
            }

            return(rawImportedTimes);
        }
Beispiel #2
0
        /// <summary>
        /// Converts a line from the file to a raw piece of data. If there are any problems
        /// then a null value is returned.
        /// </summary>
        /// <param name="line">line read from file</param>
        /// <returns>raw piece of data</returns>
        private IRaw ConvertLine(string line)
        {
            string[]     splitLine = line.Split(dataSplitter);
            RaceTimeType time      = null;
            int          order     = 0;
            string       number    = string.Empty;

            if (splitLine.Count() == 3)
            {
                time = new RaceTimeType(splitLine[1]);

                if (time.Minutes == 0 && time.Seconds == 0)
                {
                    return(null);
                }

                number = splitLine[0];

                if (!int.TryParse(splitLine[2], out order))
                {
                    return(null);
                }

                return(new Raw(number, time, order));
            }
            else
            {
                return(null);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Determine whether each line returns a valid time. Note the fault if at least one line
        /// is rubbish.
        /// </summary>
        /// <remarks>
        /// This is constantly being evaluated, I think this is because I'm not using MVVM light
        /// to evaluate property changed events.
        /// </remarks>
        /// <returns>contants valid flag</returns>
        private bool ContentsValid()
        {
            if (string.IsNullOrEmpty(this.TimeEntryContents))
            {
                return(false);
            }

            string[] lines =
                this.TimeEntryContents.Split(
                    new[] { Environment.NewLine },
                    StringSplitOptions.None);

            foreach (string line in lines)
            {
                if (string.IsNullOrWhiteSpace(line))
                {
                    this.FaultString = "Empty Value";
                    return(false);
                }

                RaceTimeType time = new RaceTimeType(line);
                if ((time.Minutes == 59 && time.Seconds == 59) || time.Seconds >= 60)
                {
                    this.FaultString = "Invalid Data";
                    return(false);
                }
            }

            this.FaultString = string.Empty;
            return(true);
        }
Beispiel #4
0
        /// <summary>
        /// Round to the nearest 30 seconds
        /// </summary>
        /// <param name="config">normalisation configuration</param>
        /// <param name="inputTime">time to round</param>
        /// <returns></returns>
        public static RaceTimeType RoundHandicap(
            NormalisationConfigType config,
            RaceTimeType inputTime)
        {
            RaceTimeType calculatedHandicap = inputTime;

            // Make sure the handicap is not less than the minimum.
            if (calculatedHandicap < new TimeType(config.MinimumHandicap, 0))
            {
                return(new RaceTimeType(config.MinimumHandicap, 0));
            }

            // Round to nearest 30 seconds
            if (calculatedHandicap.Seconds < 15)
            {
                calculatedHandicap = new RaceTimeType(calculatedHandicap.Minutes, 0);
            }
            else if (calculatedHandicap.Seconds < 45)
            {
                calculatedHandicap = new RaceTimeType(calculatedHandicap.Minutes, 30);
            }
            else
            {
                calculatedHandicap = new RaceTimeType(calculatedHandicap.Minutes + 1, 0);
            }

            return(calculatedHandicap);
        }
Beispiel #5
0
 /// <summary>
 /// Create a new entry in the results table.
 /// </summary>
 /// <param name="name">Athlete's name</param>
 /// <param name="time">Total time</param>
 /// <param name="handicap">handicap for event</param>
 /// <param name="club">Athlete's club</param>
 /// <param name="raceNumber">Number used in event</param>
 /// <param name="date">event date</param>
 /// <param name="age">age of the athlete</param>
 /// <param name="position">the position of the current entry</param>
 /// <param name="teamTrophyPoints">points associated with the Team Trophy</param>
 public ResultsTableEntry(
     int key,
     string name,
     RaceTimeType time,
     int order,
     RaceTimeType handicap,
     string club,
     SexType sex,
     string raceNumber,
     DateType date,
     int?age,
     int position,
     int teamTrophyPoints)
 {
     this.Key              = key;
     this.Club             = club;
     this.Handicap         = handicap;
     this.Name             = name;
     this.Order            = order;
     this.Points           = new CommonPoints(date);
     this.TeamTrophyPoints = teamTrophyPoints;
     this.RaceNumber       = raceNumber;
     this.Sex              = sex;
     this.Time             = time;
     this.Position         = position;
     this.ExtraInfo        = string.Empty;
 }
Beispiel #6
0
Datei: Raw.cs Projekt: abs508/jHc
 /// <summary>
 /// Creates a new instance of the Raw clas.
 /// </summary>
 /// <param name="number">Number used in the event</param>
 /// <param name="time">total time taken, including the handicap</param>
 /// <param name="timeOrder">order within the same time bracket</param>
 public Raw(
     string number,
     RaceTimeType time,
     int timeOrder)
 {
     this.RaceNumber = number;
     this.TotalTime  = time;
     this.Order      = timeOrder;
 }
Beispiel #7
0
 public RawResults(
     int key,
     string name,
     ObservableCollection <string> runningNumbers)
     : base(key, name, runningNumbers)
 {
     this.raceTime   = null;
     this.order      = 0;
     this.raceNumber = string.Empty;
 }
        /// <summary>
        /// Determine the race time. Manage rounding to the nearest second.
        /// </summary>
        /// <param name="minutes">time minutes</param>
        /// <param name="seconds">seconds minutes</param>
        /// <param name="hundreths">hundreths of a second</param>
        /// <returns>race time</returns>
        private static RaceTimeType CalculateTime(
            int minutes,
            int seconds)
        {
            RaceTimeType time =
                new RaceTimeType(
                    minutes,
                    seconds);

            return(time);
        }
Beispiel #9
0
        /// <summary>
        /// Import the times from <paramref name="fileName"/>
        /// </summary>
        /// <param name="fileName">file containing times</param>
        /// <param name="commonIo">common IO manager</param>
        /// <returns>collection of race times.</returns>
        public static List <RaceTimeType> Import(
            string fileName,
            ICommonIo commonIo)
        {
            List <RaceTimeType> rawImportedTimes = new List <RaceTimeType>();
            List <string>       rawTimes         = commonIo.ReadFile(fileName);

            if (rawTimes == null ||
                rawTimes.Count == 0)
            {
                return(rawImportedTimes);
            }

            foreach (string rawTime in rawTimes)
            {
                RaceTimeType time = new RaceTimeType(rawTime);
                rawImportedTimes.Add(time);
            }

            return(rawImportedTimes);
        }
Beispiel #10
0
        /// <summary>
        /// Gets the athlete handicap from the current season. If none is available, it gets it from
        /// the athlete main body as the predefined handicap.
        /// </summary>
        /// <param name="athleteKey">athlete key</param>
        /// <returns>athlete handicap</returns>
        private RaceTimeType GetAthleteHandicap(
            int athleteKey)
        {
            // Note the current handicap.
            RaceTimeType athleteHandicap =
                this.Model.CurrentSeason.GetAthleteHandicap(
                    athleteKey,
                    this.hcConfiguration);

            if (athleteHandicap == null)
            {
                TimeType globalHandicap =
                    this.Model.Athletes.GetRoundedHandicap(athleteKey);
                athleteHandicap =
                    new RaceTimeType(
                        globalHandicap.Minutes,
                        globalHandicap.Seconds);
            }

            return(athleteHandicap);
        }
Beispiel #11
0
        /// <summary>
        /// Creates a new instance of the ResultsTableEntry class
        /// </summary>
        /// <param name="name">athlete's name</param>
        /// <param name="time">total time</param>
        /// <param name="handicap">athlete's handicap</param>
        /// <param name="club">athlete's club</param>
        /// <param name="raceNumber">athlete's race number</param>
        /// <param name="points">athlete's points</param>
        /// <param name="teamTrophyPoints">points associated with the Team Trophy</param>
        /// <param name="pb">athlete's pb</param>
        /// <param name="yb">athlete's yb</param>
        /// <param name="notes">athlete's notes</param>
        /// <param name="position">the position of the current entry</param>
        public ResultsTableEntry(
            int key,
            string name,
            RaceTimeType time,
            int order,
            int runningOrder,
            RaceTimeType handicap,
            string club,
            SexType sex,
            string raceNumber,
            CommonPoints points,
            int teamTrophyPoints,
            bool pb,
            bool yb,
            string notes,
            string extraInfo,
            int position)
        {
            this.Key              = key;
            this.Club             = club;
            this.ExtraInfo        = extraInfo;
            this.Handicap         = handicap;
            this.Name             = name;
            this.Order            = order;
            this.PB               = pb;
            this.Points           = points;
            this.TeamTrophyPoints = teamTrophyPoints;
            this.RaceNumber       = raceNumber;
            this.RunningOrder     = runningOrder;
            this.Time             = time;
            this.SB               = yb;
            this.Sex              = sex;
            this.Position         = position;

            if (notes != null)
            {
                this.FirstTimer = notes.Contains(firstTimerNote);
            }
        }
Beispiel #12
0
        /// <summary>
        /// Determine the race time. Manage rounding to the nearest second.
        /// </summary>
        /// <param name="minutes">time minutes</param>
        /// <param name="seconds">seconds minutes</param>
        /// <param name="hundreths">hundreths of a second</param>
        /// <returns>race time</returns>
        private static RaceTimeType CalculateTime(
            int minutes,
            int seconds,
            int hundreths)
        {
            RaceTimeType time =
                new RaceTimeType(
                    minutes,
                    seconds);

            if (hundreths >= 50)
            {
                RaceTimeType second =
                    new RaceTimeType(
                        0,
                        1);

                time = time + second;
            }

            return(time);
        }
Beispiel #13
0
        /// <summary>
        /// Calculates a new handicap from the list of times.
        /// </summary>
        public RaceTimeType GetRoundedHandicap(NormalisationConfigType hcConfiguration)
        {
            RaceTimeType handicap;
            RaceTimeType handicapWorking = new RaceTimeType(0, 0);

            if (!hcConfiguration.UseCalculatedHandicap)
            {
                return(null);
            }

            if (this.NumberOfAppearances == 0)
            {
                return(null);
            }

            int eventsIncluded = 0;

            for (int index = NumberOfAppearances - 1; index >= 0; --index)
            {
                if (eventsIncluded < 3)
                {
                    if (!this.Times[index].Time.DNF && !this.Times[index].Time.Unknown)
                    {
                        handicapWorking = handicapWorking + this.Times[index].Time;
                        ++eventsIncluded;
                    }
                }
                else
                {
                    break;
                }
            }

            handicap = new RaceTimeType(hcConfiguration.HandicapTime, 0) - (handicapWorking / eventsIncluded);

            return(HandicapHelper.RoundHandicap(
                       hcConfiguration,
                       handicap));
        }
Beispiel #14
0
        /// <summary>
        ///
        /// </summary>
        private void RegisterNewResult(string raceNumber, RaceTimeType raceTime)
        {
            RawResults result = this.FindAthlete(raceNumber);

            if (result != null)
            {
                result.RaceNumber = raceNumber;
                result.RaceTime   = raceTime;

                // Determine the finish order if two or more athletes share the same finishing time.
                List <RawResults> filteredList = AllAthletes.FindAll(athlete => athlete.RaceTime == result.RaceTime);
                result.Order = filteredList.Count();

                ResetMemberData();

                RaisePropertyChangedEvent("UnregisteredAthletes");
                RaisePropertyChangedEvent("RegisteredAthletes");
            }
            else
            {
                // The athlete is unknown. Add the data to all athletes, all athletes is read
                // when saving the raw results.
                ObservableCollection <string> newNumber = new ObservableCollection <string> {
                    raceNumber
                };
                RawResults newResult = new RawResults(0, string.Empty, newNumber);
                newResult.RaceTime   = raceTime;
                newResult.RaceNumber = raceNumber;

                // Determine the finish order if two or more athletes share the same finishing time.
                List <RawResults> filteredList = AllAthletes.FindAll(athlete => athlete.RaceTime == raceTime);
                newResult.Order = filteredList.Count();

                this.AllAthletes.Add(newResult);
            }
        }
Beispiel #15
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 #16
0
 /// <summary>
 /// Initialises a new instance of the AppearanceType class.
 /// </summary>
 /// <param name="time"></param>
 /// <param name="date"></param>
 public Appearances(RaceTimeType time,
                    DateType date)
 {
     Time = time;
     Date = date;
 }
Beispiel #17
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);
        }