private RealDriverCollection MapRealDataToCars(RealDriverCollection RealDrivers, CarMappingMethod mappingMethod) { if (this.bsCars.DataSource != null) { CarCollection colCars = (CarCollection)this.bsCars.DataSource; foreach (NR2003Car c in colCars) { RealDriver foundDriver = null; switch (mappingMethod) { case CarMappingMethod.NAME: foundDriver = RealDrivers.FindByName(c.DriverFirstName, c.DriverLastName); break; case CarMappingMethod.NUMBER: foundDriver = RealDrivers.FindByNumber(c.Number); break; case CarMappingMethod.NUMBER_AND_NAME: foundDriver = RealDrivers.FindByNumberAndName(c.Number, c.DriverFirstName, c.DriverLastName); break; } if (foundDriver != null) { c.MappedToRealDriver = foundDriver; c.Selected = true; foundDriver.MatchFound = true; } } return(RealDrivers); } else { return(null); } }
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; } }