public frmDriverRatings(RealDriverCollection realDriverCollection) { InitializeComponent(); this.MaximizeBox = true; //string title; //if (race.RaceName != null) // title = race.RaceName + " (" + race.Track.Name + ")"; //else // title = race.Track.Name; //this.lblRace.Text = "LoopData for " + race.RaceDate.ToShortDateString() + ", " + title; this.CreateRatingsColumns(); this.bsRealDrivers.DataSource = realDriverCollection; }
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; } }
private async void butImportRatings_Click(object sender, EventArgs e) { bool showImportDialog = true; if (this.colCars.IsDirty == true) { DialogResult sure = MessageBox.Show("You have unsaved changes in your carlist. If you import ratings from real life data, you may possibly overwrite these changes. Are you sure you want to continue ?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (sure == DialogResult.No) { showImportDialog = false; } } if (showImportDialog) { var result = await UserManager.LoginAsync(this); if (result != null && !result.Succeeded) { MessageBox.Show(result.Error, "Login unsuccessful", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (await UserManager.IsLoggedInAsync()) { if (!UserManager.IsEmailVerified() == true) { MessageBox.Show("You'll need to verify your email address before you can proceed. Please check your mails.", "Email Verification Required", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else if (UserManager.IsEmailVerified() == true) { frmGetRealData fRealData = new frmGetRealData(); DialogResult dres = fRealData.ShowDialog(); if (dres == DialogResult.OK) { ////START FROM A BLANK CARLIST //this.colCars.IsDirty = false; //set to false to avoid confirmation dialog //this.LoadCarList(); RealDriverCollection RealDrivers = fRealData.RealDrivers; CarMappingMethod mappingMethod = fRealData.MappingMethod; bool rosterOnly = fRealData.CarListOnly; //IF THE "ROSTER ONLY" CHECKBOX WAS CHECKED, DON'T ALLOW TO MANUALLY REMAP TO ANOTHER REAL LIFE DRIVER (THERE'S NO SENSE ANYWAY) if (rosterOnly == true) { this.dgCars.Columns["mappedToRealDriverDataGridViewComboBoxColumn"].ReadOnly = true; } else { this.dgCars.Columns["mappedToRealDriverDataGridViewComboBoxColumn"].ReadOnly = false; } if (RealDrivers != null) { this.mainProc.RealDrivers = this.MapRealDataToCars(RealDrivers, mappingMethod); this.LogUnmappedDrivers(); } this.dgCars.Focus(); this.dgCars.Refresh(); if (this.dgCars.Rows.Count > 0) { this.dgCars.Rows[0].Selected = true; this.dgCars_SelectionChanged(null, null); } } } } } }