Example #1
0
        public SampleCombiner(DataSample sample)
        {
            if (sample == null)
            {
                throw new ArgumentNullException("sample");
            }

            // validate that this sampletype is acceptable
            switch (sample.SampleType)
            {
            case DataSampleType.Average:
            case DataSampleType.Histogram:
            case DataSampleType.HitCount:
            case DataSampleType.Maximum:
            case DataSampleType.Minimum:
                break;

            default:
                throw new ArgumentException("Cannot combine samples for percentiles or other types");
            }

            this.internalSample = new DataSample
                                  {
                                      SampleType = sample.SampleType,
                                      Dimensions = sample.Dimensions,
                                      Name = sample.Name
                                  };

            this.AddData(sample);
            this.timeRange = new TimeRange(sample.StartTime, sample.EndTime);
            this.hasUpdatedTimeRange = true;
        }
        static void ApplyHasSeenCheckeredFlag(DataSample data, bool[] hasSeenCheckeredFlag)
        {
            if (data.LastSample != null && data.Telemetry.LeaderHasFinished)
                for (int i = 1; i < data.SessionData.DriverInfo.CompetingDrivers.Length; i++)
                    if (data.LastSample.Telemetry.CarIdxLapDistPct[i] > 0.90 && data.Telemetry.CarIdxLapDistPct[i] < 0.10)
                        hasSeenCheckeredFlag[i] = true;

            data.Telemetry.HasSeenCheckeredFlag = hasSeenCheckeredFlag;
        }
Example #3
0
        public DataSample GetDataSample()
        {
            lock (_syncObj)
            {
                if (null == _sample)
                {
                    _sample = iRacingConnection.GetDataFeed().First();
                }

                return(_sample);
            }
        }
Example #4
0
        static void ieventRacing_NewData(DataSample data)
        {
            //You can access your game data here
            var x = data.Telemetry.SessionTimeSpan;
            var z = data.Telemetry["AirTemp"];

            var y = data.SessionData.WeekendInfo.TrackDisplayName;
            var r = data.Telemetry.SessionData.Raw;


            Trace.WriteLine("Time: {0}".F(x));
        }
        public void SampleCombinerCopiesInitialData()
        {
            var hitCountSample = new DataSample {
                HitCount = 400, SampleType = DataSampleType.HitCount, StartTime = this.start.ToMillisecondTimestamp(), EndTime = this.end.ToMillisecondTimestamp()
            };

            var combiner = new SampleCombiner(hitCountSample);

            Assert.IsNotNull(combiner.Data);
            Assert.AreEqual(DataSampleType.HitCount, combiner.Data.SampleType);
            Assert.AreEqual(400, (int)(combiner.Data).HitCount);
        }
Example #6
0
        static DataSample BuildDataSample(TrackLocation[] carIdxTrackSurface = null)
        {
            if (carIdxTrackSurface == null)
            {
                carIdxTrackSurface = new[] { TrackLocation.InPitStall, TrackLocation.OnTrack, TrackLocation.OnTrack, TrackLocation.OnTrack, TrackLocation.OnTrack, TrackLocation.OnTrack }
            }
            ;

            var data = new DataSample
            {
                IsConnected = true,
                Telemetry   = new Telemetry
                {
                    { "SessionNum", 0 },
                    { "SessionTime", 1d },
                    { "CarIdxTrackSurface", carIdxTrackSurface }
                },
                SessionData = new SessionData
                {
                    SessionInfo = new SessionData._SessionInfo
                    {
                        Sessions = new[]
                        {
                            new iRacingSDK.SessionData._SessionInfo._Sessions
                            {
                                ResultsAverageLapTime = 100d
                            }
                        }
                    }
                }
            };

            data.SessionData.DriverInfo = new SessionData._DriverInfo
            {
                Drivers = new[]
                {
                    new SessionData._DriverInfo._Drivers {
                        UserName = "******", CarIdx = 0, CarNumberRaw = 1
                    },
                    new SessionData._DriverInfo._Drivers {
                        UserName = "******", CarIdx = 1, CarNumberRaw = 2
                    },
                    new SessionData._DriverInfo._Drivers {
                        UserName = "******", CarIdx = 2, CarNumberRaw = 3
                    },
                }
            };

            data.Telemetry.SessionData = data.SessionData;
            return(data);
        }
    }
        void TrackCameraPerferences_Load(object sender, EventArgs e)
        {
            lastSample = new iRacingConnection().GetDataFeed().First();

            cameraAngleSelection.Items.Add("Front Facing");        // CameraAngle.LookingInfrontOfCar);
            cameraAngleSelection.Items.Add("Rear Facing");         // CameraAngle.LookingBehindCar);
            cameraAngleSelection.Items.Add("Looking at Car");      // CameraAngle.LookingAtCar);
            cameraAngleSelection.Items.Add("Static Track Camera"); // CameraAngle.LookingAtTrack);

            DiscoverAnyNewTrackCameras();

            InitialiseDropDownListOfTracks();
        }
