Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        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);
                }
            }
        }
Ejemplo n.º 3
0
 private void GetResultsFromData(Session session)
 {
     results   = StatisticManager.GetResultsFromDatabase(session);
     Statistic = StatisticManager.GetChampionships(results, PointSystem, DoublePoints);
     if (DataLoadedFromDatabase != null)
     {
         DataLoadedFromDatabase(this, new EventArgs());
     }
 }
Ejemplo n.º 4
0
        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);
            }
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
 internal int GetDriverPointsDelta(ChampionshipStatistic statistic, int driverIndex)
 {
     if (driverIndex == 0)
     {
         return(-1);
     }
     else
     {
         return(GetDriverPoints(statistic, driverIndex) - GetDriverPoints(statistic, driverIndex - 1));
     }
 }
Ejemplo n.º 8
0
 internal int GetTeamPointsDelta(ChampionshipStatistic statistic, int teamIndex)
 {
     if (teamIndex == 0)
     {
         return(-1);
     }
     else
     {
         return(GetTeamPoints(statistic, teamIndex) - GetTeamPoints(statistic, teamIndex - 1));
     }
 }
Ejemplo n.º 9
0
        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;
        }
Ejemplo n.º 10
0
        public void SetSession(Session session)
        {
            ChampionshipStatistic originalStatistic = Statistic;

            this.session = session;
            if (SessionChanged != null)
            {
                SessionChanged(this, session);
            }
            GetResultsFromData(session);
            RunResultsComparison(results, session, originalStatistic, Statistic);
        }
Ejemplo n.º 11
0
        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);
        }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
        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]);
        }
Ejemplo n.º 14
0
 void DataController_ChampionshipsModified(object sender, ChampionshipStatistic e)
 {
     UpdateDriverPoints(e);
 }
Ejemplo n.º 15
0
 internal Driver GetDriverAtPosition(ChampionshipStatistic statistic, int driverPosition)
 {
     return(Data.Drivers[statistic.DriverStats[driverPosition].CompetitorIndex]);
 }
Ejemplo n.º 16
0
        void StartChampionshipStatistic(object sender, int e)
        {
            ChampionshipStatistic statistic = new ChampionshipStatistic();

            statistic.DisplayStatistic(events, base.Form, (Session)e);
        }
Ejemplo n.º 17
0
 internal Team GetTeamAtPosition(ChampionshipStatistic statistic, int teamPosition)
 {
     return(Data.Teams[statistic.TeamStats[teamPosition].CompetitorIndex]);
 }
Ejemplo n.º 18
0
        void StatisticManager_ResultsUpdated(object sender, ResultsUpdatedEventArgs e)
        {
            ChampionshipStatistic newStatistic = StatisticManager.GetChampionships(e.results, PointSystem, DoublePoints);

            RunResultsComparison(e.results, e.session, Statistic, newStatistic);
        }
Ejemplo n.º 19
0
 internal int GetDriverPoints(ChampionshipStatistic statistic, int driverIndex)
 {
     return(((ChampionshipDataElement)statistic.DriverStats[driverIndex]).Points);
 }
Ejemplo n.º 20
0
 internal int GetTeamPoints(ChampionshipStatistic statistic, int teamIndex)
 {
     return(((ChampionshipDataElement)statistic.TeamStats[teamIndex]).Points);
 }