/// <summary> /// Initialises a new instance of the <see cref="PointsTableRowViewModel"/> class. /// </summary> /// <param name="athleteSeasonDetails"> /// The model object for an athlete in the current season. /// </param> /// <param name="athleteDetails"> /// The model object for an athlete. /// </param> /// <param name="pointsChanged"> /// Callback method. This is intended to be called when the points change, to allow the /// parent view model to reorder the rows. /// </param> public PointsTableRowViewModel( IAthleteSeasonDetails athleteSeasonDetails, AthleteDetails athleteDetails, Action pointsChanged) : base(athleteDetails.Key, athleteDetails.Name) { this.athleteSeasonDetails = athleteSeasonDetails; this.athleteSeasonPoints = athleteSeasonDetails.Points; this.athleteDetails = athleteDetails; this.PB = this.athleteDetails.PB.ToString(); this.Points = this.athleteSeasonPoints.TotalPoints; this.FinishingPoints = this.athleteSeasonPoints.FinishingPoints; this.PositionPoints = this.athleteSeasonPoints.PositionPoints; this.BestPoints = this.athleteSeasonPoints.BestPoints; this.RaceNumber = this.athleteDetails.PrimaryNumber; this.NumberOfRuns = this.athleteSeasonDetails.NumberOfAppearances; this.SB = this.athleteSeasonDetails.SB.ToString(); this.Sex = this.athleteDetails.Sex.ToString(); this.athleteSeasonDetails.ModelUpdateEvent += this.AthleteSeasonDetailsModelUpdateEvent; this.athleteSeasonPoints.ModelUpdateEvent += this.AthleteSeasonPointsModelUpdateEvent; this.athleteDetails.ModelUpdateEvent += this.AthleteDetailsModelUpdateEvent; this.pointsChangedCallback = pointsChanged; }
/// <summary> /// Update the points earnt for position for the indicated athlete on the indicated date. /// </summary> /// <param name="key">unique key</param> /// <param name="date">date of the event</param> /// <param name="points">earned points</param> public void UpdatePositionPoints(int key, DateType date, int points) { IAthleteSeasonDetails athlete = Athletes.Find(a => a.Key == key); if (athlete == null) { return; } athlete.UpdatePositionPoints(date, points); }
/// <summary> /// Add a new time to the indicated (key) athlete. /// </summary> /// <param name="key">unique key</param> /// <param name="newTime">new time to add</param> public void AddNewTime(int key, Appearances newTime) { IAthleteSeasonDetails athlete = Athletes.Find(a => a.Key == key); if (athlete == null) { return; } athlete.AddNewTime(newTime); }
/// <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()); }
//athleteCurrentSeason.Points.BestPoints)); /// ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- /// <name>LoadAthleteInformation</name> /// <date>14/03/15</date> /// <summary> /// Loads the athlete information via the business library and adds it to the athlete collection. /// </summary> /// ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- private void LoadAthleteInformation(List <AthleteDetails> athletes) { NormalisationConfigType hcConfiguration = this.normalisationConfigManager.ReadNormalisationConfiguration(); List <AthleteDetails> orderedList = athletes.OrderBy(athlete => athlete.Forename).ToList(); orderedList = orderedList.OrderBy(athlete => athlete.Surname).ToList(); this.AthleteCollection = new ObservableCollection <AthleteCompleteViewModel>(); foreach (AthleteDetails athlete in orderedList) { IAthleteSeasonDetails athleteCurrentSeason = this.model.CurrentSeason.Athletes.Find(a => a.Key == athlete.Key); if (athleteCurrentSeason == null) { athleteCurrentSeason = new AthleteSeasonDetails( athlete.Key, athlete.Name); } string handicap = athleteCurrentSeason.GetRoundedHandicap(hcConfiguration)?.ToString() ?? athlete.RoundedHandicap.ToString(); this.AthleteCollection.Add( new AthleteCompleteViewModel( athlete.Key, athlete.Name, athlete.Club, athlete.Sex.ToString(), handicap, athlete.PB.ToString(), athlete.LastAppearance.ToString(), athlete.Appearances, athlete.SignedConsent, athlete.Active, athleteCurrentSeason.SB.ToString(), ListOCConverter.ToObservableCollection(athlete.RunningNumbers), this.ConvertAppearances(athleteCurrentSeason.Times), this.ConvertAppearances(athlete.Times), athleteCurrentSeason.Points.TotalPoints, athleteCurrentSeason.Points.FinishingPoints, athleteCurrentSeason.Points.PositionPoints, athleteCurrentSeason.Points.BestPoints)); } }
/// <summary> /// Loop through the results and work out all the points for the Team Trophy. /// </summary> /// <param name="resultsTable">results table</param> /// <param name="currentDate">date of the event</param> private void CalculateTeamTrophyPoints( EventResults resultsTable, DateType currentDate) { // Next score is used to complete the Team Trophy by filling in any blank spots. // The position is used to assign points to an athlete in the Team Trophy. int teamTrophyCompetitionPosition = 0; int nextScore = 1; resultsTable.OrderByFinishingTime(); Dictionary <string, ITeamTrophyEvent> eventDictionary = new Dictionary <string, ITeamTrophyEvent>(); foreach (IClubSeasonDetails club in this.Model.CurrentSeason.Clubs) { ITeamTrophyEvent newEvent = new TeamTrophyEvent( currentDate, this.resultsConfiguration.ResultsConfigurationDetails.NumberInTeamTrophyTeam); eventDictionary.Add( club.Name, newEvent); } foreach (ResultsTableEntry result in resultsTable.Entries) { IAthleteTeamTrophyPoints athletePoints; IAthleteSeasonDetails athlete = this.Model.CurrentSeason.Athletes.Find( a => a.Key == result.Key); if (athlete == null) { this.logger.WriteLog( $"Calculate Results Manager - Can'f find athlete {result.Key}"); continue; } if (result.Club == string.Empty || result.FirstTimer) { result.TeamTrophyPoints = TeamTrophyNoScore; athletePoints = new AthleteTeamTrophyPoints( TeamTrophyNoScore, currentDate); athlete.TeamTrophyPoints.AddNewEvent(athletePoints); // Not part of the Team Trophy, move onto the next loop. continue; } ++teamTrophyCompetitionPosition; ITeamTrophyEvent clubEvent = eventDictionary[result.Club]; ICommonTeamTrophyPoints clubPoint = new CommonTeamTrophyPoints( teamTrophyCompetitionPosition, result.Name, result.Key, true, currentDate); // Attempt to add point to the club. It will fail if the team is already full. bool success = clubEvent.AddPoint(clubPoint); if (success) { nextScore = teamTrophyCompetitionPosition + 1; result.TeamTrophyPoints = teamTrophyCompetitionPosition; } else { // Add points failed, revert the Team Trophy position. --teamTrophyCompetitionPosition; result.TeamTrophyPoints = TeamTrophyNoScore; } athletePoints = new AthleteTeamTrophyPoints( result.TeamTrophyPoints, currentDate); athlete.TeamTrophyPoints.AddNewEvent(athletePoints); } List <ITeamTrophyEvent> orderedEvent = new List <ITeamTrophyEvent>(); foreach (KeyValuePair <string, ITeamTrophyEvent> entry in eventDictionary) { entry.Value.Complete( this.resultsConfiguration.ResultsConfigurationDetails.NumberInTeamTrophyTeam, nextScore); orderedEvent.Add(entry.Value); } // Apply the score for each team as defined by the configuration file. // To order the teams, they've needed to be pulled out from the dictionary into a list. orderedEvent = orderedEvent.OrderBy(e => e.TotalAthletePoints).ToList(); int lastPoints = -1; int lastScoringIndex = 0; for (int index = 0; index < orderedEvent.Count; ++index) { if (orderedEvent[index].NumberOfAthletes == 0) { break; } if (orderedEvent[index].TotalAthletePoints == lastPoints) { orderedEvent[index].Score = this.resultsConfiguration.ResultsConfigurationDetails.TeamTrophyPoints[lastScoringIndex]; } else if (index < this.resultsConfiguration.ResultsConfigurationDetails.TeamTrophyPoints.Count) { orderedEvent[index].Score = this.resultsConfiguration.ResultsConfigurationDetails.TeamTrophyPoints[index]; lastScoringIndex = index; } lastPoints = orderedEvent[index].TotalAthletePoints; } foreach (KeyValuePair <string, ITeamTrophyEvent> entry in eventDictionary) { this.Model.CurrentSeason.AddNewClubPoints(entry.Key, entry.Value); } }