Example #8
0
        CarDetails FindADriver(DataSample data)
        {
            var activeDrivers = GetDriversOnTrack(data, preferredCarIndexes);

            if (activeDrivers.Count == 0)
            {
                activeDrivers = GetDriversOnTrack(data, allCarIndexes);
            }

            var next = randomDriverNumber.Next(activeDrivers.Count);

            return(activeDrivers[next]);
        }
Example #9
0
        private string CreateContentCsv(DataSample data)
        {
            var arrContent = new string[] {
                ClearStringCsv(data.t.ToString(cstrDateTimeFormatMiliSecond)),
                ClearStringCsv(data.strSample),
                ClearStringCsv(data.actualMaxValue.ToString()),
                ClearStringCsv(data.actualMinValue.ToString()),
                ClearStringCsv(data.actualDelegate.ToString()),
                ClearStringCsv(data.result.ToString()),
            };

            return(string.Join(",", arrContent));
        }
Example #10
0
        private void LoadTrainingData(string dataFile)
        {
            var serialier = new JsonSerializer();

            using (var reader = new StreamReader(dataFile))
            {
                var samplesList = serialier.Deserialize(reader, typeof(List <DataSample>)) as List <DataSample>;

                numOfSamples = samplesList.Count;

                DataSample.GenerateTrainingData(samplesList, windowSize, out trainingData, out trainingLabels);
            }
        }
        public override SignalResult SellSignal(IList <DataSample> samples, DataSample sample, Position position)
        {
            var levels = LevelsDeterminator.DeterminateLevels(samples).Where(lv => lv.TouchCount > 1);

            var indexOfSample = samples.IndexOf(sample);

            if (samples.Count() <= 3)
            {
                return new SignalResult()
                       {
                           ByStopLoss      = false,
                           SignalTriggered = false
                       }
            }
            ;

            var previousSample  = samples[indexOfSample - 1];
            var prevPrevSample  = samples[indexOfSample - 2];
            var signalTriggered = false;

            if (samples.Count() > 2 &&
                (sample.CandleColor == Common.CandleColor.Red) &&
                (prevPrevSample.CandleColor == Common.CandleColor.Green)
                //&& (previousSample.CandleColor == Common.CandleColor.Green || previousSample.CandleColor == Common.CandleColor.Grey)
                //&& sample.Candle.Volume * Math.Abs(sample.Candle.Close - sample.Candle.Open) > previousSample.Candle.Volume * Math.Abs(previousSample.Candle.Close - previousSample.Candle.Open)
                && IsLastAreaVolumeMoreThanPrevious(samples, previousSample, 50, 10, 1) &&
                IsSampleWithLongTail(previousSample, PositionDirection.Short, 0.3m))
            {
                if (position != null)
                {
                    if (Math.Abs(sample.Candle.Close - position.OpenPrice) > Math.Abs(position.OpenPrice - position.StopLossPrice) * MinimumProfitMultiplicator)
                    {
                        signalTriggered = true;
                    }
                }
                else
                {
                    signalTriggered = true;
                }
            }
            else
            {
                signalTriggered = false;
            }

            return(new SignalResult()
            {
                ByStopLoss = false,
                SignalTriggered = signalTriggered
            });
        }
        /// <summary>
        /// Updates all the running data
        ///Calculates Avergae temperature and RSD for 10 secs
        /// </summary>
        /// <param name="sample"></param>
        private static void UpdateRunningData(DataSample sample)
        {
            RunningSample.Add(sample);
            if (RunningSample.Count > 1)
            {
                while ((RunningSample[RunningSample.Count - 1].Time - RunningSample[0].Time) > 10)
                {
                    RunningSample.RemoveAt(0);
                }
            }
            AvegrageTemperature = Math.Round(RunningSample.Average(x => x.Temperature), 6);

            CalculateRSD();
        }
