/// <summary> /// Add a new events results for this season. /// </summary> /// <remarks> /// If there is already an event on the <paramref name="date"/> then it should be overwritten /// instead of adding a new event. /// </remarks> /// <param name="newEvent">new event</param> public void AddEvent( IHarmonyEvent newEvent) { if (this.Events.Count > 0) { for (int index = 0; index < this.Events.Count; ++index) { if (this.Events[index].Date == newEvent.Date) { this.Events[index] = newEvent; return; } } } this.Events.Add(newEvent); }
/// <summary> /// Add points to the named club /// </summary> /// <param name="clubName">name of club</param> /// <param name="points">harmony points to add</param> public void AddNewClubPoints( string clubName, IHarmonyEvent points) { IClubSeasonDetails clubDetails = Clubs.Find(club => club.Name.CompareTo(clubName) == 0); if (clubDetails != null) { clubDetails.AddNewEvent(points); } else { ClubSeasonDetails newClubDetails = new ClubSeasonDetails(clubName); newClubDetails.AddNewEvent(points); Clubs.Add(newClubDetails); } this.ClubsChangedEvent?.Invoke(this, new EventArgs()); }
/// <summary> /// Add a new event. /// </summary> /// <param name="newPoints">points harmony received</param> public void AddNewEvent( IHarmonyEvent newEvent) { this.HarmonyCompetition.AddEvent(newEvent); }
/// <summary> /// Loop through the results and work out all the points for the harmony competition. /// </summary> /// <param name="resultsTable">results table</param> /// <param name="currentDate">date of the event</param> private void CalculateTeamHarmonyPoints( EventResults resultsTable, DateType currentDate) { // Next score is used to complete the harmony competion by filling in any blank spots. // The position is used to assign points to an athlete in the harmony competion. int harmonyCompetitionPosition = 0; int nextScore = 1; resultsTable.OrderByFinishingTime(); Dictionary <string, IHarmonyEvent> eventDictionary = new Dictionary <string, IHarmonyEvent>(); foreach (IClubSeasonDetails club in this.Model.CurrentSeason.Clubs) { IHarmonyEvent newEvent = new HarmonyEvent( currentDate, this.resultsConfiguration.ResultsConfigurationDetails.NumberInHarmonyTeam); eventDictionary.Add( club.Name, newEvent); } foreach (ResultsTableEntry result in resultsTable.Entries) { IAthleteHarmonyPoints athletePoints; AthleteSeasonDetails 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.HarmonyPoints = HarmonyNoScore; athletePoints = new AthleteHarmonyPoints( HarmonyNoScore, currentDate); athlete.HarmonyPoints.AddNewEvent(athletePoints); // Not part of the harmony competition, move onto the next loop. continue; } ++harmonyCompetitionPosition; IHarmonyEvent clubEvent = eventDictionary[result.Club]; ICommonHarmonyPoints clubPoint = new CommonHarmonyPoints( harmonyCompetitionPosition, 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 = harmonyCompetitionPosition + 1; result.HarmonyPoints = harmonyCompetitionPosition; } else { // Add points failed, rever the harmony competition position. --harmonyCompetitionPosition; result.HarmonyPoints = HarmonyNoScore; } athletePoints = new AthleteHarmonyPoints( result.HarmonyPoints, currentDate); athlete.HarmonyPoints.AddNewEvent(athletePoints); } List <IHarmonyEvent> orderedEvent = new List <IHarmonyEvent>(); foreach (KeyValuePair <string, IHarmonyEvent> entry in eventDictionary) { entry.Value.Complete( this.resultsConfiguration.ResultsConfigurationDetails.NumberInHarmonyTeam, 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(); for (int index = 0; index < orderedEvent.Count; ++index) { if (index < this.resultsConfiguration.ResultsConfigurationDetails.HarmonyPoints.Count) { orderedEvent[index].Score = this.resultsConfiguration.ResultsConfigurationDetails.HarmonyPoints[index]; } } foreach (KeyValuePair <string, IHarmonyEvent> entry in eventDictionary) { this.Model.CurrentSeason.AddNewClubPoints(entry.Key, entry.Value); } }