コード例 #1
0
ファイル: DriverTiming.cs プロジェクト: plkumar/SecondMonitor
        private void CheckAndOverrideBestLap(double layoutLength)
        {
            if (DriverInfo.Timing.BestLapTime == TimeSpan.Zero)
            {
                return;
            }

            if (BestLap == null)
            {
                ILapInfo newBestLap = new StaticLapInfo(Laps.Count + 1, DriverInfo.Timing.BestLapTime, false, Laps.LastOrDefault(), layoutLength, this);
                _lapsInfo.Insert(0, newBestLap);
                BestLap = newBestLap;
                LapCompleted?.Invoke(this, new LapEventArgs(newBestLap));
                return;
            }

            if (BestLap.LapTime == DriverInfo.Timing.BestLapTime)
            {
                return;
            }

            ILapInfo oldBestLap = BestLap;

            oldBestLap.OverrideTime(DriverInfo.Timing.BestLapTime);
            BestLap = Laps.Where(x => x.Completed && x.Valid && x.LapTime != TimeSpan.Zero).OrderBy(x => x.LapTime).FirstOrDefault();
            LapTimeReevaluated?.Invoke(this, new LapEventArgs(oldBestLap));
        }
コード例 #2
0
 internal void ResetLap()
 {
     trackSegment = -1;
     lastLap      = new LapCompleted(
         CarInfo,
         -1, // Not even started first lap yet, 0 would be running first lap.
         float.NaN, float.NaN, 0, disconnected);
 }
コード例 #3
0
 static int getComparableLapCount(LapCompleted t)
 {
     if (t != null)
     {
         return(t.lapCount);
     }
     return(0);
 }
コード例 #4
0
 static float getComparableTime(LapCompleted t)
 {
     if (t != null && !float.IsNaN(t.bestLap))
     {
         return(t.bestLap);
     }
     return(float.MaxValue);
 }
コード例 #5
0
 internal void Disconnected()
 {
     if (!finished)
     {
         Debug.Log("Disconnected: " + CarInfo.name);
         this.disconnected = true;
         lastLap           = new LapCompleted(CarInfo, lastLap.lapCount, lastLap.lastLap, lastLap.bestLap, lastLap.totalTime, true);
     }
 }
コード例 #6
0
 // Start is called before the first frame update
 void Start()
 {
     rigidBody = car.GetComponent <Rigidbody>();
     EventBus.Subscribe <LapCompleted>(this, newLap => {
         if (newLap.car.name == car.name)
         {
             lap = newLap;
         }
     });
 }
コード例 #7
0
        public static int compareByCompletedLaps(LapCompleted a, LapCompleted b)
        {
            int la = getComparableLapCount(a);
            int lb = getComparableLapCount(b);

            if (la == lb && la > 0)
            {
                return(a.totalTime.CompareTo(b.totalTime));
            }
            return(lb - la);
        }
コード例 #8
0
        public void HandleEvent(LapCompleted lapCompleted)
        {
            var xxx  = Stopwatch.StartNew();
            var race = this._raceRepository.Get(lapCompleted.RaceId);

            var lapStatistic = new LapStatistic(
                lapCompleted.RaceId,
                lapCompleted.TeamId,
                lapCompleted.TeamName,
                race.LapDistanceInMeters,
                lapCompleted.LapLength,
                lapCompleted.CompletedOn);

            this._lapStatisticRepository.AddLapStatistic(lapStatistic);

            StatsPrinter.Print("LapCompleted", xxx.ElapsedMilliseconds);
        }
コード例 #9
0
        internal void NewLapTime(float totalTime)
        {
            var now      = Time.time;
            var lapCount = lastLap.lapCount + 1;

            if (lapCount == 0)
            {
                // crossed finish line, starting first lap.
                lastLapRecordedAt = now;
                lastLap           = new LapCompleted(CarInfo, 0, float.NaN, float.NaN, totalTime, false);
                return;
            }
            var lastTime = now - lastLapRecordedAt;

            lastLapRecordedAt = now;
            var bestTime = (lastTime < lastLap.bestLap || float.IsNaN(lastLap.bestLap)) ? lastTime : lastLap.bestLap;

            this.lastLap = new LapCompleted(CarInfo, lapCount, lastTime, bestTime, totalTime, false);
            EventBus.Publish(lastLap);
        }