Example #13
0
    public DataSample GetCopy()
    {
        DataSample copy = new DataSample(inputDataArray.Length, outputDataArray.Length);

        for (int i = 0; i < inputDataArray.Length; i++)
        {
            copy.inputDataArray[i] = inputDataArray[i];
        }
        for (int o = 0; o < outputDataArray.Length; o++)
        {
            copy.outputDataArray[o] = outputDataArray[o];
        }
        return(copy);
    }
Example #14
0
        private void HandleSample(DataSample sample)
        {
            if (!_hasSentSessionData)
            {
                _hasSentSessionData = true;
                NewSessionInfo?.Invoke(SessionInfo.FromSessionData(sample.SessionData));
            }

            _subject.OnNext(new TelemetryUpdate
            {
                MyCar            = MyCarState.FromDataSample(sample),
                CompetitorStates = CarState.FromSample(sample)
            });
        }
        public void Process(DataSample data, TimeSpan relativeTime, ref OverlayData.LeaderBoard leaderBoard)
        {
            var session = data.SessionData.SessionInfo.Sessions[data.Telemetry.SessionNum];

            leaderBoard = captureLeaderBoard.CreateLeaderBoard(data, relativeTime, leaderBoard.Drivers);

            for (int i = 1; i < data.SessionData.DriverInfo.CompetingDrivers.Length; i++)
            {
                AnnounceIfDriverHasFinished(data, relativeTime, session, i, ref leaderBoard);
                MarkResultFlashCardStart(data, relativeTime, session, i);
            }

            overlayData.LeaderBoards.Add(leaderBoard);
        }
        BattleState SearchForNextBattle(DataSample data, Func <BattleState> notFound)
        {
            var battleDriver = Battle.Find(data, battleGap, battleFactor, Settings.Default.PreferredDrivers);

            if (battleDriver == null)
            {
                isInBattle = false;
                return(notFound());
            }

            isInBattle       = true;
            battleEndTime    = data.Telemetry.SessionTimeSpan + this.battleStickyPeriod;
            cameraChangeTime = data.Telemetry.SessionTimeSpan + this.battleCameraChangePeriod;
            return(new BattleState(BattlePosition.Started, battleDriver.Details));
        }
Example #17
0
        OverlayData.CamDriver CreateCamDriver(DataSample data, TimeSpan relativeTime)
        {
            var driver = GetCurrentDriverDetails(data);

            if (driver == null)
            {
                return(null);
            }

            return(new OverlayData.CamDriver
            {
                StartTime = relativeTime.TotalSeconds,
                CurrentDriver = driver,
            });
        }
        private void MergeHistograms(DataSample sample)
        {
            foreach (var pair in sample.Histogram)
            {
                uint existingValue;
                if (!this.internalSample.Histogram.TryGetValue(pair.Key, out existingValue))
                {
                    existingValue = 0;
                }

                this.internalSample.Histogram[pair.Key] = existingValue + pair.Value;
            }

            this.internalSample.SampleCount += sample.SampleCount;
        }
Example #19
0
        static DataSample CreateSample(double time, SessionData sessionData)
        {
            var data = new DataSample
            {
                SessionData = sessionData,
                IsConnected = true,
                Telemetry   = new Telemetry
                {
                    { "SessionTime", time },
                }
            };

            data.Telemetry.SessionData = sessionData;
            return(data);
        }
        void MarkResultFlashCardStart(DataSample data, TimeSpan relativeTime, SessionData._SessionInfo._Sessions session, int i)
        {
            if (!data.LastSample.Telemetry.Cars[i].HasSeenCheckeredFlag || overlayData.TimeForOutroOverlay != null)
            {
                return;
            }

            var position = (int)session.ResultsPositions.First(r => r.CarIdx == i).Position;

            if (position == Settings.Default.ResultsFlashCardPosition)
            {
                overlayData.TimeForOutroOverlay = relativeTime.TotalSeconds;
                TraceInfo.WriteLine("{0} Mark show results flash card.", data.Telemetry.SessionTimeSpan);
            }
        }
