// call api to get formatted bus arrival timing of all public buses plying the bus stop public static async Task <string> GetPublicBusesArrivalTiming(string busStopCode) { string display = ""; PublicBusStop pbs = await JsonLoader.LoadPublicBusInfo(busStopCode); // case unable to get data if (pbs == null) { return("Public buses timing currently not available\n"); } foreach (PublicBusSvc service in pbs.Services) { display += service.ServiceNo + ": "; // case not operating if (service.Status.Equals("Not In Operation")) { display += "not operating\n"; } // get next/subsequent bus timing (give +- 1 min offset for public buses timing) if (service.NextBus.EstimatedArrival.HasValue) { var nextTiming = ((TimeSpan)(service.NextBus.EstimatedArrival - DateTime.Now)).Minutes; if (nextTiming >= -1) { display += (nextTiming <= 0) ? "Arr" : ((nextTiming > 60) ? "--" : nextTiming + " min"); } } if (service.SubsequentBus.EstimatedArrival.HasValue) { var nextTiming = ((TimeSpan)(service.SubsequentBus.EstimatedArrival - DateTime.Now)).Minutes; if (nextTiming >= -1) { display += " / "; display += (nextTiming <= 0) ? "Arr" : ((nextTiming > 60) ? "--" : nextTiming + " min"); } } if (service.SubsequentBus3.EstimatedArrival.HasValue) { var nextTiming = ((TimeSpan)(service.SubsequentBus3.EstimatedArrival - DateTime.Now)).Minutes; if (nextTiming >= -1) { display += " / "; display += (nextTiming <= 0) ? "Arr" : ((nextTiming > 60) ? "--" : nextTiming + " min"); } } display += "\n"; } return(display); }
// 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() : "--"))); }
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); }