コード例 #10
0
        internal void NewLapTime(float totalTime)
        {
            var now      = Time.time;
            var lapCount = lastLap.lapCount + 1;

            if (lapCount == 0)
            {
                // crossed finish line, starting first lap.
                lastLapRecordedAt = now;
                lastLap           = new LapCompleted(CarInfo, 0, 0, 0, totalTime, false);
                return;
            }
            var lastTime = now - lastLapRecordedAt;

            Debug.Log("Lap Time for '" + CarInfo.name + "': " + lastTime);
            lastLapRecordedAt = now;
            var bestTime = (lastTime < lastLap.bestLap || lastLap.bestLap == 0) ? lastTime : lastLap.bestLap;

            this.lastLap = new LapCompleted(CarInfo, lapCount, lastTime, bestTime, totalTime, false);
            EventBus.Publish(lastLap);
        }
コード例 #11
0
ファイル: OpcProcessor.cs プロジェクト: IekMx/IekSamplerWin10
        public Models.Tag ProcessTag(Models.Tag tag)
        {
            switch (tag.Server)
            {
            case "CoDeSys.OPC.DA":
                if (_FestoTags.Count < 37 && !_FestoTags.Any(x => x.Name == tag.Name))
                {
                    if (!string.IsNullOrEmpty(tag.Name))
                    {
                        _FestoTags.Add(tag);
                    }
                    return(null);
                }
                else if (!_initialized)
                {
                    _FestoTags.Where(x => x.Name.StartsWith("PLC1.Application.GVL.HMI_bShowAuto_")).ToList().ForEach(x =>
                    {
                        if (bool.Parse(x.Value))
                        {
                            int.TryParse(x.Name.Replace("PLC1.Application.GVL.HMI_bShowAuto_", ""), out var auto);
                            UpdateSteps(auto == 1 ? 8 : auto == 2 ? 16 : 32);
                        }
                    });

                    _initialized = true;
                }
                var t = _FestoTags.FirstOrDefault(x => x.Handle == tag.Handle);
                if (t != null)
                {
                    t.Value = tag.Value;
                }
                break;

            case "GaugeToolsXL OPC Server":
                double.TryParse(tag.Value, out _gaugeLastVal);
                CountChanged?.Invoke(_gaugeLastVal);
                return(null);

            default:
                break;
            }

            switch (tag.Name)
            {
            case "PLC1.Application.GVL.Record1.lrTarget":
                var ipos    = _FestoTags.FirstOrDefault(x => x.Value == tag.Value);
                var miniPos = _FestoTags.Where(x => x.Name.StartsWith("PLC1.Application.GVL_1.HMI_iPos") && x.Value != "0").Min(x => int.Parse(x.Value)).ToString();
                var maxiPos = _FestoTags.Where(x => x.Name.StartsWith("PLC1.Application.GVL_1.HMI_iPos") && x.Value != "0").Max(x => int.Parse(x.Value)).ToString();
                if (ipos.Value == maxiPos)
                {
                    LapCompleted?.Invoke(true);
                }
                if (ipos.Value == miniPos)
                {
                    LapCompleted?.Invoke(false);
                }
                TagValidated?.Invoke(new Models.Tag
                {
                    Handle = int.Parse(tag.Value),
                    Name   = ipos.Name,
                    Value  = _gaugeLastVal.ToString()
                });
                break;

            case "PLC1.Application.GVL.HMI_bShowAuto_1":
            case "PLC1.Application.GVL.HMI_bShowAuto_2":
            case "PLC1.Application.GVL.HMI_bShowAuto_3":
                if (bool.Parse(tag.Value))
                {
                    int.TryParse(tag.Name.Replace("PLC1.Application.GVL.HMI_bShowAuto_", ""), out var auto);
                    UpdateSteps(auto == 1 ? 8 : auto == 2 ? 16 : 32);
                }
                break;

            case "PLC1.Application.GVL_1.HMI_rDelay":
                DelayUpdated?.Invoke(tag);
                break;

            default:
                break;
            }

            if (!_FestoTags.Any(x => x.Name == "PLC1.Application.PLC_PRG.bHOME_OK" && bool.Parse(x.Value)))
            {
                return(null);
            }

            return(null);
        }
コード例 #12
0
 public static int compareByBestLap(LapCompleted a, LapCompleted b)
 {
     return(getComparableTime(a).CompareTo(getComparableTime(b)));
 }
コード例 #13
0
 public abstract int compareLaps(LapCompleted a, LapCompleted b);
コード例 #14
0
 public override int compareLaps(LapCompleted a, LapCompleted b)
 {
     return(Racing.compareByBestLap(a, b));
 }
コード例 #15
0
 protected virtual void OnLapCompleted(LapEventArgs e)
 {
     LapCompleted?.Invoke(this, e);
 }