Example #21
0
        void AddEvent(InterestState interest, DataSample d, TimeSpan t)
        {
            raceEvents.Add(new OverlayData.RaceEvent
            {
                Interest     = interest,
                StartTime    = lastStartTime.TotalSeconds,
                EndTime      = t.TotalSeconds,
                WithOvertake = withOvertake,
                Position     = position
            });
            lastStartTime = t;

            TraceInfo.WriteLine("{0} Stopping {1}{2}", d.Telemetry.SessionTimeSpan, interest.ToString(), withOvertake ? " - with Overtake" : "");
            withOvertake = false;
        }
        bool HasBattleTimeout(DataSample data)
        {
            if (data.Telemetry.SessionTimeSpan > cameraChangeTime && !Battle.IsInBattle(data, battleGap, battleFollower, battleLeader))
            {
                TraceInfo.WriteLine("{0} Battle has stopped.", data.Telemetry.SessionTimeSpan);
                return(true);
            }

            if (data.Telemetry.UnderPaceCar)
            {
                TraceInfo.WriteLine("{0} Battle has stopped, due to double yellows.", data.Telemetry.SessionTimeSpan);
                return(true);
            }

            return(data.Telemetry.SessionTimeSpan > battleEndTime);
        }
Example #23
0
        public void MeasureProcess(DataSample data)
        {
            if (data.isRaw)
            {
                InsertMeasureRaw(data, _DBUltity);
            }
            else
            {
                InsertMeasureDetail(data, _DBUltity);

                if (MeasureType == emMeasureType.AlarmTest && Math.Abs(data.actualDelegate) >= Math.Abs(DeviceCurrent.AlarmValue))
                {
                    InsertMeasureLimit(data, _DBUltity);
                }
            }
        }
        public void TestHitCountSampleCombiner()
        {
            var hitCountSample = new DataSample {
                HitCount = 1, SampleType = DataSampleType.HitCount, StartTime = this.start.ToMillisecondTimestamp(), EndTime = this.end.ToMillisecondTimestamp()
            };
            var combiner = new SampleCombiner(hitCountSample);

            for (uint i = 0; i < 100; i++)
            {
                var before = (combiner.Data).HitCount;
                combiner.AddSample(new DataSample {
                    HitCount = i, SampleType = DataSampleType.HitCount, StartTime = this.start.ToMillisecondTimestamp(), EndTime = this.end.ToMillisecondTimestamp()
                });
                Assert.AreEqual(before + i, (combiner.Data).HitCount);
            }
        }
Example #25
0
 private void CopyDataSampleToModule(DataSample sample, TestModule module)
 {
     module.bias[0]      = sample.inputDataArray[0];
     module.ownVelX[0]   = sample.inputDataArray[1];
     module.ownVelY[0]   = sample.inputDataArray[2];
     module.enemyPosX[0] = sample.inputDataArray[3];
     module.enemyPosY[0] = sample.inputDataArray[4];
     module.enemyVelX[0] = sample.inputDataArray[5];
     module.enemyVelY[0] = sample.inputDataArray[6];
     module.enemyDirX[0] = sample.inputDataArray[7];
     module.enemyDirY[0] = sample.inputDataArray[8];
     module.distLeft[0]  = sample.inputDataArray[9];
     module.distRight[0] = sample.inputDataArray[10];
     module.distUp[0]    = sample.inputDataArray[11];
     module.distDown[0]  = sample.inputDataArray[12];
 }
Example #26
0
        private void DataList_DragItemsCompleted(ListViewBase sender, DragItemsCompletedEventArgs args)
        {
            var data = JsonConvert.SerializeObject(DataList.Items);

            _app.Child("dataSample").Set(data); //send data to Firebase

            UpdateButton.IsEnabled = DataList.SelectedItem != null;

            DataSample selectedItem = DataList.SelectedItem as DataSample;

            if (selectedItem != null)
            {
                selectedItem.IsReadOnly = true;
                PreviousSelectedIndex   = DataList.SelectedIndex;
            }
        }
        public void Process(DataSample data, TimeSpan relativeTime, ref OverlayData.LeaderBoard leaderBoard)
        {
            if (leaderBoardUpdateRate == 0 || leaderBoard == null)
            {
                leaderBoard = captureLeaderBoard.CreateLeaderBoard(data, relativeTime, LatestRunningOrder(data, relativeTime));
            }
            else
            {
                leaderBoard = captureLeaderBoard.CreateLeaderBoard(data, relativeTime, leaderBoard.Drivers);
            }

            leaderBoardUpdateRate++;
            leaderBoardUpdateRate = leaderBoardUpdateRate % 8;

            overlayData.LeaderBoards.Add(leaderBoard);
        }
