Пример #1
0
        public async Task <BusStopDetails> GetStopDataAsync(string StopRef, DateTime timeStart, DateTime timeEnd, bool forceRefresh = false)
        {
            //check if its in the buffer
            OpenArchive gtfsArchive = GetArchiveFromBuffer(this.archiveFileName);

            if (gtfsArchive == null)
            {
                string     completePath = this.fileMgr.FilePathRoot + this.archiveFileName;
                ZipArchive zipFile      = this.fileMgr.GetZipFile(this.archiveFileName);
                gtfsArchive = new OpenArchive(completePath, zipFile);
                this.bufferedArchives.Add(gtfsArchive);
            }

            //get stop id
            //find stop id from stop name or stop code
            StopModel stopObj = GetStopFromStopRef(gtfsArchive, StopRef);


            //get expected trips at stop
            List <TripTimesModel> trips = GetTripsFromStopId(gtfsArchive, stopObj.stop_id, timeStart, timeEnd);


            //fill in the details
            BusStopDetails stopDetails = new BusStopDetails();

            stopDetails.StopId        = stopObj.stop_id;
            stopDetails.StopRef       = stopObj.stop_code;
            stopDetails.StopPointName = stopObj.stop_name;
            stopDetails.busStopX      = stopObj.stop_lat;
            stopDetails.busStopY      = stopObj.stop_lon;

            foreach (TripTimesModel trip in trips)
            {
                //details from trip times
                VehicleJourney vehicleJourney  = new VehicleJourney();
                TimeSpan       startTime       = timeStart.TimeOfDay;
                TimeSpan       endTime         = timeEnd.TimeOfDay;
                TimeSpan       tripArrivalTime = trip.departure_time;
                DateTime       startOfDate     = timeStart.Date;
                startOfDate = startOfDate.Add(tripArrivalTime);

                vehicleJourney.TripId          = trip.trip_id;
                vehicleJourney.AimedArrival    = startOfDate;
                vehicleJourney.ConfidenceLevel = 3; //not real time


                //get more details from trip.csv
                TripModel tripDetails = GetTripFromTripId(gtfsArchive, trip.trip_id);
                vehicleJourney.DirrectionAway = tripDetails.direction_id == 1;

                //get more details from routes.csv
                RouteModel routeDetails = GetRouteFromRouteId(gtfsArchive, tripDetails.route_id);
                vehicleJourney.LineRef = routeDetails.route_short_name;

                stopDetails.IncomingVehicles.Add(vehicleJourney);
            }
            stopDetails.IncomingVehicles.Sort();
            return(stopDetails);
        }
Пример #2
0
        private BusStopDetails ConvertJsonToBusStop(JsonObject jsonObj)
        {
            BusStopDetails busStop = new BusStopDetails();
            JsonObject     stopMon = jsonObj.GetArray <JsonObject>("StopMonitoringDelivery")?.FirstOrDefault();


            //get bus stop details
            busStop.StopRef      = stopMon.GetArray <JsonObject>("MonitoringRef")?.FirstOrDefault()?.Get("Value");
            busStop.RspTimestamp = stopMon.Get <DateTime>("ResponseTimestamp");

            //other bus stop details are stored in the vehicle journey
            if (stopMon.Get("MonitoredStopVisit") == null)
            {
                return(busStop);
            }
            JsonObject monitoredCall = stopMon.GetByBPath <JsonObject>("MonitoredStopVisit[0]/MonitoredVehicleJourney/MonitoredCall");

            busStop.StopPointName = monitoredCall.GetByBPath <string>("StopPointName[0]/Value");


            string xCordStr = monitoredCall?.GetByBPath <string>("VehicleLocationAtStop/Items[0]");
            string yCordStr = monitoredCall?.GetByBPath <string>("VehicleLocationAtStop/Items[1]");

            if (xCordStr != null && yCordStr != null)
            {
                busStop.busStopX = float.Parse(xCordStr);
                busStop.busStopY = float.Parse(yCordStr);
            }
            busStop.Version = stopMon.Get("version");

            //get busses that are comming
            JsonObject[] BussesTracked = stopMon.GetArray <JsonObject>("MonitoredStopVisit");
            foreach (JsonObject bus in BussesTracked)
            {
                //fill in a incomingVehicle object
                VehicleJourney incomingVehicle = new VehicleJourney();

                //make variables for frequently used objects
                JsonObject stopVisit        = bus.Get <JsonObject>("MonitoredVehicleJourney");
                JsonObject busMonitoredCall = stopVisit.Get <JsonObject>("MonitoredCall");

                incomingVehicle.RecordedAt      = GetLocalDateTime(bus.Get("RecordedAtTime"));
                incomingVehicle.ValidUntil      = GetLocalDateTime(bus.Get("ValidUntilTime"));
                incomingVehicle.ConfidenceLevel = stopVisit.Get <int>("ConfidenceLevel");

                incomingVehicle.FinalDestinationName = busMonitoredCall.GetByBPath <string>("StopPointName[0]/Value");
                incomingVehicle.DirrectionAway       = stopVisit.GetByBPath <string>("DirectionRef/Value") == "O" ? true : false;
                incomingVehicle.LineRef          = stopVisit.GetByBPath <string>("LineRef/Value");
                incomingVehicle.AimedArrival     = GetLocalDateTime(busMonitoredCall.Get("AimedArrivalTime"));
                incomingVehicle.EstimatedArrival = GetLocalDateTime(busMonitoredCall.Get("LatestExpectedArrivalTime"));
                incomingVehicle.DriverName       = stopVisit.Get("DriverName");
                incomingVehicle.DriverRef        = stopVisit.Get("DriverRef");
                incomingVehicle.VehicleRef       = stopVisit?.GetByBPath <string>("VehicleRef/Value");
                busStop.IncomingVehicles.Add(incomingVehicle);
            }

            return(busStop);
        }
 public VehicleJourneyDto ToDto(VehicleJourney vehicleJourney)
 {
     return(new VehicleJourneyDto
     {
         VehicleId = vehicleJourney.VehicleId,
         Latitude = vehicleJourney.Latitude,
         Longitude = vehicleJourney.Longitude,
         Timestamp = vehicleJourney.Timestamp,
         EventCode = vehicleJourney.EventCode.ToString(),
         JourneyStart = vehicleJourney.JourneyStart,
         JourneyEnd = vehicleJourney.JourneyEnd
     });
 }