private static void ReEvaluate(WeekendInfo previous, WeekendInfo current, AbstractScoring scoring) { if (current == null) { throw new ArgumentNullException(); } if (scoring == null) { throw new ArgumentNullException(); } if (current.Weekend.Race.IsEmpty()) { throw new ArgumentException(); } Weekend weekend = current.Weekend; RaceSession race = weekend.Race; var poss = race.Positions.GetLastLap(); weekend.Points.Clear(); PrepareNewStandings(previous, current); Dictionary <Driver, TempData> tmp = CalculateTempData(poss); foreach (var item in poss) { UpdateNewDriverStandingsByNewRace(previous, current, scoring, weekend, race, tmp, item); } OrderDriverStandingsByPointsAndAssignPosition(current); }
private static void FillSession(RaceSession session, List <ENG.NR2003.TelemetryEvents.TelemetryEvent> list) { if (session == null) { throw new ArgumentNullException(); } if (list == null) { throw new ArgumentNullException(); } if (session.IsEmpty() == false) { throw new ArgumentException("Cannot fill non-empty session."); } EventFiller ef = new EventFiller(); Type t = typeof(EventFiller); foreach (var item in list) { System.Reflection.MethodInfo mi = t.GetMethod("Fill", new Type[] { session.GetType(), item.GetType() }); mi.Invoke(ef, new object[] { session, item }); } session.EvaluateLapsAndBuildPositions(); session.RegisterPitLaps(); session.EvaluateYellowPhasesLaps(); }
public void Fill(RaceSession session, DriverEntry te) { if (te.IsPaceCar) { return; } int carIdx = te.CarIdx; Driver d = session.Weekend.Season.Drivers.TryGetBestBy(te.CarNum, te.Name); if (d == null) { d = Driver.Create(te.CarNum, te.Name); session.Weekend.Season.Drivers.Add(d); } if (session.Weekend.Drivers.ContainsKey(carIdx)) { Driver existing = session.Weekend.Drivers[carIdx]; if (existing.Number != d.Number || existing.NameSurname != d.NameSurname) { throw new Exception("The driver names with same number between sessions differs, which is not allowed in one race weekend."); } } else { session.Weekend.Drivers.Add(carIdx, d); } }
public async Task <EntityState> Update(string id, RaceSession raceSession) { using (ApplicationDbContext db = new ApplicationDbContext()) { db.Entry(raceSession).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (db.RaceSessions.Count(e => e.Id == id) == 0) { return(EntityState.Unchanged); } else { throw; } } return(db.Entry(raceSession).State); } }
public void Fill(RaceSession session, CurrentWeekend te) { if (te.AtTrack == false) { return; } FillOrCheckCurrentWeekend(session, te); }
public async Task <IHttpActionResult> DeleteRaceSession(string id) { RaceSession raceSession = await repo.Delete(id); if (raceSession == null) { return(NotFound()); } return(Ok(Mapper.Map <RaceSessionDTO>(raceSession))); }
public async Task <RaceSession> Insert(RaceSession raceSession) { using (ApplicationDbContext db = new ApplicationDbContext()) { raceSession.Id = string.IsNullOrEmpty(raceSession.Id) ? Guid.NewGuid().ToString() : raceSession.Id; raceSession = db.RaceSessions.Add(raceSession); await db.SaveChangesAsync(); } return(raceSession); }
private bool HasOpenedYellowSession(RaceSession session) { if (session.Yellows.Count == 0) { return(false); } if (session.Yellows[session.Yellows.Count - 1].IsValid() == false) { return(true); } return(false); }
public override Task OnNavigatedToAsync(object parameter, NavigationMode mode) { if (parameter == null) { SimpleIoc.Default.GetInstance <NavigationServiceEx>().Navigate(typeof(MainViewModel).FullName); } else { this.session = parameter as RaceSession; } return(Task.CompletedTask); }
public async Task <IHttpActionResult> PostRaceSession(RaceSessionDTO raceSessionDTO) { RaceSession raceSession = Mapper.Map <RaceSession>(raceSessionDTO); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } raceSession = await repo.Insert(raceSession); return(CreatedAtRoute("DefaultApi", new { id = raceSession.Id }, Mapper.Map <RaceSessionDTO>(raceSession))); }
public RaceHUDViewModel() { RaceType defaultRaceType = new RaceType( RaceTypesEnum.FreePlay, "Free Play", "Players drive for the fun of it - no limit and no rules!", 999, false, false, 0, Symbol.Play); this.session = new RaceSession(defaultRaceType, new ObservableCollection <Driver>()); this.RaceButtonBrush = this.greenBrush; this.IsRacePaused = true; }
public RaceSessionView(RaceSession rs, int lapNumber) { if (rs.IsEmpty()) { return; } var laps = rs.Positions[lapNumber]; for (int i = 0; i < laps.Count; i++) { // pits only lower than current lap RacePit[] pits = rs.PitLaps.Get(laps[i].Driver); Item item = new Item(laps, i, pits, rs); inner.Add(item); } }
public void Fill(RaceSession session, SessionInfo te) { if (te.SessionFlag == SessionInfo.eSessionFlag.kFlagGreen) { if (HasOpenedYellowSession(session)) { session.Yellows[session.Yellows.Count - 1].EndTime = Time.CreateFromSeconds(te.CurrentTime); } } else if (te.SessionFlag == SessionInfo.eSessionFlag.kFlagYellow) { if (HasOpenedYellowSession(session) == false) { YellowPhase yp = new YellowPhase(); yp.StartTime = Time.CreateFromSeconds(te.CurrentTime); session.Yellows.Add(yp); } } }
public void Fill(RaceSession session, Standings te) { if (te.IsOfficial == false) { return; } foreach (var item in te.Positions) { if (item.CarIdx == -1) { continue; } Driver d = session.Weekend.Drivers[item.CarIdx]; session.Positions.SetDriverFinalStatus(d, ConvertTelemetryEnumToAppEnum(item.ReasonOut)); } }
public void RaceSessionDTO_Test() { // Act RaceSessionDTO raceSessionDTO = Mapper.Map <RaceSessionDTO>(raceSession); RaceSession testRaceSession = Mapper.Map <RaceSession>(raceSessionDTO); //Assert Assert.AreEqual(raceSession.EndTime, raceSessionDTO.EndTime); Assert.AreEqual(raceSession.Id, raceSessionDTO.Id); Assert.AreEqual(raceSession.NumberOfDrivers, raceSessionDTO.NumberOfDrivers); Assert.AreEqual(raceSession.RaceTypeId, raceSessionDTO.RaceTypeId); Assert.AreEqual(raceSession.StartTime, raceSessionDTO.StartTime); Assert.AreEqual(raceSession.TrackId, raceSessionDTO.TrackId); Assert.AreEqual(raceSession.EndTime, testRaceSession.EndTime); Assert.AreEqual(raceSession.Id, testRaceSession.Id); Assert.AreEqual(raceSession.NumberOfDrivers, testRaceSession.NumberOfDrivers); Assert.AreEqual(raceSession.RaceTypeId, testRaceSession.RaceTypeId); Assert.AreEqual(raceSession.StartTime, testRaceSession.StartTime); Assert.AreEqual(raceSession.TrackId, testRaceSession.TrackId); }
public Item(List <RaceLap> laps, int i, RacePit [] pits, RaceSession rs) { RaceLap lap = laps[i]; pits = pits.Where(k => k.LapNumber <= lap.LapNumber).ToArray(); this.Driver = lap.Driver.NameSurname; this.Number = lap.Driver.Number; this.Position = lap.CurrentPosition; if (i == 0) { this.GapToFirst = RaceGap.Empty; this.GapToPrevious = RaceGap.Empty; } else { RaceLap prev = laps[i - 1]; this.GapToFirst = new RaceGap(laps[0], lap); this.GapToPrevious = new RaceGap(laps[i - 1], lap); } this.LapCount = lap.LapNumber; this.State = rs.Positions.GetDriverFinalStatus(lap.Driver).ToString(); this.LapsInLead = GetLapsInLead(lap); this.PitCount = pits.Length; this.BestTime = GetBestTime(lap); this.MeanTime = GetMeanTime(lap); this.MeanTimePY = GetMeanTimePY(lap); this.WorstTime = GetWorstTime(lap); this.BestPitTime = GetBestPitTime(pits); this.MeanPitTime = GetMeanPitTime(pits); this.WorstPitTime = GetWorstPitTime(pits); this.BestPosition = GetBestPositionSoFar(lap); this.WorstPosition = GetWorstPositionSoFar(lap); this.PitInLaps = GetPitLapsAsString(pits); this.MaxGainPerLap = GetMaxGainPerLap(lap); this.MaxLoosePerLap = GetMaxLoosePerLap(lap); this.BlackFlags = lap.Sum(k => k.IsBlackFlagged ? 1 : 0, k => k.PreviousLapAsRaceLap); }
public RaceForChartSessionView(RaceSession rs) { int lapCount = rs.Weekend.Settings.RaceLapCount; if (rs.IsEmpty()) { return; } for (int lapNumber = 1; lapNumber <= lapCount; lapNumber++) { var laps = rs.Positions[lapNumber]; for (int i = 0; i < laps.Count; i++) { // pits only lower than current lap RacePit[] pits = rs.PitLaps.Get(laps[i].Driver); Item item = new Item(laps, i, pits, rs); inner.Add(item); } } }
public void Fill(RaceSession session, LapCrossing te) { int carIdx = te.CarIdx; if (session.Weekend.Drivers.ContainsKey(carIdx) == false) { throw new ApplicationException("Failed to find driver with carIdx " + carIdx + " in registered drivers of weekend."); } Driver d = session.Weekend.Drivers[carIdx]; RaceLap l = new RaceLap(); l.Driver = d; l.CrossedAtTime = Time.CreateFromSeconds(te.CrossedAt); if (l.CrossedAtTime.TotalMiliseconds < 0) { throw new ApplicationException("CrossedAt below zero."); } l.IsBlackFlagged = te.IsBlackFlagged; l.IsOffTrack = te.IsOffTrack; l.IsPitted = te.IsPitted; session.Laps.Add(l); }
public void Initialize() { if (!automapperIntialised) { Mapper.Initialize(cfg => { cfg.CreateMap <RaceSession, RaceSessionDTO>() .ReverseMap() .ForMember(src => src.DriverResults, opt => opt.Ignore()) .ForMember(src => src.RaceType, opt => opt.Ignore()) .ForMember(src => src.Track, opt => opt.Ignore()); cfg.CreateMap <DriverResult, DriverResultDTO>() .ForMember(dest => dest.DriverId, opt => opt.MapFrom(src => src.ApplicationUserId)) .ReverseMap() .ForMember(dest => dest.ApplicationUserId, opt => opt.MapFrom(src => src.DriverId)); cfg.CreateMap <Track, TrackDTO>() .ForPath(dest => dest.RecordHolder, opt => opt.MapFrom(src => src.BestLapTime == null ? "No Record set" : src.BestLapTime.ApplicationUser.UserName)) .ForPath(dest => dest.TrackRecord, opt => opt.MapFrom(src => src.BestLapTime == null ? new System.TimeSpan(0, 0, 59) : src.BestLapTime.LapTime.Time)) .ReverseMap() .ForMember(src => src.BestLapTimeId, opt => opt.Ignore()) .ForMember(src => src.ApplicationUsers, opt => opt.Ignore()) .ForMember(src => src.Cars, opt => opt.Ignore()); cfg.CreateMap <Car, CarDTO>() .ForPath(dest => dest.RecordHolder, opt => opt.MapFrom(src => src.BestLapTime == null ? "No Record set" : src.BestLapTime.ApplicationUser.UserName)) .ForPath(dest => dest.TrackRecord, opt => opt.MapFrom(src => src.BestLapTime == null ? new System.TimeSpan(0, 0, 59) : src.BestLapTime.LapTime.Time)) .ReverseMap() .ForPath(src => src.BestLapTimeId, opt => opt.Ignore()); cfg.CreateMap <RaceType, RaceTypeDTO>(); cfg.CreateMap <Driver, DriverDTO>() .ForPath(dest => dest.UserId, opt => opt.MapFrom(src => src.ApplicationUser.Id)) .ForPath(dest => dest.UserName, opt => opt.MapFrom(src => src.ApplicationUser.UserName)) .ForPath(dest => dest.ImageName, opt => opt.MapFrom(src => src.ApplicationUser.ImageName)) .ForMember(dest => dest.SelectedCar, opt => opt.MapFrom(src => src.Car)) .ReverseMap() .ForMember(src => src.ApplicationUserId, opt => opt.MapFrom(dest => dest.UserId)) .ForPath(src => src.ApplicationUser, opt => opt.Ignore()) .ForPath(src => src.Track, opt => opt.Ignore()) .ForMember(src => src.Car, opt => opt.MapFrom(dest => dest.SelectedCar)); cfg.CreateMap <LapTime, LapTimeDTO>() .ReverseMap() .ForMember(src => src.DriverResult, opt => opt.Ignore()); }); automapperIntialised = true; } user = new ApplicationUser(); user.Id = driverId.ToString(); user.UserName = recordHolderName; user.ImageName = imageName; raceType = new RaceType(); raceType.Id = raceTypeId; raceType.Name = raceTypeName; raceType.Rules = raceTypeRules; raceType.Symbol = raceTypeSymbol; laptime = new LapTime(); laptime.Id = "1"; laptime.DriverResultId = driverResultId; laptime.LapNumber = lapNumber; laptime.Time = trackRecord; bestLapTime = new BestLapTime(); bestLapTime.ApplicationUserId = user.Id.ToString(); bestLapTime.ApplicationUser = user; bestLapTime.LapTime = laptime; bestLapTime.CarId = carId; bestLapTime.LapTimeId = laptime.Id; track = new Track(); track.BestLapTime = bestLapTime; track.Length = trackLength; track.Name = trackName; track.Id = trackId; car = new Car(); car.Id = carId; car.TrackId = trackId; car.ImageName = imageName; car.Name = name; car.Track = new Track(); car.BestLapTime = bestLapTime; driver = new Driver(); driver.Id = driverId; driver.ApplicationUser = user; driver.ApplicationUserId = user.Id; driver.Car = car; driver.CarId = car.Id; driver.ControllerId = controllerId; driver.Track = track; driver.TrackId = track.Id; driverResult = new DriverResult(); driverResult.Id = driverResultId; driverResult.ApplicationUser = user; driverResult.ApplicationUserId = user.Id; driverResult.BestLapTime = trackRecord; driverResult.Car = car; driverResult.CarId = car.Id; driverResult.ControllerNumber = controllerId; driverResult.Finished = finished; driverResult.Fuel = fuel; raceSession = new RaceSession(); raceSession.Id = raceSessionId; raceSession.CrashPenalty = crashPenalty; raceSession.EndTime = endTime; raceSession.FuelEnabled = fuelEnabled; raceSession.LapsNotDuration = lapsNotDuration; raceSession.NumberOfDrivers = numDrivers; raceSession.RaceLength = raceLength; raceSession.RaceLimitValue = raceLimitValue; raceSession.RaceType = raceType; raceSession.RaceTypeId = raceType.Id; raceSession.StartTime = startTime; raceSession.Track = track; raceSession.TrackId = trackId; }
public Item(List <RaceLap> laps, int indexOfLap, RacePit[] pits, RaceSession rs) : base(laps, indexOfLap, pits, rs) { this.LapNumber = laps[indexOfLap].LapNumber; this.Time = laps[indexOfLap].Time.TotalMiliseconds; }
private static void UpdateNewDriverStandingsByNewRace(WeekendInfo previous, WeekendInfo current, AbstractScoring scoring, Weekend weekend, RaceSession race, Dictionary <Driver, TempData> tmp, RaceLap item) { DriverStandings prevDs = null; if (previous != null) { prevDs = previous.Standings[item.Driver]; } if (current.Standings[item.Driver] == null) { current.Standings.Add(new DriverStandings() { Driver = item.Driver }); } DriverStandings newDs = current.Standings[item.Driver]; int racePoints = GetRacePoints(item, scoring, tmp); weekend.Points.Add(item.Driver, racePoints); newDs.PointsM.Add(racePoints); newDs.BlackFlagsMean.Add(item.Sum( i => i.IsBlackFlagged ? 1 : 0, i => i.PreviousLapAsRaceLap )); if (race.Positions.GetDriverFinalStatus(item.Driver) == RacePositionCollection.eStatus.Accident || race.Positions.GetDriverFinalStatus(item.Driver) == RacePositionCollection.eStatus.Retired) { newDs.CrashesCount++; } if (race.Positions.GetDriverFinalStatus(item.Driver) == RacePositionCollection.eStatus.Running) { newDs.FinishesCount++; } newDs.FinishPositionsMean.Add(item.CurrentPosition); newDs.LapsInLead += tmp[item.Driver].LapsInLead; newDs.QualifyPositionsMean.Add( tmp[item.Driver].QualifyPosition); newDs.RacesCount++; newDs.LapsCount += item.LapNumber; int pos = item.CurrentPosition; if (pos < 2) { newDs.Top1++; } if (pos < 3) { newDs.Top2++; } if (pos < 4) { newDs.Top3++; } if (pos < 6) { newDs.Top5++; } if (pos < 11) { newDs.Top10++; } if (pos < 21) { newDs.Top20++; } newDs.PreviousWeekendStanding = prevDs; if (prevDs != null) { prevDs.NextWeeendStanding = newDs; } }
public void Fill(RaceSession session, GamePaused te) { }
public void Fill(RaceSession session, ApplicationExit te) { }
public void Fill(RaceSession session, DriverInCar te) { }
private static void UpdateRaceSession(RaceSession session, SessionInfo e) { Contract.Requires(session.SessionNum == e.SessionNum); session.YPA.AddTime(e.CurrentTime, e.SessionFlag == SessionInfo.eSessionFlag.kFlagYellow); }
public void Fill(RaceSession session, DriverWithdrawl te) { }
public void Fill(RaceSession session, TelemetryEvent te) { throw new NotImplementedException("No implementation to invoke race fill over " + te.GetType().FullName); }