コード例 #1
0
ファイル: BusHelper.cs プロジェクト: nusbusmap/NUSBusMap
        // call api to get bus arrival timing of particular bus service plying the bus stop
        public static async Task <string> GetPublicBusesArrivalTiming(string busStopCode, string busSvcNo)
        {
            PublicBusStop pbs = await JsonLoader.LoadPublicBusInfo(busStopCode, busSvcNo);

            // case unable to get data
            if (pbs == null)
            {
                return("Public buses timing currently not available\n");
            }

            PublicBusSvc service = pbs.Services [0];

            // case not operating
            if (service.Status.Equals("Not In Operation"))
            {
                return("not operating");
            }

            // return next/subsequent/subsequent3 timing
            return((service.NextBus.EstimatedArrival.HasValue) ? ((TimeSpan)(service.NextBus.EstimatedArrival - DateTime.Now)).Minutes.ToString() :
                   ((service.SubsequentBus.EstimatedArrival.HasValue) ? ((TimeSpan)(service.SubsequentBus.EstimatedArrival - DateTime.Now)).Minutes.ToString() :
                    ((service.SubsequentBus3.EstimatedArrival.HasValue) ? ((TimeSpan)(service.SubsequentBus3.EstimatedArrival - DateTime.Now)).Minutes.ToString() : "--")));
        }
コード例 #2
0
ファイル: BusHelper.cs プロジェクト: nusbusmap/NUSBusMap
        public static async Task <List <PublicBusOnRoad> > GetPublicBuses(string busStopCode)
        {
            List <PublicBusOnRoad> publicBuses = new List <PublicBusOnRoad> ();
            PublicBusStop          pbs         = await JsonLoader.LoadPublicBusInfo(busStopCode);

            // case unable to get data
            if (pbs == null)
            {
                return(publicBuses);
            }

            foreach (PublicBusSvc service in pbs.Services)
            {
                // case not operating, or public bus not shown on map -- ignore
                if (service.Status.Equals("Not In Operation") || !PublicBusSvcOnMap.Contains(service.ServiceNo))
                {
                    continue;
                }

                // add to list after adding service info to bus (for display purpose)
                service.NextBus.ServiceNo            = Regex.Replace(service.ServiceNo, @"[^\d]", String.Empty);       // ignore alphabet in serviceno when displaying bus position
                service.SubsequentBus.ServiceNo      = Regex.Replace(service.ServiceNo, @"[^\d]", String.Empty);
                service.SubsequentBus3.ServiceNo     = Regex.Replace(service.ServiceNo, @"[^\d]", String.Empty);
                service.NextBus.OriginatingID        = service.OriginatingID;
                service.SubsequentBus.OriginatingID  = service.OriginatingID;
                service.SubsequentBus3.OriginatingID = service.OriginatingID;
                service.NextBus.TerminatingID        = service.TerminatingID;
                service.SubsequentBus.TerminatingID  = service.TerminatingID;
                service.SubsequentBus3.TerminatingID = service.TerminatingID;

                publicBuses.Add(service.NextBus);
                publicBuses.Add(service.SubsequentBus);
                publicBuses.Add(service.SubsequentBus3);
            }

            return(publicBuses);
        }
コード例 #3
0
ファイル: BusHelper.cs プロジェクト: joycelynng/NUSBusMap
 public static void LoadBusData()
 {
     BusStops    = JsonLoader.LoadStops();
     BusSvcs     = JsonLoader.LoadSvcs();
     ActiveBuses = new Dictionary <string, BusOnRoad> ();
 }