public async override Task Process()

in Backend/src/Trackable.TripDetection/Modules/TripExtractorBase.cs [68:127]


        public async override Task<TripDetectionContext> Process(TripDetectionContext input, ILogger logger)
        {
            await OnProcessCalled(input);

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

            input.ResultantTrips = new List<Trip>();

            int tripId = 1;
            double distanceCoveredByTrip = 0;
            int numberOfMovingPoints = 0;
            var processedPoints = new List<TrackingPoint>();
            var currentLegs = new List<TripLeg>();
            foreach (var tripLeg in input.TripLegCandidates)
            {
                distanceCoveredByTrip += tripLeg.MovingSegment.GetBoundingRadius() * 2;
                numberOfMovingPoints += tripLeg.MovingSegment.Points.Count;

                processedPoints.AddRange(tripLeg.FirstStoppedSegment.Points);
                processedPoints.AddRange(tripLeg.LastStoppedSegment.Points);
                processedPoints.AddRange(tripLeg.MovingSegment.Points);

                var leg = GenerateTripLeg(tripLeg);
                currentLegs.Add(leg);

                // If the stop marking the end of the trip leg was matched the specified criteria,
                // Add current trip to the list of trips and reset variables for the next trip.
                if (isEndOfTrip(tripLeg.LastStoppedSegment))
                {
                    // If trip does not meet trip requirements, dont add to the resulting list of trips
                    if (numberOfMovingPoints >= this.miniumumTripPoints
                       && distanceCoveredByTrip >= this.minimumTripDistance)
                    {
                        var currentTrip = new Trip()
                        {
                            Id = tripId++,
                            AssetId = tripLeg.MovingSegment.Points.First().AssetId,
                            TrackingDeviceId = tripLeg.MovingSegment.Points.First().TrackingDeviceId,
                            EndLocationId = currentLegs.Last().EndLocationId,
                            EndTimeUtc = currentLegs.Last().EndTimeUtc,
                            StartLocationId = currentLegs.First().StartLocationId,
                            StartTimeUtc = currentLegs.First().StartTimeUtc,
                            TripLegs = currentLegs
                        };

                        processedPoints.ForEach(p => p.TripId = currentTrip.Id);
                        input.ResultantTrips.Add(currentTrip);
                    }

                    currentLegs = new List<TripLeg>();
                    processedPoints.Clear();
                    distanceCoveredByTrip = 0;
                    numberOfMovingPoints = 0;
                }
            }

            logger.LogDebugSerialize("Resulting trips {0}", input.ResultantTrips);

            return input;
        }