Example #28
0
        OverlayData.CamDriver CreateCamDriver(DataSample data, TimeSpan relativeTime)
        {
            var driver = GetCurrentDriverDetails(data);

            if (driver == null)
            {
                return(null);
            }

            return(new OverlayData.CamDriver
            {
                StartTime = relativeTime.TotalSeconds,
                CurrentDriver = driver,
                camGroupNumber = data.Telemetry.CamGroupNumber     //get current, active camera group from telemetry data
            });
        }
Example #29
0
        bool IsInPits(DataSample data)
        {
            if (data.Telemetry.CamCar.TrackSurface == TrackLocation.InPitStall && pitBoxStartTime == 0)
            {
                Trace.WriteLine("{0} Incident car is in pit stall".F(data.Telemetry.SessionTimeSpan));
                pitBoxStartTime = data.Telemetry.SessionTime;
            }

            if (data.Telemetry.CamCar.TrackSurface == TrackLocation.InPitStall && pitBoxStartTime + 2 < data.Telemetry.SessionTime)
            {
                Trace.WriteLine("{0} Finishing showing incident as car is in pit stall".F(data.Telemetry.SessionTimeSpan));
                return(true);
            }

            return(false);
        }
Example #30
0
        public override SignalResult SellSignal(IList <DataSample> samples, DataSample sample, Position position)
        {
            var indexOfSample = samples.IndexOf(sample);

            if (samples.Count() <= 1)
            {
                return new SignalResult()
                       {
                           ByStopLoss      = false,
                           SignalTriggered = false
                       }
            }
            ;

            var previousSample  = samples[indexOfSample - 1];
            var signalTriggered = false;

            if (samples.Count() > 1 &&
                (sample.CandleColor == Common.CandleColor.Red) &&
                (previousSample.CandleColor == Common.CandleColor.Green || previousSample.CandleColor == Common.CandleColor.Grey) &&
                sample.Candle.Volume * Math.Abs(sample.Candle.Close - sample.Candle.Open) > previousSample.Candle.Volume * Math.Abs(previousSample.Candle.Close - previousSample.Candle.Open) &&
                IsLastAreaVolumeMoreThanPrevious(samples, sample, 50, 40, 3))
            {
                if (position != null)
                {
                    if (Math.Abs(sample.Candle.Close - position.OpenPrice) > Math.Abs(position.OpenPrice - position.StopLossPrice) * MinimumProfitMultiplicator)
                    {
                        signalTriggered = true;
                    }
                }
                else
                {
                    signalTriggered = true;
                }
            }
            else
            {
                signalTriggered = false;
            }

            return(new SignalResult()
            {
                ByStopLoss = false,
                SignalTriggered = signalTriggered
            });
        }
    }
