public DataProcessingException(string message, List <Race> selectedRaces, RatingsFormula selectedFormula)
            : base(message)
        {
            string strSelectedRaces = "/";

            if (selectedRaces != null && selectedRaces.Count > 0)
            {
                strSelectedRaces = "";
                foreach (Race r in selectedRaces)
                {
                    strSelectedRaces += r.Id + ", ";
                }

                strSelectedRaces.TrimEnd(new char[] { ',', ' ' });
            }

            string strSelectedFormula = "/";

            if (selectedFormula != null && !selectedFormula.IsProtected)
            {
                strSelectedFormula = selectedFormula.ToXMLString();
            }

            this.Data.Add("SelectedRaces", strSelectedRaces);
            this.Data.Add("SelectedFormula", strSelectedFormula);
        }
Пример #2
0
        private void cmbFormula_SelectedIndexChanged(object sender, EventArgs e)
        {
            RatingsFormula previousFormula = this.bsSelectedFormula.DataSource as RatingsFormula;

            if (previousFormula != null)
            {
                previousFormula.Options.SetToDefaults();
            }

            this.bsSelectedFormula.DataSource = (RatingsFormula)this.cmbFormula.SelectedItem;
            this.chkFOUseDefault.Checked      = true;
        }
Пример #3
0
 private int SortFormulas(RatingsFormula a, RatingsFormula b)
 {
     return(a.Name.CompareTo(b.Name));
 }
