public string GetLastLap([FromQuery(Name = "token")] string token, string identifier) { try { SessionManager sessionManager = new SessionManager(Server.TeamServer.ObjectManager, Server.TeamServer.TokenIssuer.ValidateToken(token)); Session session = sessionManager.LookupSession(identifier); Stint stint = session.GetCurrentStint(); if (stint != null) { Lap lap = stint.GetCurrentLap(); if (lap != null) { return(lap.Identifier.ToString()); } else if (stint.Nr > 1) { lap = sessionManager.LookupStint(session, stint.Nr - 1).GetCurrentLap(); if (lap != null) { return(lap.Identifier.ToString()); } } } return(""); } catch (Exception exception) { return("Error: " + exception.Message); } }
public void ValidateStint(Stint stint) { if (stint == null) { throw new Exception("Not a valid stint..."); } }
public Stint CreateStint(Session session, Driver driver, int lap) { ValidateSession(session); ValidateDriver(driver); Task <List <Stint> > task = ObjectManager.Connection.QueryAsync <Stint>( @" Select * From Stints Where SessionID = ? And DriverID = ? And Lap = ? ", session.ID, driver.ID, lap); if (task.Result.Count == 0) { Stint lastStint = session.GetCurrentStint(); int stintNr = (lastStint != null) ? lastStint.Nr + 1 : 1; Stint stint = new Stint { SessionID = session.ID, DriverID = driver.ID, Nr = stintNr, Lap = lap }; stint.Save(); return(stint); } else { return(task.Result[0]); } }
public void DeleteStint(Stint stint) { if (stint != null) { stint.Delete(); } }
public Stint LookupStint(Guid identifier) { Stint stint = FindStint(identifier); ValidateStint(stint); return(stint); }
public Stint LookupStint(Session session, int stintNr) { Stint stint = FindStint(session, stintNr); ValidateStint(stint); return(stint); }
public void ValidateLap(Stint stint, Lap lap) { ValidateStint(stint); if (lap == null) { throw new Exception("Not a valid lap..."); } }
public void ValidateStint(Session session, Stint stint) { ValidateSession(session); if (stint == null) { throw new Exception("Not a valid stint..."); } }
public void CollectAndProcessData(Session session) { string lineInput = ""; int lineNumber = 0; int lapNo = 0; //number of laps in driver's stint int lineStatus = 0; //0 is no numbers read, 1 is reading, 2 is finished reading int driverIndex = -1; int driverNumber; int readStatus = 0; int sessionIndex = session.GetSessionIndex(); Stint tempStint; do //terminates when file ends. { if (lineStatus == 0) { lineInput = GetNextLineToInput(lineNumber++, FileData); } if (NameCheck(lineInput, out driverNumber) == true) { lapNo = 0; lineStatus = 0; driverIndex = Driver.ConvertToDriverIndex(driverNumber); DriverWeekendStints[driverIndex].Clear(); tempStint = new Stint(sessionIndex, lapNo); readStatus = 1; do { lineInput = GetNextLineToInput(lineNumber++, FileData); if (GetNumber(lineInput, 0) == lapNo++) { UseTimeData(lineInput, lapNo - 1, driverIndex, sessionIndex, ref readStatus, ref tempStint); } else { lineStatus++; } } while (lineStatus != 2); //exits when times are finished if (tempStint.lapTimes.Count != 0) { DriverWeekendStints[driverIndex] += tempStint; } } else { if (lineStatus == 2) { lineInput = GetNextLineToInput(lineNumber++, FileData); } } //end if } while (lineInput != null); }
public RaceBuilder AddDefaultMiddleStint() { Stint stint = new Stint() { RNGMinimum = 10, RNGMaximum = 40 }; _race.Stints.Add(stint); return(this); }
public string Get([FromQuery(Name = "token")] string token, string identifier) { try { SessionManager sessionManager = new SessionManager(Server.TeamServer.ObjectManager, Server.TeamServer.TokenIssuer.ValidateToken(token)); Stint stint = sessionManager.LookupStint(identifier); return(ControllerUtils.SerializeObject(stint, new List <string>(new string[] { "Identifier", "Nr", "Lap" }))); } catch (Exception exception) { return("Error: " + exception.Message); } }
public RaceBuilder AddDefaultCloseStint() { Stint stint = new Stint() { ApplyReliability = true, RNGMinimum = 10, RNGMaximum = 45 }; _race.Stints.Add(stint); return(this); }
public string GetLap([FromQuery(Name = "token")] string token, string identifier) { try { SessionManager sessionManager = new SessionManager(Server.TeamServer.ObjectManager, Server.TeamServer.TokenIssuer.ValidateToken(token)); Stint stint = sessionManager.LookupStint(identifier); Lap lap = stint.GetCurrentLap(); return((lap != null) ? lap.Identifier.ToString() : "Null"); } catch (Exception exception) { return("Error: " + exception.Message); } }
public void ReadFromFile(string fileName) { int driverIndex = 0; int stintIndex = 0; int startLap, length; TyreType tyreType; string driverName; List <Stint> listOfStintsToAdd = new List <Stint>(); Stint tempStint = new Stint(); StreamReader s = new StreamReader(fileName); //read titles to remove. s.ReadLine(); stintIndex = 0; listOfStintsToAdd.Clear(); while (!s.EndOfStream) { string[] inputData = s.ReadLine().Split(','); driverName = inputData[0]; startLap = int.Parse(inputData[1]); length = int.Parse(inputData[2]); if (inputData[3] == "Prime") { tyreType = TyreType.Prime; } else { tyreType = TyreType.Option; } if (driverName != Data.Drivers[driverIndex].DriverName) { fileData[driverIndex] = new Strategy(listOfStintsToAdd); driverIndex++; stintIndex = 0; listOfStintsToAdd.Clear(); } tempStint = new Stint(startLap, tyreType, length); listOfStintsToAdd.Add(tempStint); stintIndex++; } fileData[driverIndex] = new Strategy(listOfStintsToAdd); }
public RaceBuilder AddDefaultStartStint() { Stint stint = new Stint() { ApplyChassisLevel = true, ApplyDriverLevel = true, ApplyEngineLevel = true, ApplyQualifyingBonus = true, RNGMinimum = 10, RNGMaximum = 35 }; _race.Stints.Add(stint); return(this); }
public string Post([FromQuery(Name = "token")] string token, [FromQuery(Name = "stint")] string stint, [FromBody] string keyValues) { try { Token theToken = Server.TeamServer.TokenIssuer.ValidateToken(token); SessionManager sessionManager = new SessionManager(Server.TeamServer.ObjectManager, theToken); Stint theStint = sessionManager.LookupStint(stint); Dictionary <string, string> properties = ControllerUtils.ParseKeyValues(keyValues); return(sessionManager.CreateLap(theStint, lap: Int32.Parse(properties["Nr"])).Identifier.ToString()); } catch (Exception exception) { return("Error: " + exception.Message); } }
public string GetSessionStintValue([FromQuery(Name = "token")] string token, string identifier, int stint, [FromQuery(Name = "name")] string name) { try { SessionManager sessionManager = new SessionManager(Server.TeamServer.ObjectManager, Server.TeamServer.TokenIssuer.ValidateToken(token)); Stint theStint = Server.TeamServer.ObjectManager.Connection.QueryAsync <Stint>( @" Select * From Stints Where SessionID In (Select ID From Sessions Where Identifier = ?) And Nr = ? ", identifier, stint).Result.FirstOrDefault <Stint>(); return(sessionManager.GetStintValue(theStint, name)); } catch (Exception exception) { return("Error: " + exception.Message); } }
public string GetStint([FromQuery(Name = "token")] string token, string identifier, [FromQuery(Name = "stint")] string stint) { try { Server.TeamServer.TokenIssuer.ValidateToken(token); int stintNr = Int32.Parse(stint); Stint theStint = Server.TeamServer.ObjectManager.Connection.QueryAsync <Stint>( @" Select * From Stints Where SessionID In (Select ID From Sessions Where Identifier = ?) And Nr = ? ", identifier, stint).Result.FirstOrDefault <Stint>(); return((theStint != null) ? theStint.Identifier.ToString() : "Null"); } catch (Exception exception) { return("Error: " + exception.Message); } }
void UseTimeData(string time, int lapNo, int driverIndex, int sessionIndex, ref int readStatus, ref Stint tempStint) { float lapTime; //readStatus - 0: waiting for start, 1: out-lap, 2: add lap to stint. time = time.Remove(0, (lapNo >= 10 ? 3 : 2)); //takes away the lap number if (time[0] == 'P') { time = time.Remove(0, 2); //removes the 'P' if (readStatus == 2) { //pass old stint DriverWeekendStints[driverIndex] += tempStint; //start new tempStint tempStint = new Stint(sessionIndex, lapNo); } //get ready to read new stint readStatus = 0; } //load the lap time from a string lapTime = GetLapTime(time); if (readStatus == 2) //if reading { //adds lap time to stint tempStint += lapTime; } else { //increments readStatus if not already reading readStatus++; } }
public Lap CreateLap(Stint stint, int lap) { ValidateStint(stint); Task <List <Lap> > task = ObjectManager.Connection.QueryAsync <Lap>( @" Select * From Laps Where StintID = ? And Nr = ? ", stint.ID, lap); if (task.Result.Count == 0) { Lap theLap = new Lap { SessionID = stint.Session.ID, StintID = stint.ID, Nr = lap }; theLap.Save(); return(theLap); } else { return(task.Result[0]); } }
public async Task <int> CreateCopyOfLastSeason(int championshipID) { var newSeason = new Season(); var lastSeason = await Data.AsNoTracking() .Where(e => e.ChampionshipId == championshipID) .Include(e => e.Championship) .OrderByDescending(e => e.SeasonNumber) .FirstOrDefaultAsync(); if (lastSeason != null) { var lastRaces = await Context.Races .Where(e => e.SeasonId == lastSeason.SeasonId) .Include(e => e.Stints) .ToListAsync(); foreach (var pos in lastSeason.PointsPerPosition) { newSeason.PointsPerPosition.Add(pos); } newSeason.PolePoints = lastSeason.PolePoints; newSeason.QualificationRemainingDriversQ2 = lastSeason.QualificationRemainingDriversQ2; newSeason.QualificationRemainingDriversQ3 = lastSeason.QualificationRemainingDriversQ3; newSeason.QualificationRNG = lastSeason.QualificationRNG; newSeason.QualyBonus = lastSeason.QualyBonus; newSeason.SeasonNumber = (lastSeason.SeasonNumber + 1); newSeason.PitMax = lastSeason.PitMax; newSeason.PitMin = lastSeason.PitMin; foreach (var race in lastRaces.OrderBy(e => e.Round)) { var track = Context.Tracks.SingleOrDefaultAsync(e => e.Id == race.TrackId); var stints = new List <Stint>(); foreach (var lastStint in race.Stints.OrderBy(e => e.Number)) { var stint = new Stint { Number = lastStint.Number, ApplyDriverLevel = lastStint.ApplyDriverLevel, ApplyChassisLevel = lastStint.ApplyChassisLevel, ApplyEngineLevel = lastStint.ApplyEngineLevel, ApplyQualifyingBonus = lastStint.ApplyQualifyingBonus, ApplyReliability = lastStint.ApplyReliability, RNGMaximum = lastStint.RNGMaximum, RNGMinimum = lastStint.RNGMinimum }; stints.Add(stint); } var newRace = _raceBuilder .InitializeRace(await track, newSeason) .AddModifiedStints(stints) .GetResultAndRefresh(); newSeason.Races.Add(newRace); } } newSeason.ChampionshipId = championshipID; await Add(newSeason); await SaveChangesAsync(); return(newSeason.SeasonId); }
public void ReadFromFile(Session session, string fileName) { if (File.Exists(fileName)) { string line = ""; string[] lineParts; float lapTime = 0; int lapType = 0; int lapNumber = 0; int returnedDriverIndex = -1; int driverIndex = -1; int sessionIndex = session.GetSessionIndex(); Stint tempStint = null; StreamReader r = new StreamReader(fileName); do { line = r.ReadLine(); if (IsDriverName(line, out returnedDriverIndex)) { driverIndex = returnedDriverIndex; if (driverIndex - 1 >= 0 && tempStint != null && tempStint.lapTimes.Count > 0) { DriverWeekendStints[driverIndex - 1] += tempStint; } lapNumber = 0; DriverWeekendStints[driverIndex].Clear(); tempStint = new Stint(sessionIndex, lapNumber); } else { lineParts = line.Split(','); if (lineParts.Length == 2) { if (lineParts[0] != "") { lapTime = float.Parse(lineParts[0]); } if (lineParts[1] != "") { lapType = int.Parse(lineParts[1]); } } lapNumber++; if (lapType == 1 && tempStint != null) { tempStint += lapTime; } if (lapType == 2 && tempStint != null && tempStint.lapTimes.Count > 0) { DriverWeekendStints[driverIndex] += tempStint; tempStint = new Stint(sessionIndex, lapNumber); } } } while (!r.EndOfStream); r.Dispose(); } }
/// <summary> /// Gets the points result of a single <see cref="StintResult"/>, with any enabled <see cref="StintResult"/> modifiers applied. /// </summary> /// <param name="stint">The <see cref="Stint"/> supplying the modifiers to use.</param> /// <param name="driverResult">The partial <see cref="DriverResult"/> from which to derive certain modifiers.</param> public void UpdateStintResult(StintResult stintResult, Stint stint, DriverResult driverResult, SeasonTeam team, Weather weather, Specification trackSpec, int driverCount, int qualyBonus, int pitMin, int pitMax, AppConfig appConfig) { if (stintResult is null || driverResult is null || stint is null || team is null || appConfig is null) { throw new NullReferenceException(); } // Applies the increased or decreased odds for the specific track. double engineWeatherMultiplier = 1; int weatherRNG = 0; int weatherDNF = 0; var driver = driverResult.SeasonDriver; stintResult.StintStatus = StintStatus.Running; switch (weather) { case Weather.Sunny: engineWeatherMultiplier = appConfig.SunnyEngineMultiplier; break; case Weather.Overcast: engineWeatherMultiplier = appConfig.OvercastEngineMultiplier; break; case Weather.Rain: weatherRNG += appConfig.RainAdditionalRNG; weatherDNF += appConfig.RainDriverReliabilityModifier; engineWeatherMultiplier = appConfig.WetEngineMultiplier; break; case Weather.Storm: weatherRNG += appConfig.StormAdditionalRNG; weatherDNF += appConfig.StormDriverReliabilityModifier; engineWeatherMultiplier = appConfig.WetEngineMultiplier; break; } if (stint.ApplyReliability) { // Check for the reliability of the chassis. if (GetReliabilityResult(team.Reliability + driverResult.ChassisRelMod) == -1) { stintResult.StintStatus = StintStatus.ChassisDNF; } // Check for the reliability of the driver. else if (GetReliabilityResult(driver.Reliability + weatherDNF + driverResult.DriverRelMod) == -1) { stintResult.StintStatus = StintStatus.DriverDNF; if (driver.SeasonDriverId == 1894) { stintResult.StintStatus = StintStatus.DriverDNF; } } } if (stintResult.StintStatus == StintStatus.Running || stintResult.StintStatus == StintStatus.Mistake) { // Add one because Random.Next() has an exclusive upper bound. int result = _rng.Next(stint.RNGMinimum + driverResult.MinRNG, stint.RNGMaximum + weatherRNG + driverResult.MaxRNG + 1); // Iterate through GetReliabilityResult twice to check if a driver made a mistake or not, requires two consequential true's to return a mistake bool mistake = false; for (int i = 0; i < appConfig.MistakeAmountRolls; i++) { mistake = GetReliabilityResult(driver.Reliability + weatherDNF + driverResult.DriverRelMod) == -1; if (!mistake) { break; } } // If the bool mistake is true then we have to subtract from the result if (mistake) { result += _rng.Next(appConfig.MistakeLowerValue, appConfig.MistakeUpperValue); stintResult.StintStatus = StintStatus.Mistake; } // In here we loop through the strategy of the driver to see if it is time for a pitstop foreach (var tyreStrat in driverResult.Strategy.Tyres.OrderBy(t => t.StintNumberApplied)) { // The value for the tyre in iteration matches the current stint number, so it is time for a pitstop if (tyreStrat.StintNumberApplied == stint.Number && stint.Number != 1) { driverResult.TyreLife = tyreStrat.Tyre.Pace; driverResult.CurrTyre = tyreStrat.Tyre; stintResult.Pitstop = true; } } // Current status tells us there is a pitstop so calculate pitstop RNG over the result if (stintResult.Pitstop) { result += _rng.Next(pitMin, pitMax + 1); } // Deals with the tyre wear for this driver and changes tyres if it is needed result += driverResult.TyreLife; // Current status tells us the driver is still running so we apply some of the wear to the tyre driverResult.TyreLife += _rng.Next(driverResult.CurrTyre.MaxWear + driverResult.MaxTyreWear, driverResult.CurrTyre.MinWear + driverResult.MinTyreWear); // Applies the qualifying bonus based on the amount of drivers for the current stint if (stint.ApplyQualifyingBonus) { result += Helpers.GetQualifyingBonus(driverResult.Grid, driverCount, qualyBonus); } // Applies the quality of the driver to the current stint if it is relevant if (stint.ApplyDriverLevel) { result += driver.Skill + driverResult.DriverRacePace; } // Applies the power of the chassis to the result when it applies if (stint.ApplyChassisLevel) { int bonus = Helpers.GetChassisBonus(Helpers.CreateTeamSpecDictionary(team), trackSpec.ToString()); int statusBonus = 0; if (driver.DriverStatus == DriverStatus.First) { statusBonus = appConfig.ChassisModifierDriverStatus; } else if (driver.DriverStatus == DriverStatus.Second) { statusBonus = (appConfig.ChassisModifierDriverStatus * -1); } result += team.Chassis + driverResult.ChassisRacePace + bonus + statusBonus; } // Applies the power of the engine plus external factors when it is relevant for the current stint if (stint.ApplyEngineLevel) { result += (int)Math.Round((team.Engine.Power + driverResult.EngineRacePace) * engineWeatherMultiplier); } // Finally adds the result of the stint to the stintresult stintResult.Result = result; } }
public string GetStintValue(Stint stint, string name) { ValidateStint(stint); return(ObjectManager.GetAttribute(stint, name)); }
public void DeleteStintValue(Stint stint, string name) { ValidateStint(stint); ObjectManager.DeleteAttribute(stint, name); }
public void SetStintValue(Stint stint, string name, string value) { ValidateStint(stint); ObjectManager.SetAttribute(stint, name, value); }