public static MovingData Create(BustronicContext context)
        {
            var routes = context.Routes
                         .Where(e => e.IsReady.HasValue && e.IsReady.Value == true && e.DeletedAt == null)
                         .Include(e => e.RouteSegments)
                         .AsEnumerable()
                         .Select(e =>
            {
                e.RouteSegments = e.RouteSegments.Where(e => e.DeletedAt == null).OrderBy(e => e.Position).ToList();
                return(e);
            })
                         .ToList();
            var routeSegmentPaths  = context.RouteSegmentPaths.ToList();
            var routeSegmentSpeeds = context.RouteSegmentSpeeds.ToList();
            var timeIntervals      = context.TimeIntervals.ToList();

            var movingData = new MovingData(context)
            {
                Routes            = routes,
                RouteSegmentPaths = routeSegmentPaths
                                    .GroupBy(e => e.RouteSegmentId)
                                    .ToDictionary(gdc => gdc.Key, gdc => gdc.ToList()),
                RouteSegmentSpeeds = routeSegmentSpeeds
                                     .GroupBy(e => e.RouteSegmentId)
                                     .ToDictionary(gdc => gdc.Key,
                                                   gdc => gdc.Where(g => g.History == 0).ToDictionary(c => c.TimeIntervalId, c => c)),
                TimeIntervals = timeIntervals.ToList(),
            };

            return(movingData);
        }
Exemple #2
0
        public static List <MovingVehicleInfo> Create(MovingData movingData)
        {
            var list = new List <MovingVehicleInfo>();

            foreach (var item in movingData.GetMovingVehicles())
            {
                if (
                    !item.RouteSegmentId.HasValue ||
                    !item.ConfirmedAt.HasValue ||
                    !item.LastPathPosition.HasValue ||
                    !item.DistanceFromLastPath.HasValue)
                {
                    continue;
                }
                var route = movingData.Routes.Find(e => e.Id == item.RouteId);
                if (route == null)
                {
                    continue;
                }
                List <RouteSegments> routeSegments = route.RouteSegments.ToList();
                list.Add(new MovingVehicleInfo()
                {
                    MovingVehicle = item,
                    Route         = route,
                    RouteSegments = routeSegments,
                });
            }
            return(list);
        }