Example #31
0
        private void InsertMeasureRaw(DataSample data, clsDBUltity db, DeviceInfo device)
        {
            var _hasErrDB = false;

            if (string.IsNullOrEmpty(data.strSample))
            {
                return;
            }

            double dblMax;
            double dblMin;
            double dblDelegate;
            string strValue;

            string[] arrValue;
            var      result = (int)clsDBUltity.emMeasureResult.Pass;

            GetDataFromSample(data.strSample, out arrValue, out strValue, out dblMax, out dblMin, out dblDelegate);

            if (device.MeasureType == emMeasureType.AlarmTest)
            {
                result = device.AlarmValue > (int)dblDelegate ? (int)clsDBUltity.emMeasureResult.Normal : (int)clsDBUltity.emMeasureResult.Alarm;
            }

            if (!_hasErrDB)
            {
                if (!db.InsertMeasureDetailRaw(data.deviceId, device.MeasureId, data.t, data.strSample, (int)dblMax, (int)dblMin, (int)dblDelegate, result))
                {
                    _hasErrDB       = true;
                    _nameErrFileRaw = clsConfig.MEASURE_DETAIL_RAW_NAME_FILE + DateTime.Now.ToString(clsDBUltity.cstrDateTimeFormatNoMiliSecond2);
                    string content = db.GetInsertMeasureDetailRawSql(data.deviceId, device.MeasureId, data.t, data.strSample, (int)dblMax, (int)dblMin, (int)dblDelegate, result);
                    WriteFileErrors(_nameErrFileRaw, content, device.MeasureId);
                    _numberRecordWriteRaw++;
                }
            }
            else
            {
                if (string.IsNullOrEmpty(_nameErrFileRaw) || _numberRecordWriteRaw == clsConfig.MAX_RECORD_FILE_ERR)
                {
                    _numberRecordWriteRaw = 0;
                    _nameErrFileRaw       = clsConfig.MEASURE_DETAIL_RAW_NAME_FILE + DateTime.Now.ToString(clsDBUltity.cstrDateTimeFormatNoMiliSecond2);
                }
                string content = db.GetInsertMeasureDetailRawSql(data.deviceId, device.MeasureId, data.t, data.strSample, (int)dblMax, (int)dblMin, (int)dblDelegate, result);
                WriteFileErrors(_nameErrFileRaw, content, device.MeasureId);
                _numberRecordWriteRaw++;
            }
        }
Example #32
0
        public void Direct(DataSample data)
        {
            if (isWatchingRandomDriver)
            {
                return;
            }

            isWatchingRandomDriver = true;

            finishWatchingRandomDriverAt = data.Telemetry.SessionTimeSpan + stickyTime;

            camera = cameraControl.FindACamera(new[] { CameraAngle.LookingInfrontOfCar, CameraAngle.LookingAtCar, CameraAngle.LookingAtTrack });
            car    = FindADriver(data);

            TraceInfo.WriteLine("{0} Changing camera to random driver: {1}; camera: {2}", data.Telemetry.SessionTimeSpan, car.UserName, camera.CameraName);
            cameraControl.CameraOnDriver((short)car.CarNumberRaw, camera.CameraNumber);
        }
Example #33
0
        DataSample[] CreateSamplesFromFrameNumbers(params int[] frameNumbers)
        {
            DataSample lastSample = null;

            return frameNumbers.Select(n =>
                {
                    var sample = new DataSample
                    {
                        IsConnected = true,
                        Telemetry = new Telemetry
                        {
                            { "ReplayFrameNum", n }
                        },
                        LastSample = lastSample
                    };

                    lastSample = sample;
                    return sample;
                }
            ).ToArray();
        }
        static void ApplyHasRetired(DataSample data, TimeSpan[] lastTimeOfData)
        {
            data.Telemetry.HasRetired = new bool[64];

            if (!(new[] { SessionState.Racing, SessionState.Checkered, SessionState.CoolDown }).Contains(data.Telemetry.SessionState))
                return;

            for (int i = 1; i < data.SessionData.DriverInfo.CompetingDrivers.Length; i++)
            {
                if (data.Telemetry.HasSeenCheckeredFlag[i])
                    continue;

                if (data.Telemetry.HasData(i))
                {
                    lastTimeOfData[i] = data.Telemetry.SessionTimeSpan;
                    continue;
                }

                if (lastTimeOfData[i] + 30.Seconds() < data.Telemetry.SessionTimeSpan)
                    data.Telemetry.HasRetired[i] = true;
            }
        }
Example #35
0
 private void MergeHitCounts(DataSample sample)
 {
     this.internalSample.HitCount += sample.HitCount;
 }
 private float[] GetDistancesFromSamples(DataSample[] correctedSamples)
 {
     return correctedSamples.Select(s => s.Telemetry.CarIdxLap[0] + s.Telemetry.CarIdxLapDistPct[0]).ToArray();
 }
Example #37
0
        public void UpdateDataSample(DataSample sample)
        {
            if (sample == null)
            {
                throw new ArgumentNullException("sample");
            }

            this.UpdateDictionary(sample.Histogram);
            sample.SampleCount += this.SampleCount;
            sample.SampleType = DataSampleType.Histogram;
        }
