public ResultPageViewModel(/*Stopwatch model,*/ IRegionManager regionManager) { this.RegionManager = regionManager; StateStore.Store.ObserveOnDispatcher().Subscribe(state => { LapTimes.Clear(); LapTimes.AddRange(state.GetState <ObservableCollection <LapTime> >(ApplicationStateKey.LapTimeList)); }); //this.LapTimes = model.Items // .ToReadOnlyReactiveCollection(x => new LapTimeViewModel(x)); BackCommand = new DelegateCommand(Back); }
private void StopImpl() { switch (timerState) { case TimerState.Running: stopWatch.Stop(); TimerState = TimerState.Stopped; break; case TimerState.Stopped: if (!dialogService.Confirm("Are you sure you want to start new?", "Confirm")) { return; } stopWatch.Reset(); LapTimes.Clear(); TimerState = TimerState.Initial; break; case TimerState.Initial: default: throw new ArgumentOutOfRangeException(); } }
public async Task <ActionResult <LapTimes> > PostLapTime(LapTimeDTO lapTimeDTO) { if (lapTimeDTO != null) { if (IsAnyNullOrEmpty(lapTimeDTO) == false) { ProjectCars2User user = await _context.Users.FirstOrDefaultAsync(c => c.GamerTag == lapTimeDTO.GamerTag); if (user != null) { CarClass carClass = await _context.CarClasses.FirstOrDefaultAsync(c => c.VehicleClass == lapTimeDTO.VehicleClass); if (carClass == null) { carClass = await CreateCarClass(lapTimeDTO.VehicleClass); } if (carClass == null) { return(null); } Car car = await _context.Cars.FirstOrDefaultAsync(c => c.VehicleName == lapTimeDTO.VehicleName); if (car == null) { car = await CreateCar(lapTimeDTO.VehicleName, carClass); } if (car == null) { return(null); } Track track = await _context.Tracks.FirstOrDefaultAsync(c => c.TrackLength == lapTimeDTO.TrackLength); if (track == null) { track = await CreateTrack(lapTimeDTO.TrackLength, lapTimeDTO.TrackName); } if (track == null) { return(null); } SessionMode sessionMode = await _context.SessionModes.FirstOrDefaultAsync(c => c.SessionModeName == lapTimeDTO.SessionMode); if (sessionMode == null) { sessionMode = await CreateSessionMode(lapTimeDTO.SessionMode); } if (sessionMode == null) { return(null); } Platform platform = await _context.Platforms.FirstOrDefaultAsync(c => c.PlatformName == lapTimeDTO.Platform); if (platform == null) { platform = await CreatePlatform(lapTimeDTO.Platform); } if (platform == null) { return(null); } Setup setup = await _context.Setups.FirstOrDefaultAsync(c => c.SetupName == lapTimeDTO.Setup); if (setup == null) { setup = await CreateSetup(lapTimeDTO.Setup); } if (setup == null) { return(null); } TodoApi.Models.Controller controller = await _context.Controllers.FirstOrDefaultAsync(c => c.ControllerName == lapTimeDTO.Controller); if (controller == null) { controller = await CreateController(lapTimeDTO.Controller); } if (controller == null) { return(null); } Camera camera = await _context.Cameras.FirstOrDefaultAsync(c => c.CameraName == lapTimeDTO.Camera); if (camera == null) { camera = await CreateCamera(lapTimeDTO.Camera); } if (camera == null) { return(null); } bool isModified = false; LapTimes lapTime = await _context.LapTimes .Include(l => l.Track) .Include(l => l.Car) .Include(l => l.ProjectCars2User) .FirstOrDefaultAsync(l => l.ProjectCars2User.Email == user.Email && l.Track.TrackName == track.TrackName && l.Car.VehicleName == car.VehicleName); if (lapTime != null) { isModified = true; } else { lapTime = new LapTimes(); lapTime.LapTime = double.MaxValue; } if (lapTime.LapTime > lapTimeDTO.LapTime) { lapTime.ProjectCars2User = user; lapTime.Camera = camera; lapTime.Car = car; lapTime.Controller = controller; lapTime.Platform = platform; lapTime.SessionMode = sessionMode; lapTime.Setup = setup; lapTime.Track = track; lapTime.LapDate = lapTimeDTO.LapDate; lapTime.AmbTemp = lapTimeDTO.AmbTemp; lapTime.LapTime = lapTimeDTO.LapTime; lapTime.RainDensity = lapTimeDTO.RainDensity; lapTime.Sector1 = lapTimeDTO.Sector1; lapTime.Sector2 = lapTimeDTO.Sector2; lapTime.Sector3 = lapTimeDTO.Sector3; lapTime.TrackTemp = lapTimeDTO.TrackTemp; } if (isModified == true) { _context.Entry(lapTime).State = EntityState.Modified; } else { _context.LapTimes.Add(lapTime); } await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetLapTime), new { id = lapTime.Id }, lapTime)); } else { return(null); } } else { return(null); } } return(null); }
private void ProcessLocationChange() { if (_race == null) { return; } if (!_race.WaypointsMustBeVisitedInOrder) { ProcessUnorderedRouteLocationChange(); return; } DistanceToWaypoint = EDLocation.DistanceBetween(Location, _race.Route.Waypoints[WaypointIndex].Location); int lapStartWaypoint = _race.LapStartWaypoint - 1; if (_race.Laps == 0) { TotalDistanceLeft = _race.Route.TotalDistanceLeftAtWaypoint(WaypointIndex) + DistanceToWaypoint; } else { // Total distance left needs to take into account the laps TotalDistanceLeft = _race.TotalDistanceLeftAtWaypoint(WaypointIndex, Lap) + DistanceToWaypoint; if (lapStartWaypoint < 0) { lapStartWaypoint = 0; } } if ((_race.Leader == null) || (TotalDistanceLeft < _race.Leader.TotalDistanceLeft)) { _race.Leader = this; } EDWaypoint previousWaypoint = null; if (WaypointIndex > 0) { previousWaypoint = _race.Route.Waypoints[WaypointIndex - 1]; } else if (_race.Laps > 0) { previousWaypoint = _race.Route.Waypoints[_race.Route.Waypoints.Count - 1]; } if (_race.Route.Waypoints[WaypointIndex].WaypointHit(Location, _previousLocation, previousWaypoint?.Location)) { // Commander has reached the target waypoint NumberOfWaypointsVisited++; if (_race.Laps > 0) { if (WaypointIndex != lapStartWaypoint) { AddRaceHistory($"Arrived at {_race.Route.Waypoints[WaypointIndex].Name} (lap {Lap})"); } else { // We're at the start waypoint, so have completed a lap DateTime lapEndTime = TimeStamp; LapEndTimes.Add(lapEndTime); TimeSpan thisLapTime = lapEndTime.Subtract(LapStartTime); LapTimes.Add(thisLapTime); LapStartTime = lapEndTime; string lapTime = $"{thisLapTime:hh\\:mm\\:ss}"; if (Lap == 1) { FastestLap = 1; } else if (thisLapTime < FastestLapTime()) { FastestLap = Lap; } Lap++; // We've only finished if this lap number is greater than the number of laps if (Lap > _race.Laps) { Finished = true; if (!Eliminated) { FinishTime = DateTime.UtcNow; string raceTime = $"{FinishTime.Subtract(StartTime):hh\\:mm\\:ss}"; notableEvents?.AddStatusEvent("CompletedNotification", Commander, $" ({raceTime})"); AddRaceHistory($"Completed in {raceTime}"); } WaypointIndex = 0; DistanceToWaypoint = 0; } else if (!Eliminated) { notableEvents?.AddStatusEvent("CompletedLap", Commander, $" {Lap - 1} ({lapTime})"); AddRaceHistory($"Completed lap {Lap - 1} in {lapTime}"); } if (Lap > 2 && FastestLap == Lap - 1) { notableEvents?.AddStatusEvent("FastestLapNotification", Commander, lapTime); } } } else { AddRaceHistory($"Arrived at {_race.Route.Waypoints[WaypointIndex].Name}"); } WaypointIndex++; if ((_race.Laps > 0) && (WaypointIndex > _race.LapEndWaypoint) && (Lap <= _race.Laps)) { WaypointIndex = lapStartWaypoint; } else if (WaypointIndex >= _race.Route.Waypoints.Count) { if (!Eliminated) { Finished = true; FinishTime = DateTime.UtcNow; string raceTime = $"{FinishTime.Subtract(StartTime):hh\\:mm\\:ss}"; notableEvents?.AddStatusEvent("CompletedNotification", Commander, $" ({raceTime})"); AddRaceHistory($"Completed in {raceTime}"); WaypointIndex = 0; DistanceToWaypoint = 0; } } } if (DistanceToWaypoint < _nextLogDistanceToWaypoint) { AddRaceHistory($"{(DistanceToWaypoint / 1000):F1}km to {_race.Route.Waypoints[WaypointIndex].Name}"); _nextLogDistanceToWaypoint = DistanceToWaypoint - 5000; } }