Пример #4
0
        public void CalculateRatings()
        {
            try
            {
                this.realDrivers = new RealDriverCollection();

                RatingsFormula formula = this.selectedFormula;

                foreach (DriverStats statAll in this.driverStatsByType["ALL"])
                {
                    RealDriver d = new RealDriver();


                    d.Number = statAll.CarNumber;

                    if (statAll.Driver != null)
                    {
                        d.FullName = statAll.Driver.Name;
                    }

                    if (this.CarListOnly == false)
                    {
                        //GET A DICTIONARY OF STATS (BY TRACKTYPE) FOR THIS DRIVER
                        Dictionary <string, DriverStats> singleDriverStatsByType = this.GetSingleDriverStatsByType(this.driverStatsByType, formula.Options.MappingMethod, statAll.CarNumber, statAll.Driver);

                        Dictionary <string, object> variables = new Dictionary <string, object>();


                        Type DriverStatsType = typeof(DriverStats); //USING REFLECTION TO MAP THE DRIVERSTATS PROPERTIES TO THE VARIABLES

                        //TRACKTYPE SPECIFIC VARIABLES
                        foreach (TrackType tt in trackTypes)
                        {
                            variables.Add("@countSelectedRaces" + tt.Id, this.selectedRacesInfo[tt.Id].Count);

                            foreach (string variable in FormulaVariableList.GetList())
                            {
                                string propertyName = variable.Replace("@", "").CapitilizeFirstChar();

                                PropertyInfo pi  = DriverStatsType.GetProperty(propertyName);
                                object       val = pi.GetValue(singleDriverStatsByType[tt.Id], null);

                                variables.Add(variable + tt.Id, val);
                            }
                        }

                        //VARIABLES FOR ALL TRACKTYPES
                        variables.Add("@countSelectedRaces", this.selectedRacesInfo["ALL"].Count);

                        foreach (string variable in FormulaVariableList.GetList())
                        {
                            string propertyName = variable.Replace("@", "").CapitilizeFirstChar();

                            PropertyInfo pi  = DriverStatsType.GetProperty(propertyName);
                            object       val = pi.GetValue(statAll, null);

                            variables.Add(variable, val);
                        }


                        d.Ratings = new Ratings();

                        d.Ratings.GetRating("dr_aggr").Min = this.EvalFormulaToInteger(formula.DriverAggressionMin, variables, "DriverAggressionMin", formula.IsProtected);
                        d.Ratings.GetRating("dr_aggr").Max = this.EvalFormulaToInteger(formula.DriverAggressionMax, variables, "DriverAggressionMax", formula.IsProtected);

                        d.Ratings.GetRating("dr_cons").Min = this.EvalFormulaToInteger(formula.DriverConsistencyMin, variables, "DriverConsistencyMin", formula.IsProtected);
                        d.Ratings.GetRating("dr_cons").Max = this.EvalFormulaToInteger(formula.DriverConsistencyMax, variables, "DriverConsistencyMax", formula.IsProtected);

                        d.Ratings.GetRating("dr_fin").Min = this.EvalFormulaToInteger(formula.DriverFinishingMin, variables, "DriverFinishingMin", formula.IsProtected);
                        d.Ratings.GetRating("dr_fin").Max = this.EvalFormulaToInteger(formula.DriverFinishingMax, variables, "DriverFinishingMax", formula.IsProtected);

                        d.Ratings.GetRating("dr_qual").Min = this.EvalFormulaToInteger(formula.DriverQualifyingMin, variables, "DriverQualifyingMin", formula.IsProtected);
                        d.Ratings.GetRating("dr_qual").Max = this.EvalFormulaToInteger(formula.DriverQualifyingMax, variables, "DriverQualifyingMax", formula.IsProtected);

                        d.Ratings.GetRating("dr_rc").Min = this.EvalFormulaToInteger(formula.DriverRoadCourseMin, variables, "DriverRoadCourseMin", formula.IsProtected);
                        d.Ratings.GetRating("dr_rc").Max = this.EvalFormulaToInteger(formula.DriverRoadCourseMax, variables, "DriverRoadCourseMax", formula.IsProtected);

                        d.Ratings.GetRating("dr_st").Min = this.EvalFormulaToInteger(formula.DriverShortTrackMin, variables, "DriverShortTrackMin", formula.IsProtected);
                        d.Ratings.GetRating("dr_st").Max = this.EvalFormulaToInteger(formula.DriverShortTrackMax, variables, "DriverShortTrackMax", formula.IsProtected);

                        d.Ratings.GetRating("dr_sw").Min = this.EvalFormulaToInteger(formula.DriverSpeedwayMin, variables, "DriverSpeedwayMin", formula.IsProtected);
                        d.Ratings.GetRating("dr_sw").Max = this.EvalFormulaToInteger(formula.DriverSpeedwayMax, variables, "DriverSpeedwayMax", formula.IsProtected);

                        d.Ratings.GetRating("dr_ss").Min = this.EvalFormulaToInteger(formula.DriverSuperSpeedwayMin, variables, "DriverSuperSpeedwayMin", formula.IsProtected);
                        d.Ratings.GetRating("dr_ss").Max = this.EvalFormulaToInteger(formula.DriverSuperSpeedwayMax, variables, "DriverSuperSpeedwayMax", formula.IsProtected);

                        d.Ratings.GetRating("veh_aero").Min = this.EvalFormulaToInteger(formula.VehicleAeroMin, variables, "VehicleAeroMin", formula.IsProtected);
                        d.Ratings.GetRating("veh_aero").Max = this.EvalFormulaToInteger(formula.VehicleAeroMax, variables, "VehicleAeroMax", formula.IsProtected);

                        d.Ratings.GetRating("veh_chas").Min = this.EvalFormulaToInteger(formula.VehicleChassisMin, variables, "VehicleChassisMin", formula.IsProtected);
                        d.Ratings.GetRating("veh_chas").Max = this.EvalFormulaToInteger(formula.VehicleChassisMax, variables, "VehicleChassisMax", formula.IsProtected);

                        d.Ratings.GetRating("veh_eng").Min = this.EvalFormulaToInteger(formula.VehicleEngineMin, variables, "VehicleEngineMin", formula.IsProtected);
                        d.Ratings.GetRating("veh_eng").Max = this.EvalFormulaToInteger(formula.VehicleEngineMax, variables, "VehicleEngineMax", formula.IsProtected);

                        d.Ratings.GetRating("veh_rel").Min = this.EvalFormulaToInteger(formula.VehicleReliabilityMin, variables, "VehicleReliabilityMin", formula.IsProtected);
                        d.Ratings.GetRating("veh_rel").Max = this.EvalFormulaToInteger(formula.VehicleReliabilityMax, variables, "VehicleReliabilityMax", formula.IsProtected);

                        d.Ratings.GetRating("pc_cons").Min = this.EvalFormulaToInteger(formula.PitcrewConsistencyMin, variables, "PitcrewConsistencyMin", formula.IsProtected);
                        d.Ratings.GetRating("pc_cons").Max = this.EvalFormulaToInteger(formula.PitcrewConsistencyMax, variables, "PitcrewConsistencyMax", formula.IsProtected);

                        d.Ratings.GetRating("pc_spe").Min = this.EvalFormulaToInteger(formula.PitcrewSpeedMin, variables, "PitcrewSpeedMin", formula.IsProtected);
                        d.Ratings.GetRating("pc_spe").Max = this.EvalFormulaToInteger(formula.PitcrewSpeedMax, variables, "PitcrewSpeedMax", formula.IsProtected);

                        d.Ratings.GetRating("pc_strat").Min = this.EvalFormulaToInteger(formula.PitcrewStrategyMin, variables, "PitcrewStrategyMin", formula.IsProtected);
                        d.Ratings.GetRating("pc_strat").Max = this.EvalFormulaToInteger(formula.PitcrewStrategyMax, variables, "PitcrewStrategyMax", formula.IsProtected);
                    }

                    this.realDrivers.Add(d);
                }

                this.realDrivers.Sort();
            }
            catch (Exception ex)
            {
                DataProcessingException dpEx = new DataProcessingException(ex.Message, this.selectedRaces, this.selectedFormula);
                this.dataProcessingException = dpEx;
            }
        }
