Пример #1
0
        public async override Task <TripDetectionContext> Process(TripDetectionContext input, ILogger logger)
        {
            var tripSegments = input.TripSegments;

            input.TripLegCandidates = new List <TripLegCandidate>();

            logger.LogDebugSerialize("Input trip segments {0}", tripSegments);

            var currentLeg  = new TripLegCandidate();
            var previousLeg = new TripLegCandidate();

            for (int i = 0; i < tripSegments.Count - 2; i += 2)
            {
                if (tripSegments[i].IsMovingSegment)
                {
                    continue;
                }

                currentLeg.FirstStoppedSegment = (StoppedSegment)tripSegments[i];
                currentLeg.MovingSegment       = (MovingSegment)tripSegments[i + 1];
                currentLeg.LastStoppedSegment  = (StoppedSegment)tripSegments[i + 2];

                if (currentLeg.MovingSegment.Points.Count < this.minimumNumberOfLegPoints)
                {
                    if (previousLeg.LastStoppedSegment.Points.Any())
                    {
                        previousLeg.LastStoppedSegment.Points.AddRange(currentLeg.LastStoppedSegment.Points);
                        previousLeg.LastStoppedSegment.EndLocationId = currentLeg.LastStoppedSegment.EndLocationId;
                    }
                }
                else
                {
                    if (previousLeg.FirstStoppedSegment.Points.Any())
                    {
                        input.TripLegCandidates.Add(previousLeg);
                    }

                    previousLeg = currentLeg;
                    currentLeg  = new TripLegCandidate();
                }
            }

            if (previousLeg.LastStoppedSegment.Points.Any())
            {
                input.TripLegCandidates.Add(previousLeg);
            }

            logger.LogDebugSerialize("Output trip candidates {0}", input.TripLegCandidates);

            return(input);
        }
Пример #2
0
 private TripLeg GenerateTripLeg(TripLegCandidate tripLegCandidate)
 {
     return(new TripLeg
     {
         AverageSpeed = tripLegCandidate.MovingSegment.GetAverageSpeed(),
         Route = tripLegCandidate.MovingSegment.Points,
         StartLocationId = tripLegCandidate.FirstStoppedSegment.EndLocationId,
         EndLocationId = tripLegCandidate.LastStoppedSegment.StartLocationId,
         StartTimeUtc = DateTimeUtils.FromUnixTime(
             tripLegCandidate.MovingSegment.Points.First().DeviceTimestampUtc),
         EndTimeUtc = DateTimeUtils.FromUnixTime(
             tripLegCandidate.MovingSegment.Points.Last().DeviceTimestampUtc)
     });
 }