Ejemplo n.º 1
0
Archivo: Season.cs Proyecto: abs508/jHc
        /// <summary>
        /// Add a new time to the indicated (key) athlete.
        /// </summary>
        /// <param name="key">unique key</param>
        /// <param name="points">new points to add</param>
        public void AddNewPoints(
            int key,
            CommonPoints points)
        {
            IAthleteSeasonDetails athlete = Athletes.Find(a => a.Key == key);

            if (athlete == null)
            {
                return;
            }

            athlete.AddNewPoints(points);
            this.AthletesChangedEvent?.Invoke(this, new EventArgs());
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        /// ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
        /// <name>SaveAthleteSeasonData</name>
        /// <date>30/03/15</date>
        /// <summary>
        /// Reads the athlete season details xml from file and decodes it.
        /// </summary>
        /// <param name="fileName">name of xml file</param>
        /// <returns>decoded athlete's details</returns>
        /// ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
        public List <IClubSeasonDetails> LoadClubSeasonData(string fileName)
        {
            List <IClubSeasonDetails> seasonDetails = new List <IClubSeasonDetails>();

            try
            {
                XDocument reader      = XDocument.Load(fileName);
                XElement  rootElement = reader.Root;

                var clubList = from Club in rootElement.Elements(c_clubElement)
                               select new
                {
                    name   = (string)Club.Attribute(nameAttribute),
                    points = from Points in Club.Elements(c_pointsElement)
                             select new
                    {
                        point = from Point in Points.Elements(c_eventPointsElement)
                                select new
                        {
                            finishing = (int)Point.Attribute(finishingPointsAttribute),
                            position  = (int)Point.Attribute(positionPointsAttribute),
                            best      = (int)Point.Attribute(bestPointsAttribute),
                            date      = (string)Point.Attribute(eventDateAttribute)
                        }
                    },
                    harmonyPoints = from HarmonyPoints in Club.Elements(HarmonyPointsElement)
                                    select new
                    {
                        events = from HarmonyEvent in HarmonyPoints.Elements(EventElement)
                                 select new
                        {
                            size         = (int)HarmonyEvent.Attribute(HarmonyTeamSizeAttribute),
                            virtualPoint = (int)HarmonyEvent.Attribute(HarmonyVirtualAthletePointAttribute),
                            date         = (string)HarmonyEvent.Attribute(HarmonyEventDateAttribute),
                            score        = (int)HarmonyEvent.Attribute(HarmonyScoreAttribute),
                            points       = from Point in HarmonyEvent.Elements(c_eventPointsElement)
                                           select new
                            {
                                value = (int)Point.Attribute(HarmonyPointAttribute),
                                key   = (int)Point.Attribute(AthleteKeyAttribute)
                            }
                        }
                    }
                };

                foreach (var club in clubList)
                {
                    ClubSeasonDetails clubDetails = new ClubSeasonDetails(club.name);

                    foreach (var points in club.points)
                    {
                        foreach (var point in points.point)
                        {
                            DateType date =
                                new DateType(
                                    point.date);
                            CommonPoints readPoints =
                                new CommonPoints(
                                    point.finishing,
                                    point.position,
                                    point.best,
                                    date);


                            clubDetails.ClubCompetition.AddNewEvent(readPoints);
                            // TODO, should probably check that there are the correct number read from the xml file.
                            // i.e. there is one for each event in the currently loaded season.
                        }
                    }

                    foreach (var harmonyPoints in club.harmonyPoints)
                    {
                        foreach (var harmonyEvent in harmonyPoints.events)
                        {
                            List <ICommonHarmonyPoints> pointsList = new List <ICommonHarmonyPoints>();
                            DateType date =
                                new DateType(
                                    harmonyEvent.date);

                            foreach (var point in harmonyEvent.points)
                            {
                                CommonHarmonyPoints readPoints =
                                    new CommonHarmonyPoints(
                                        point.value,
                                        string.Empty,
                                        point.key,
                                        true,
                                        date);

                                pointsList.Add(readPoints);
                            }

                            IHarmonyEvent readEvent =
                                new HarmonyEvent(
                                    date,
                                    pointsList,
                                    harmonyEvent.size,
                                    harmonyEvent.score);
                            readEvent.Complete(
                                harmonyEvent.size,
                                harmonyEvent.virtualPoint);

                            clubDetails.HarmonyCompetition.AddEvent(readEvent);
                        }
                    }


                    seasonDetails.Add(clubDetails);
                }
            }
            catch (Exception ex)
            {
                this.logger.WriteLog("Error reading athlete data: " + ex.ToString());

                seasonDetails = new List <IClubSeasonDetails>();
            }

            return(seasonDetails);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Add a new entry to represent a new event.
        /// </summary>
        /// <param name="date">Date of the event</param>
        public void AddNewEvent(CommonPoints newPoints)
        {
            AllPoints.Add(newPoints);

            this.PositionPoints = this.CalculatePositionPoints();
        }
Ejemplo n.º 6
0
        /// ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
        /// <name>SaveAthleteSeasonData</name>
        /// <date>30/03/15</date>
        /// <summary>
        /// Reads the athlete season details xml from file and decodes it.
        /// </summary>
        /// <param name="fileName">name of xml file</param>
        /// <returns>decoded athlete's details</returns>
        /// ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
        public List <IAthleteSeasonDetails> LoadAthleteSeasonData(
            string fileName,
            IResultsConfigMngr resultsConfigurationManager)
        {
            List <IAthleteSeasonDetails> seasonDetails = new List <IAthleteSeasonDetails>();

            try
            {
                XDocument reader      = XDocument.Load(fileName);
                XElement  rootElement = reader.Root;

                var athleteList = from Athlete in rootElement.Elements(c_athleteElement)
                                  select new
                {
                    key            = (int)Athlete.Attribute(c_keyAttribute),
                    name           = (string)Athlete.Attribute(c_nameAttribute),
                    runningNumbers = from RunningNumbers in Athlete.Elements(c_runningNumbersElement)
                                     select new
                    {
                        numbers = from Numbers in RunningNumbers.Elements(c_numberElement)
                                  select new
                        {
                            number = (string)Numbers.Attribute(c_numberAttribute)
                        }
                    },
                    eventTimes = from EventTimes in Athlete.Elements(c_timesElement)
                                 select new
                    {
                        events = from Times in EventTimes.Elements(c_eventTimeElement)
                                 select new
                        {
                            time = (string)Times.Attribute(c_eventTimeAttribute),
                            date = (string)Times.Attribute(c_eventDateAttribute)
                        }
                    },
                    mobTrophyPoints = from Points in Athlete.Elements(MobTrophyPointsElement)
                                      select new
                    {
                        point = from Point in Points.Elements(c_eventPointsElement)
                                select new
                        {
                            finishing = (int)Point.Attribute(c_finishingPoints),
                            position  = (int)Point.Attribute(c_positionPoints),
                            best      = (int)Point.Attribute(c_bestPoints),
                            date      = (string)Point.Attribute(c_eventDateAttribute)
                        }
                    },
                    teamTrophyPoints = from Points in Athlete.Elements(TeamTrophyPointsElement)
                                       select new
                    {
                        point = from Point in Points.Elements(c_eventPointsElement)
                                select new
                        {
                            teamTrophyPoint = (int)Point.Attribute(TeamTrophyPointsAttribute),
                            date            = (string)Point.Attribute(c_eventDateAttribute)
                        }
                    }
                };

                foreach (var athlete in athleteList)
                {
                    AthleteSeasonDetails athleteDetails =
                        new AthleteSeasonDetails(
                            athlete.key,
                            athlete.name);

                    foreach (var eventTms in athlete.eventTimes)
                    {
                        foreach (var times in eventTms.events)
                        {
                            athleteDetails.AddNewTime(new Appearances(new RaceTimeType(times.time),
                                                                      new DateType(times.date)));
                        }
                    }

                    foreach (var points in athlete.mobTrophyPoints)
                    {
                        foreach (var point in points.point)
                        {
                            DateType eventDate =
                                new DateType(
                                    point.date);

                            CommonPoints commonPoints =
                                new CommonPoints(
                                    point.finishing,
                                    point.position,
                                    point.best,
                                    eventDate);

                            athleteDetails.Points.AddNewEvent(commonPoints);
                            // TODO, should probably check that there are the correct number read from the xml file.
                            // i.e. there is one for each event in the currently loaded season.
                            // Will want to change it to proper serialisation at some point.
                        }
                    }

                    foreach (var points in athlete.teamTrophyPoints)
                    {
                        foreach (var point in points.point)
                        {
                            DateType date = new DateType(point.date);
                            IAthleteTeamTrophyPoints newEvent =
                                new AthleteTeamTrophyPoints(
                                    point.teamTrophyPoint,
                                    date);

                            athleteDetails.TeamTrophyPoints.AddNewEvent(newEvent);
                        }
                    }

                    seasonDetails.Add(athleteDetails);
                }
            }
            catch (Exception ex)
            {
                this.logger.WriteLog("Error reading athlete data: " + ex.ToString());

                seasonDetails = new List <IAthleteSeasonDetails>();
            }

            return(seasonDetails);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Add a new entry to represent a new event.
 /// </summary>
 /// <param name="date">Date of the event</param>
 public void AddNewEvent(CommonPoints newPoints)
 {
     this.AllPoints.Add(newPoints);
     this.ModelUpdateEvent?.Invoke(this, EventArgs.Empty);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Add some new points
 /// </summary>
 /// <param name="points">points to add</param>
 public void AddNewPoints(CommonPoints points)
 {
     this.Points.AddNewEvent(points);
 }
Ejemplo n.º 9
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);
        }