private void RunResultsComparison(Result[,] results, Session session, ChampionshipStatistic originalStatistic, ChampionshipStatistic newStatistic) { if (this.session != session) //If the original data needs to be updated { this.session = session; if (SessionChanged != null) { SessionChanged(this, session); } GetResultsFromData(session); originalStatistic = Statistic; } int[] driverDeltasByIndex = ChampionshipStatistic.GetDriverDeltasFrom(originalStatistic, Statistic); int[] teamDeltasByIndex = ChampionshipStatistic.GetTeamDeltasFrom(originalStatistic, Statistic); this.results = results; if (ChampionshipsModified != null) { ChampionshipsModified(this, newStatistic); } if (TeamDeltasUpdated != null) { TeamDeltasUpdated(this, teamDeltasByIndex); } if (DriverDeltasUpdated != null) { DriverDeltasUpdated(this, driverDeltasByIndex); } }
void UpdateDriverPoints(ChampionshipStatistic statistic) { Driver driver; int pointsDelta = 0; for (int driverIndex = 0; driverIndex < Data.NumberOfDrivers; driverIndex++) { driver = DataController.GetDriverAtPosition(statistic, driverIndex); Number[driverIndex].Text = Convert.ToString(driver.DriverNumber); Names[driverIndex].Text = Convert.ToString(driver.DriverName); Names[driverIndex].ForeColor = driver.LineColour; Points[driverIndex].Text = Convert.ToString(DataController.GetDriverPoints(statistic, driverIndex)); if (driverIndex != 0) { pointsDelta = DataController.GetDriverPointsDelta(statistic, driverIndex); PointsDelta[driverIndex].Text = Convert.ToString(pointsDelta); } } Team team; for (int teamIndex = 0; teamIndex < Data.NumberOfDrivers / 2; teamIndex++) { team = DataController.GetTeamAtPosition(statistic, teamIndex); TeamNames[teamIndex].Text = Convert.ToString(team.TeamName); TeamPoints[teamIndex].Text = Convert.ToString(DataController.GetTeamPoints(statistic, teamIndex)); if (teamIndex != 0) { pointsDelta = DataController.GetTeamPointsDelta(statistic, teamIndex); TeamPointsDelta[teamIndex].Text = Convert.ToString(pointsDelta); } } }
private void GetResultsFromData(Session session) { results = StatisticManager.GetResultsFromDatabase(session); Statistic = StatisticManager.GetChampionships(results, PointSystem, DoublePoints); if (DataLoadedFromDatabase != null) { DataLoadedFromDatabase(this, new EventArgs()); } }
void ChampionshipData_PointSystemChanged(object sender, EventArgs e) { ChampionshipStatistic newStatistic = StatisticManager.GetChampionships(results, PointSystem, DoublePoints); RunResultsComparison(results, session, Statistic, newStatistic); if (ChampionshipsModified != null) { ChampionshipsModified(this, newStatistic); } }
public void TestSortByIndex() { var Data = new Data(); ChampionshipStatistic statistic = new ChampionshipStatistic(); statistic.CalculateStatistics(); statistic.Sort(OrderType.Ascending, SortType.Index); //The result here depends on the database: it should be the first car in the database. Assert.AreEqual("HAMILTON", ((ChampionshipDataElement)statistic.DriverStats[0]).CompetitorName); }
public void TestSortByValue() { var Data = new Data(); ChampionshipStatistic statistic = new ChampionshipStatistic(); statistic.CalculateStatistics(); statistic.Sort(OrderType.Descending, SortType.Value); Assert.AreEqual("HAMILTON", ((ChampionshipDataElement)statistic.DriverStats[0]).CompetitorName); }
internal int GetDriverPointsDelta(ChampionshipStatistic statistic, int driverIndex) { if (driverIndex == 0) { return(-1); } else { return(GetDriverPoints(statistic, driverIndex) - GetDriverPoints(statistic, driverIndex - 1)); } }
internal int GetTeamPointsDelta(ChampionshipStatistic statistic, int teamIndex) { if (teamIndex == 0) { return(-1); } else { return(GetTeamPoints(statistic, teamIndex) - GetTeamPoints(statistic, teamIndex - 1)); } }
public static ChampionshipStatistic GetChampionships(Result[,] results, PointScoringSystem pointSystem, bool doublePoints) { ChampionshipStatistic statistic = new ChampionshipStatistic(); statistic.PointSystem = pointSystem; statistic.DoublePoints = doublePoints; statistic.SetResults(results); statistic.CalculateStatistics(); statistic.Sort(OrderType.Descending, SortType.Value); return statistic; }
public void SetSession(Session session) { ChampionshipStatistic originalStatistic = Statistic; this.session = session; if (SessionChanged != null) { SessionChanged(this, session); } GetResultsFromData(session); RunResultsComparison(results, session, originalStatistic, Statistic); }
internal int[] GetDriverData() { int[] driverChampionship = new int[Data.NumberOfDrivers]; ChampionshipStatistic statistic = StatisticManager.GetChampionships(results, pointSystem, doublePoints); for (int driverIndex = 0; driverIndex < Data.NumberOfDrivers; driverIndex++) { driverChampionship[driverIndex] = ((ChampionshipDataElement)statistic.DriverStats[driverIndex]).Points; } return(driverChampionship); }
internal int[] GetTeamData() { int[] teamChampionship = new int[Data.NumberOfDrivers / 2]; ChampionshipStatistic statistic = StatisticManager.GetChampionships(results, pointSystem, doublePoints); for (int teamIndex = 0; teamIndex < Data.NumberOfDrivers / 2; teamIndex++) { teamChampionship[teamIndex] = ((ChampionshipDataElement)statistic.TeamStats[teamIndex]).Points; } return(teamChampionship); }
public void TestPopulateChampionshipResults() { var Data = new Data(); ChampionshipStatistic statistic = new ChampionshipStatistic(); Result[,] results = new Result[Data.NumberOfDrivers, Data.NumberOfTracks]; for (int i = 0; i < Data.NumberOfDrivers; i++) { //First round results: results[i, 0].position = (i + 1); } statistic.SetResults(results); statistic.CalculateStatistics(); statistic.Sort(OrderType.Descending, SortType.Value); Assert.AreEqual(0, statistic.DriverStats[0].CompetitorIndex); Assert.AreEqual(25, ((ChampionshipDataElement)statistic.DriverStats[0]).Points); Assert.AreEqual(43, ((ChampionshipDataElement)statistic.TeamStats[0]).Points); Assert.AreEqual(1, ((ChampionshipDataElement)statistic.TeamStats[0]).NumberOfResults[0]); }
void DataController_ChampionshipsModified(object sender, ChampionshipStatistic e) { UpdateDriverPoints(e); }
internal Driver GetDriverAtPosition(ChampionshipStatistic statistic, int driverPosition) { return(Data.Drivers[statistic.DriverStats[driverPosition].CompetitorIndex]); }
void StartChampionshipStatistic(object sender, int e) { ChampionshipStatistic statistic = new ChampionshipStatistic(); statistic.DisplayStatistic(events, base.Form, (Session)e); }
internal Team GetTeamAtPosition(ChampionshipStatistic statistic, int teamPosition) { return(Data.Teams[statistic.TeamStats[teamPosition].CompetitorIndex]); }
void StatisticManager_ResultsUpdated(object sender, ResultsUpdatedEventArgs e) { ChampionshipStatistic newStatistic = StatisticManager.GetChampionships(e.results, PointSystem, DoublePoints); RunResultsComparison(e.results, e.session, Statistic, newStatistic); }
internal int GetDriverPoints(ChampionshipStatistic statistic, int driverIndex) { return(((ChampionshipDataElement)statistic.DriverStats[driverIndex]).Points); }
internal int GetTeamPoints(ChampionshipStatistic statistic, int teamIndex) { return(((ChampionshipDataElement)statistic.TeamStats[teamIndex]).Points); }