示例#1
0
        private List <TripDataPoint> PolyFill(IOrderedEnumerable <TripDataPoint> points)
        {
            //now that we have every datapoint merged, polyfill null or empty values
            TripDataPoint last = null;

            foreach (var point in points)
            {
                var p = point;
                if (last == null)
                {
                    last = p;
                    continue;
                }
                if (p.Position == null)
                {
                    p.Position = last.Position;
                }
                if (p.CoolantTemp == 0)
                {
                    p.CoolantTemp = last.CoolantTemp;
                }
                if (p.EngineLoad == 0)
                {
                    p.EngineLoad = last.EngineLoad;
                }
                if (p.FuelLevel == 0)
                {
                    p.FuelLevel = last.FuelLevel;
                }
                if (p.FuelRate == 0)
                {
                    p.FuelRate = last.FuelRate;
                }
                if (p.IntakeTemp == 0)
                {
                    p.IntakeTemp = last.IntakeTemp;
                }
                if (p.RpiTemperature == 0)
                {
                    p.RpiTemperature = last.RpiTemperature;
                }
                if (p.Speed == 0)
                {
                    p.Speed = last.Speed;
                }
                if (p.Voltage == 0)
                {
                    p.Voltage = last.Voltage;
                }
                if (p.AccelerometerX == 0)
                {
                    p.AccelerometerX = last.AccelerometerX;
                }
                if (p.AccelerometerY == 0)
                {
                    p.AccelerometerY = last.AccelerometerY;
                }
                if (p.AccelerometerZ == 0)
                {
                    p.AccelerometerZ = last.AccelerometerZ;
                }
                if (p.Altitude == 0)
                {
                    p.Altitude = last.Altitude;
                }

                last = p;
            }
            return(points.ToList());
        }
示例#2
0
        private List <TripDataPoint> AlignData(List <TripDataPoint> first, IReadOnlyCollection <StorageDataResponse> second, PrimitiveDataPoints dataPoint)
        {
            if (first == null)
            {
                first = new List <TripDataPoint>();
            }

            int threshold = 20;

            foreach (var newPoint in second)
            {
                var existing = (from f in first where Math.Abs((f.Timestamp - newPoint.Ts).TotalSeconds) < threshold select f)?.FirstOrDefault();
                if (existing == null)
                {
                    //datapoint isnt there yet, add it
                    existing = new TripDataPoint()
                    {
                        Timestamp = newPoint.Ts
                    };
                    first.Add(existing);
                }
                else
                {
                    if (dataPoint == PrimitiveDataPoints.CoolantTemp)
                    {
                        existing.CoolantTemp = newPoint.Value;
                    }
                    if (dataPoint == PrimitiveDataPoints.EngineLoad)
                    {
                        existing.EngineLoad = newPoint.Value;
                    }
                    if (dataPoint == PrimitiveDataPoints.FuelLevel)
                    {
                        existing.FuelLevel = newPoint.Value;
                    }
                    if (dataPoint == PrimitiveDataPoints.FuelRate)
                    {
                        existing.FuelRate = newPoint.Value;
                    }
                    if (dataPoint == PrimitiveDataPoints.IntakeTemp)
                    {
                        existing.IntakeTemp = newPoint.Value;
                    }
                    if (dataPoint == PrimitiveDataPoints.Position)
                    {
                        existing.Position = newPoint.Location;
                    }
                    if (dataPoint == PrimitiveDataPoints.RpiTemperature)
                    {
                        existing.RpiTemperature = newPoint.Value;
                    }
                    if (dataPoint == PrimitiveDataPoints.Speed)
                    {
                        existing.Speed = newPoint.Value;
                    }
                    if (dataPoint == PrimitiveDataPoints.Voltage)
                    {
                        existing.Voltage = newPoint.Value;
                    }
                    if (dataPoint == PrimitiveDataPoints.AccelerometerX)
                    {
                        existing.AccelerometerX = newPoint.Value;
                    }
                    if (dataPoint == PrimitiveDataPoints.AccelerometerY)
                    {
                        existing.AccelerometerY = newPoint.Value;
                    }
                    if (dataPoint == PrimitiveDataPoints.AccelerometerZ)
                    {
                        existing.AccelerometerZ = newPoint.Value;
                    }
                    if (dataPoint == PrimitiveDataPoints.Altitude)
                    {
                        existing.Altitude = newPoint.Value;
                    }
                }
            }

            first = PolyFill(first.OrderBy(t => t.Timestamp));
            first = PolyFill(first.OrderByDescending(t => t.Timestamp));
            return(first);
        }