Пример #5
0
        public void ComputeDriverStatsForEachTrackType()
        {
            try
            {
                this.selectedRacesInfo.Clear();
                this.driverStatsByType.Clear();

                RatingsFormula formula = this.selectedFormula;

                if (formula != null)
                {
                    List <RaceInfo> racesInfo = (from r in this.selectedRaces
                                                 select new RaceInfo
                    {
                        Race = r,
                        WinnerLaps = (from drd in driverRaceDataList
                                      where drd.Race.Id == r.Id &&
                                      drd.RaceResult != null &&
                                      drd.RaceResult.FinishPosition == 1
                                      select drd.RaceResult.Laps).FirstOrDefault(),
                        NumberOfStarters = (from drd in driverRaceDataList
                                            where drd.Race.Id == r.Id &&
                                            drd.RaceResult != null
                                            select drd.RaceResult).Count()
                    }).ToList();

                    this.selectedRacesInfo.Add("ALL", racesInfo);


                    List <DriverStats> statsAll = this.ComputeDriverStats(this.driverRaceDataList, racesInfo, formula.Options.MappingMethod);

                    this.driverStatsByType.Add("ALL", statsAll);

                    foreach (TrackType tt in trackTypes)
                    {
                        int countSelected;

                        List <DriverRaceData> driverRaceDataForSpecificType;
                        List <RaceInfo>       racesInfoForSpecificType;

                        if (formula.Options.UseNr2003TrackTypes == false)
                        {
                            driverRaceDataForSpecificType = (from drd in driverRaceDataList
                                                             where String.Equals(drd.Race.TrackTypeId, tt.Id)
                                                             select drd).ToList();

                            racesInfoForSpecificType = (from ri in racesInfo
                                                        where String.Equals(ri.Race.TrackTypeId, tt.Id)
                                                        select ri).ToList();

                            countSelected = racesInfoForSpecificType.Count;
                        }
                        else
                        {
                            driverRaceDataForSpecificType = (from drd in driverRaceDataList
                                                             where String.Equals(drd.Race.NR2003TrackTypeId, tt.Id)
                                                             select drd).ToList();

                            racesInfoForSpecificType = (from ri in racesInfo
                                                        where String.Equals(ri.Race.NR2003TrackTypeId, tt.Id)
                                                        select ri).ToList();

                            countSelected = racesInfoForSpecificType.Count;
                        }

                        this.selectedRacesInfo.Add(tt.Id, racesInfoForSpecificType);


                        List <DriverStats> stats = this.ComputeDriverStats(driverRaceDataForSpecificType, racesInfoForSpecificType, formula.Options.MappingMethod);

                        var nonFoundDriversForThisTrackType = from s in statsAll
                                                              where stats.Contains(s, new DriverStatsComparerByNumberAndName()) == false
                                                              select s;

                        foreach (DriverStats ds in nonFoundDriversForThisTrackType)
                        {
                            DriverStats nonFoundDriver = new DriverStats();
                            nonFoundDriver.CarNumber = ds.CarNumber;
                            nonFoundDriver.Driver    = ds.Driver;

                            stats.Add(nonFoundDriver);
                        }

                        this.driverStatsByType.Add(tt.Id, stats);
                    }
                }
            }
            catch (Exception ex)
            {
                DataProcessingException dpEx = new DataProcessingException(ex.Message, this.selectedRaces, this.selectedFormula);
                this.dataProcessingException = dpEx;
            }
        }