Example #38
0
        /// <summary>
        /// Add data to the combined sample. Ignore envelope data
        /// </summary>
        /// <param name="sample"></param>
        internal void AddData(DataSample sample)
        {
            switch (this.internalSample.SampleType)
            {
            case DataSampleType.Average:
                this.MergeAverages(sample);
                break;

            case DataSampleType.Histogram:
                this.MergeHistograms(sample);
                break;

            case DataSampleType.Maximum:
                this.MergeMax(sample);
                break;

            case DataSampleType.Minimum:
                this.MergeMin(sample);
                break;
            case DataSampleType.HitCount:
                this.MergeHitCounts(sample);
                break;

            default:
                throw new InvalidOperationException("Impossible to add this data");
            }
        }
Example #39
0
        private void MergeMax(DataSample sample)
        {
            if (sample.MaxValue > this.internalSample.MaxValue)
            {
                this.internalSample.MaxValue = sample.MaxValue;
            }

            this.internalSample.SampleCount += sample.SampleCount;
        }
 public Car Car(DataSample data)
 {
     return data.Telemetry.Cars[this.carIdx];
 }
 static void ApplyIsFinalLap(DataSample data)
 {
     data.Telemetry.IsFinalLap = data.Telemetry.RaceLaps >= data.SessionData.SessionInfo.Sessions[data.Telemetry.SessionNum].ResultsLapsComplete;
 }
 static void ApplyLeaderHasFinished(DataSample data)
 {
     if (data.Telemetry.RaceLaps > data.SessionData.SessionInfo.Sessions[data.Telemetry.SessionNum].ResultsLapsComplete)
         data.Telemetry.LeaderHasFinished = true;
 }
Example #43
0
        private void MergeAverages(DataSample sample)
        {
            ulong newSampleCount;
            checked
            {
                newSampleCount = sample.SampleCount + this.internalSample.SampleCount;
            }

            // avoid overflow by combining two samples in pieces as opposed to expanding them and re-dividing. 
            // There is a new denominator common to both samples. Scale both samples appropriately
            double oldMulitiplier = (this.internalSample.SampleCount / (double)newSampleCount);
            double newMultiplier = (sample.SampleCount / (double)newSampleCount);

            this.internalSample.Average = (oldMulitiplier * this.internalSample.Average) +
                                          (newMultiplier * sample.Average);
            this.internalSample.SampleCount = newSampleCount;
        }
Example #44
0
        private void MergeMin(DataSample sample)
        {
            if (sample.MinValue < this.internalSample.MinValue)
            {
                this.internalSample.MinValue = sample.MinValue;
            }

            this.internalSample.SampleCount += sample.SampleCount;
        }
Example #45
0
 /// <summary>
 /// Determine if there is a machine count as part of this sample (e.g. if the sample is an aggregated data sample).
 /// Otherwise return 1
 /// </summary>
 /// <param name="sample"></param>
 /// <returns></returns>
 internal static uint ExtractMachineCount(DataSample sample)
 {
     return sample.MachineCount > 0 ? sample.MachineCount : 1;
 }
Example #46
0
        private void MergeHistograms(DataSample sample)
        {
            foreach (var pair in sample.Histogram)
            {
                uint existingValue;
                if (!this.internalSample.Histogram.TryGetValue(pair.Key, out existingValue))
                {
                    existingValue = 0;
                }

                this.internalSample.Histogram[pair.Key] = existingValue + pair.Value;
            }

            this.internalSample.SampleCount += sample.SampleCount;
        }
Example #47
0
 public void UpdateDataSample(DataSample sample)
 {
     if (sample == null)
     {
         throw new ArgumentNullException("sample");
     }
     sample.SampleType = DataSampleType.HitCount;
     sample.HitCount += this.HitCount;
 }
Example #48
0
        public void AddSample(DataSample sample)
        {
            if (sample == null)
            {
                throw new ArgumentNullException("sample");
            }

            if (sample.SampleType != this.internalSample.SampleType)
            {
                throw new InvalidDataException(string.Format(
                                                             "Sample Type: {0} does not match combined sample type: {1}",
                                                             sample.SampleType, this.internalSample.SampleType));
            }

            if (sample.StartTime != this.internalSample.StartTime ||
                sample.EndTime != this.internalSample.EndTime)
            {
                this.timeRange = TimeRange.Merge(this.timeRange,
                                                 new TimeRange(sample.StartTime, sample.EndTime));
                this.hasUpdatedTimeRange = true;
            }

            this.AddData(sample);
        }