public void MakeLap(CompetingModels CM) { if (Finished) { Finished = false; BadFinish = false; } DateTime Now = DateTime.Now; if (Laps.Count == 0) { RoundStart = Now; PreviousTime = Now; Laps.Add(new Lap(Now, Now, true)); } else { CurrentTime = Now; Laps.Add(new Lap(Now, PreviousTime, false)); PreviousTime = Now; } if (Laps.Count - 1 == CM.LapsCount) { Finish(); return; } }
/// <summary> /// Executes the load laps command. /// </summary> async Task ExecuteLoadLapsCommand() { if (IsBusy) { return; } IsBusy = true; try { var laps = await App.RestService.LapsByRaceAndDriverAsync(Race.Season, Race.Round, Driver.Id); Race.Laps = laps.Laps; Laps.Clear(); foreach (var l in laps.Laps) { Laps.Add(l); } } catch (Exception ex) { Debug.WriteLine(ex); } finally { IsBusy = false; } }
public async Task Test4ThensAsync500MsEach2000MsTotal() { // Start the runner asynchronously. Task t = Runner.Run(S).Then(S, S, S).Async(); // Take a lap right away. This should be only a few milliseconds in // if the runner tasks really started asynchronously. Laps.Add(Lapper.Lap()); // Wait for all of the runner tasks to finish. await t.ConfigureAwait(false); Lapper.Stop(); // There should be 5 laps; one that we took right away and one each per runner task. Assert.Equal(5, Laps.Count); // The first task should have been lapped right away, a few milliseconds after starting. // Let's give a 500% epsilon since the expected time is so short. TimeAssert.DeltaEquals(TimeSpan.FromMilliseconds(10), Lapper.Laps[0], 5); // The rest should each take about 500ms. foreach (var lap in Laps.Skip(1)) { TimeAssert.DeltaEquals(TimeSpan.FromMilliseconds(500), lap, 0.1); } // ... And the total time should have been about 4 x 500ms = 2000ms. TimeAssert.DeltaEquals(TimeSpan.FromMilliseconds(2000), Lapper.Elapsed, 0.1); }
public async Task Test4AndsAsync500MsEach500MsTotal() { // Start the runner asynchronously. Task t = Runner.Run(S).And(S, S, S).Async(); // Take a lap right away. This should be only a few milliseconds in // if the runner tasks really started asynchronously. Laps.Add(Lapper.Lap()); // Wait for the runner to finish. await t.ConfigureAwait(false); Lapper.Stop(); // The async lap (first lap) should have been only a few ms after its stopwatch started. TimeAssert.EpsilonEquals(TimeSpan.FromMilliseconds(25), Laps[0], TimeSpan.FromMilliseconds(50)); // We should have one lap per task run. Assert.Equal(5, Laps.Count); // Each lap should be about 500ms... // Skip the first lap because it was the one we took right away. foreach (TimeSpan lap in Laps.Skip(1)) { TimeAssert.DeltaEquals(TimeSpan.FromMilliseconds(500), lap, 0.1); } // And the elapsed time should be 500ms since the tasks were all run in parallel. TimeAssert.DeltaEquals(TimeSpan.FromMilliseconds(500), Lapper.Elapsed, 0.1); }
private void Add(int rot) { Laps.Add(new Lap(rot)); Calc(); SetLabel(); }
public virtual void AddLap(LapRecord lr) { Laps.Add(lr); OrderedLaps.Add(lr); OrderedLaps.Sort(); UpdateTimes(); RecalculateMeanOfLapTimes(); }
public void Lap(string lapName) { _stopwatch.Stop(); Laps.Add(new LappingStopwatchResult(lapName, _stopwatch.Elapsed)); _stopwatch.Reset(); _stopwatch.Start(); }
public void AddLap() { string tempFullTime = "Общее время: " + Time; TimeSpan tempT = TimeSpan.FromMilliseconds(elapsedTime - lastTime); lastTime = elapsedTime; string tempLapTime = "Время круга: "; tempLapTime += string.Format("{0:D2}:{1:D2}:{2:D2}", tempT.Hours, tempT.Minutes, tempT.Seconds); Laps.Add(new Lap { LapNumber = Laps.Count + 1, LapTime = tempLapTime, FullTime = tempFullTime }); }
private void DriverTimingOnNewLapStarted(object sender, DriverTiming.LapEventArgs e) { /*if (!Laps.Last().LapInfo.Completed) * { * Laps.RemoveAt(Laps.Count - 1); * }*/ var newLapModel = new LapViewModel(e.Lap); if (Laps.Any() && Laps.Last().LapNumber == newLapModel.LapNumber) { Laps.Remove(Laps.Last()); } Laps.Add(newLapModel); _gui.LapsGrid.ScrollIntoView(newLapModel); }
public void AddLap() { var newLap = new UserLap { SetupSheetID = new Guid(), LapTime = TimeSpan.Zero }; if (SelectedLap == null || SelectedLap.InLap) { var lastNonInLap = Laps.LastOrDefault(x => x.InLap == false); if (lastNonInLap != null) { newLap.LapNumber = lastNonInLap.LapNumber + 1; } else { newLap.LapNumber = Laps.Count() + 1; } } else { newLap.LapNumber = Laps.Count() + 1; } //bump the lap number of every lap beyond the insert point. for (var i = newLap.LapNumber - 1; i < Laps.Count(); i++) { Laps[i].LapNumber++; } var lvm = new LapViewModel { Lap = newLap }; Laps.Add(lvm); var lastOrDefault = Laps.LastOrDefault(x => x.InLap == false); SelectedLap = lastOrDefault; }
public void AddLap(Lap lap) { Laps.Add(lap); }
public void Update(Dictionary <string, object> dict, API api, Module caller) { double currTime = (double)api.GetData("SessionTime"); OldPosition = Position; int carIdx = int.Parse(dict.GetDictValue("CarIdx")); if (Driver == null || Driver.CarIndex != carIdx) { return; } Position = int.Parse(dict.GetDictValue("Position")); ClassPosition = int.Parse(dict.GetDictValue("ClassPosition")) + 1; GapLaps = int.Parse(dict.GetDictValue("Lap")); GapTime = float.Parse(dict.GetDictValue("Time").Replace('.', ',')); FastestLapNumber = int.Parse(dict.GetDictValue("FastestLap")); float newTime = float.Parse(dict.GetDictValue("FastestTime").Replace('.', ',')); LapTimeImproved = newTime < FastestLapTime || (newTime != 0 && FastestLapTime == 0) && !first; FastestLapTime = newTime; LastLapTime = float.Parse(dict.GetDictValue("LastTime").Replace('.', ',')); LapsLed = int.Parse(dict.GetDictValue("LapsLed")); LapsComplete = int.Parse(dict.GetDictValue("LapsComplete")); Incidents = int.Parse(dict.GetDictValue("Incidents")); SurfaceType surfaceType = ((SurfaceType[])api.GetData("CarIdxTrackSurface"))[carIdx]; SessionTimerModule m = (SessionTimerModule)API.Instance.FindModule("SessionTimer"); SessionType sessionType = m.SessionType; bool inpits = ((bool[])api.GetData("CarIdxOnPitRoad"))[carIdx]; if (sessionType == SessionType.LapRace || sessionType == SessionType.TimeRace) { InPits = inpits || surfaceType == SurfaceType.InPitStall; } else { InPits = inpits || surfaceType == SurfaceType.InPitStall || surfaceType == SurfaceType.NotInWorld; } Surface = surfaceType; Track track = ((SessionsModule)API.Instance.FindModule("Sessions")).Track; SessionState sessionState = m.SessionState; int finishLine = m.LapsTotal + 1; if (finishLine < 0) { finishLine = int.MaxValue; } SurfaceType surface = (SurfaceType)((int[])api.GetData("CarIdxTrackSurface"))[Driver.CarIndex]; int lapNumber = ((int[])api.GetData("CarIdxLap"))[Driver.CarIndex]; float trackPct = ((float[])api.GetData("CarIdxLapDistPct"))[Driver.CarIndex]; if (currentime >= prevtime) { currentime = (double)api.GetData("SessionTime"); } double timeoffset = 0; if (((double)api.GetData("SessionTime") - (double)api.GetData("ReplaySessionTime")) < 2) { timeoffset = (int)api.GetData("ReplayFrameNum") - ((double)api.GetData("SessionTime") * 60); } double prevpos = PrevTrackPct; double prevupdate = PrevTrackPctUpdate; float curpos = ((float[])api.GetData("CarIdxLapDistPct"))[Driver.CarIndex]; CurrentLap.ReplayPos = (int)(((double)api.GetData("SessionTime") * 60) + timeoffset); if (currentime > prevupdate && curpos != prevpos) { float speed = 0; if (curpos < 0.1 && prevpos > 0.9) { speed = (float)((((curpos - prevpos) + 1) * (double)track.Length) / (currentime - prevupdate)); } else { speed = (float)(((curpos - prevpos) * (double)track.Length) / (currentime - prevupdate)); } if (Math.Abs(Prevspeed - speed) < 1 && (curpos - prevpos) >= 0) { Speed = speed; } Prevspeed = speed; PrevTrackPct = curpos; PrevTrackPctUpdate = currentime; if (!Finished) { CurrentTrackPct = lapNumber + trackPct - 1; } if (curpos < 0.1 && prevpos > 0.9 && !Finished) { if (surface != SurfaceType.NotInWorld && speed > 0) { Double now = currentime - ((curpos / (1 + curpos - prevpos)) * (currentime - prevtime)); Sector sector = new Sector(); sector.Number = Sector; sector.Speed = Speed; sector.Time = (float)(now - SectorBegin); sector.Begin = SectorBegin; CurrentLap.Sectors.Add(sector); CurrentLap.Time = (float)(now - Begin); // TODO CurrentLap.ClassPosition = SharedData.Sessions.CurrentSession.getClassPosition(driver.Driver); if (sessionType == SessionType.LapRace || sessionType == SessionType.TimeRace) { CurrentLap.Gap = (float)GapLive; } else { LiveStandingsItem leader = ((LiveStandingsModule)caller).Leader; if (leader != null) { CurrentLap.Gap = CurrentLap.Time - leader.FastestLapTime; } } CurrentLap.GapLaps = 0; if (CurrentLap.LapNumber > 0 && Laps.FindIndex(l => l.LapNumber.Equals(CurrentLap.LapNumber)) == -1 && (sessionState != SessionState.Gridding || sessionState != SessionState.Cooldown)) { Laps.Add(CurrentLap); } CurrentLap = new Lap(); CurrentLap.LapNumber = lapNumber; CurrentLap.Gap = PreviousLap.Gap; CurrentLap.GapLaps = PreviousLap.GapLaps; CurrentLap.ReplayPos = (int)(((double)api.GetData("SessionTime") * 60) + timeoffset); CurrentLap.SessionTime = (double)api.GetData("SessionTime"); SectorBegin = now; Sector = 0; Begin = now; // caution lap calc //if (m.SessionFlags.FlagSet(SessionFlag.Yellow) && Position == 1) // SharedData.Sessions.CurrentSession.CautionLaps++; // class laps led //if (SharedData.Sessions.CurrentSession.getClassLeader(driver.Driver.CarClassName).Driver.CarIdx == driver.Driver.CarIdx && driver.CurrentLap.LapNum > 1) // driver.ClassLapsLed = driver.ClassLapsLed + 1; } } if (track.Sectors.Count > 0 && Driver.CarIndex >= 0) { for (int j = 0; j < track.Sectors.Count; j++) { if (curpos > track.Sectors[j] && j > Sector) { double now = currentime - ((curpos - track.Sectors[j]) * (curpos - prevpos)); Sector sector = new Sector(); sector.Number = Sector; sector.Time = (float)(now - SectorBegin); sector.Speed = Speed; sector.Begin = SectorBegin; CurrentLap.Sectors.Add(sector); SectorBegin = now; Sector = j; } } } if (CurrentLap.LapNumber + CurrentLap.GapLaps >= finishLine && surface != SurfaceType.NotInWorld && (sessionType == SessionType.LapRace || sessionType == SessionType.TimeRace) && !Finished) { ((LiveStandingsModule)caller).UpdateLivePositions(); CurrentTrackPct = (Math.Floor(CurrentTrackPct) + 0.0064) - (0.0001 * Position); Finished = true; } if (Driver.CarIndex >= 0) { Surface = surface; } } if (((LiveStandingsModule)caller).Leader != null) { Out = dict.GetDictValue("ReasonOutStr").StartsWith("Disconnected") || CurrentTrackPct <= ((LiveStandingsModule)caller).Leader.CurrentTrackPct * 0.75; } GridItem gridItem = GridModule.FindDriverStatic(this); if (gridItem != null) { Dnq = gridItem.QualiTime <= 0.0; } Dsq = dict.GetDictValue("ReasonOutStr").StartsWith("Disqualified"); Dns = (sessionType == SessionType.LapRace || sessionType == SessionType.TimeRace) ? CurrentTrackPct == 0.0 : false; prevtime = currentime; CurrentSessionTime = currentime; }
private void parseLaps(XmlDocument doc) { try { XmlNamespaceManager ns = new XmlNamespaceManager(doc.NameTable); ns.AddNamespace("k", @"http://www.opengis.net/kml/2.2"); double startTime = 0; double lapTime = 0; Sample prevSample = null; string prevTimeString = null; for (int n = 1; ; n++) { string expr = String.Format("/k:kml/k:Document/k:Folder/k:Folder[k:styleUrl='#lap' and k:name='{0}']/k:Placemark", n); XmlNodeList nodes = doc.SelectNodes(expr, ns); if (nodes == null || nodes.Count == 0) { break; } Lap l = new Lap(); l.mIndex = n; l.mAbsStartTime = startTime; Laps.Add(l); foreach (XmlNode node in nodes) { XmlNode descNode = node.SelectSingleNode("k:description", ns); XmlNode coordNode = node.SelectSingleNode("k:Point/k:coordinates", ns); if (descNode != null && coordNode != null) { Sample s = new Sample(); s.mLap = l; string timeString = parseDesc(s, descNode); parseCoords(s, coordNode); // If the ISO time code is the same as the one of the last sample // then discard the sample as a dup. With TrackMaster data this // happens for the first sample of each lap. if (prevTimeString != null && prevTimeString == timeString) { continue; } prevTimeString = timeString; Samples.Add(s); double elapsed = s.mElapsedTime; s.mAbsStartTime = startTime + elapsed; lapTime = elapsed; if (prevSample != null) { prevSample.mAbsEndTime = s.mAbsStartTime; } prevSample = s; } } // foreach node sample l.mLapTime = lapTime; startTime += lapTime; } // for n lap TotalTime = startTime; } catch (XPathException e) { // TODO use debug log System.Diagnostics.Debug.Print(e.Message + "\n" + e.StackTrace + "\n"); } }