public DelaysPage(StopModel stop) { InitializeComponent(); Title = stop.StopDesc; Items = new ObservableCollection <DelayModel>(); DelayViewModel = new DelayViewModel(stop.StopId); }
private void LoadStopsChanged() { try { ObservableCollection <StopModel> stops = new ObservableCollection <StopModel>(); MetroMobiliteService metroMobiliteService = new MetroMobiliteService(); Dictionary <string, Stop> dico = metroMobiliteService.GetStops(Lon, Lat, Int32.Parse(Dist)); foreach (var item in dico.Values) { StopModel model = new StopModel(item.name, item.lat.ToString(), item.lon.ToString()); List <Line> lineDetails = metroMobiliteService.GetLines(item.lines); foreach (var line in lineDetails) { model.Lines.Add(new LineModel { ShortName = line.shortName, LongName = line.longName, Color = line.color, TextColor = line.textColor, Mode = line.mode, Type = line.type }); } stops.Add(model); } Stops = stops; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void RequestStop(StopModel stop) { // you should travel to a stop before requesting a stop to disembark (direction == Any) // as the disembark request is assumed to be from someone already in the lift if (stop.Level < 0 || stop.Level > Lift.Levels.Length - 1) { throw new InvalidOperationException("Invalid Stop"); } if (stop.Level == 0 && stop.Direction == DirectionEnum.Down) { throw new InvalidOperationException("Invalid Summons. Cannot go down from lowest level"); } if (stop.Level == Lift.Levels.Length - 1 && stop.Direction == DirectionEnum.Up) { throw new InvalidOperationException("Invalid Summons. Cannot go up from highest level"); } if (Lift.CurrentLevel == stop.Level) { // already here - open doors Lift.DoorsOpen = true; return; } AcceptStop(stop); }
public void Delete(StopModel objectToDelete) { using (var db = GetDbConn()) { db.Delete(objectToDelete); } }
public void LoadStops() { Dist = "500"; Lat = "5.7253605"; Lon = "45.1910605"; ObservableCollection <StopModel> stops = new ObservableCollection <StopModel>(); MetroMobiliteService metroMobiliteService = new MetroMobiliteService(); Dictionary <string, Stop> dico = metroMobiliteService.GetStops(Lon, Lat, Int32.Parse(Dist)); foreach (var item in dico.Values) { StopModel model = new StopModel(item.name, item.lat.ToString(), item.lon.ToString()); List <Line> lineDetails = metroMobiliteService.GetLines(item.lines); foreach (var line in lineDetails) { model.Lines.Add(new LineModel { ShortName = line.shortName, LongName = line.longName, Color = line.color, TextColor = line.textColor, Mode = line.mode, Type = line.type }); } stops.Add(model); } Stops = stops; }
public void DeleteStop(StopModel stopToDelete) { ChooseBusStopDelayService.DeleteFromDb(stopToDelete); var toDelete = Items.FirstOrDefault(x => x.StopModel.StopId == stopToDelete.StopId); Items.Remove(toDelete); }
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); }
public IHttpActionResult RequestStop(StopModel model) { var lift = HttpContext.Current.Application["Lift"]; var liftService = new LiftService((Lift)lift); liftService.RequestStop(model); HttpContext.Current.Application["Lift"] = liftService.Lift; return(Ok()); }
static MarkerModel MarkerMapper(StopModel stopModel) { return(new MarkerModel() { StopId = stopModel.StopId, StopDesc = stopModel.StopDesc, StopLat = stopModel.StopLat, StopLon = stopModel.StopLon, StopBusLines = stopModel.BusLineNames, StopHeading = stopModel.DestinationHeadsigns }); }
public ActionResult Stop(StopModel model) { if (ModelState.IsValid) { StopDto stop = this.stopService.Create(((ClaimsPrincipal)this.User).AppUserId(), model.GroupId, model.Reason); Microsoft.AspNet.SignalR.GlobalHost.ConnectionManager.GetHubContext <GroupHub>() .Clients.All.groupLifeCycleStateChange(this.tenantContext.FriendlyName, Web.Models.Group.LifeCycleState.Stopped.ToString()); return(RedirectToAction("Index", "Dashboard")); } return(PartialView(model)); }
protected StopModel GetStopFromStopRef(OpenArchive gtfsArchive, string stopRef) { if (stopsList == null) { using (Stream stopsStream = gtfsArchive.zip.GetEntry("google_transit/stops.csv").Open()) { this.stopsList = CsvSerializer.DeserializeFromStream <List <StopModel> >(stopsStream); } } StopModel stopObj = stopsList.FirstOrDefault(o => o.stop_code == stopRef); return(stopObj); }
public SearchAddressViewModel() { stopService = (App.Current as App).Container.GetService <IStopService>(); // New up our observable collection AddressesFound = new ObservableCollection <StringWrapper>(); SearchCommand = new RelayCommand(async() => { // If our button is showing "search", let's do the following if (SearchAddButtonText == "Search") { // Reset everything AddressesFound.Clear(); AddressSelected = new StringWrapper(); MapLocationFinderResult result = await MapLocationFinder.FindLocationsAsync(BuildingNumber + " " + StreetName + ", " + PostCode, null); if (result.Status == MapLocationFinderStatus.Success) { MapAddress address = result.Locations.FirstOrDefault().Address; Geopoint point = result.Locations.FirstOrDefault().Point; var stringw = new StringWrapper { StringContent = address.FormattedAddress, TempLatitude = Convert.ToDecimal(point.Position.Latitude), TempLongitude = Convert.ToDecimal(point.Position.Longitude) }; AddressesFound.Add(stringw); } else { return; } } else // it's basically showing "Add" at this point, so add our item to the list of stops { StopModel stopModel = new StopModel() { Name = StopName, Address = AddressSelected.StringContent, Latitude = AddressSelected.TempLatitude, Longitude = AddressSelected.TempLongitude }; stopService.AddStop(stopModel); } }); }
public int Compare(object x, object y) { StopModel model1 = x as StopModel, model2 = y as StopModel; double val1 = model1.HighestPriority - model2.HighestPriority; if (val1 != 0) { return(Math.Sign(val1)); } int val2 = model2.RouteCount - model1.RouteCount; if (val2 != 0) { return(val2); } return(model1.ComparableName.CompareTo(model2.ComparableName)); }
public void SaveStopModel(StopModel stopModel) { using (var db = GetDbConn()) { db.CreateTable <StopModel>(); var oldStopModel = db.Table <StopModel>().SingleOrDefault(stop => stop.StopId == stopModel.StopId); if (oldStopModel != null && oldStopModel.StopId >= 0) { return; } db.CreateTable <StopModel>(); db.Insert(stopModel); } }
private List <StopModel> GetData(string query) { var results = new List <StopModel>(); var busRuns = new List <BusModel>(); string uri = "https://services.portauthority.org/PAACServices/api/"; String urlParameters = query; HttpClient client = new HttpClient(); client.BaseAddress = new Uri(uri); // Add an Accept header for JSON format client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/xml")); // List data response HttpResponseMessage response = client.GetAsync(urlParameters).Result; if (response.IsSuccessStatusCode) { // Parse the response body. var responseResult = response.Content.ReadAsStringAsync().Result; var busResults = (List <BusModel>)Newtonsoft.Json.JsonConvert.DeserializeObject(responseResult, typeof(List <BusModel>)); var stops = busResults.Select(x => new { x.Stpid, x.Stpnm }).Distinct(); foreach (var s in stops) { var stop = new StopModel(); stop.StopId = s.Stpid; stop.StopName = s.Stpnm; var b = busResults.Select(x => x).Where(x => x.Stpid == stop.StopId).ToList(); stop.BusRuns = b; results.Add(stop); } } return(results); }
private StopModel CreateStopModel(List <Consignment> consignments, RttSiteDefault site) { var stopModel = new StopModel { DueTime = consignments[0].PlannedStopArrivalTime.GetValueOrDefault(), LocationId = utils.ResolveDecoId(consignments[0], site), TimeAtStop = SumConsignmentStopTimes(consignments), Visits = new List <StopVisitModel>() { CreateStopVisitModel(consignments, site) }, PathToStop = new PathModel() { Distance = consignments[0].PlannedTravelDistance, TravelTime = TimeSpan.FromMinutes(consignments[0].PlannedTravelDuration) } }; return(stopModel); }
private void AcceptStop(StopModel stop) { switch (stop.Direction) { case DirectionEnum.Up: Lift.Levels[stop.Level].SummonsUp = true; break; case DirectionEnum.Down: Lift.Levels[stop.Level].SummonsDown = true; break; case DirectionEnum.Any: default: Lift.Disembark.Add(stop.Level); break; } if (Lift.CurrentDirection == DirectionEnum.Any) { // first request - set our direction Lift.CurrentDirection = stop.Level > Lift.CurrentLevel ? DirectionEnum.Up : DirectionEnum.Down; } }
public void DeleteFromDb(StopModel item) { _databaseRepository.Delete(item); }
public void Navigate(Type type, StopModel stop) => ChooseBusStopDelayService.Navigate(type, stop);
public void AddStopAtIndex(object stop, int index) { StopModel stopModel = stop as StopModel; Stops.Insert(index, stopModel); }
public int RetrieveIndexOfStop(object stop) { StopModel stopModel = stop as StopModel; return(Stops.IndexOf(stopModel)); }
public void RemoveStop(object stop) { StopModel stopModel = stop as StopModel; Stops.Remove(stopModel); }
public void AddStop(object stop) { StopModel stopModel = stop as StopModel; Stops.Add(stopModel); }
public async Task SetContent(bool full, Func <object, bool> searchFilter = null) { searchFilter = searchFilter ?? (o => true); if (SearchText.Text.Length == 0) { var history = await Task.Run(() => App.UB.History.StopEntries .GroupBy(p => p.Stop) .Select(x => Tuple.Create(x.Key, x.Min(e => HistoryHelpers.DayPartDistance(e)), x.Sum(p => p.RawCount))) .OrderByDescending(t => t.Item3) .OrderBy(t => t.Item2) ); ClearContent(); CategorySelector.Visibility = Visibility.Visible; HistoryList.Visibility = Visibility.Visible; HistoryList.ItemsSource = history.Select(t => new StopModel(t.Item1)).Take(8).ToArray(); ResetSearchResult(); } else { IEnumerable <StopModel> stops = new StopModel[0]; IEnumerable <RouteGroup> routes = new RouteGroup[0]; string searchText = SearchText.Text; if (searchText.Length > 0) { routes = await Task.Run(() => App.Model.FindRoutes(searchText) .OrderByText(r => r.Name) .ToList() ); } if (searchText.Length >= 3) { //elvileg nem teljesen pontos, mert lehetnek azonos route-ok a szummában de közelítésnek megteszi //+ A megálló végállomásként is számít stops = await Task.Run(() => App.Model .FindStops(searchText) .Select(s => new StopModel(s, true, true)) .OrderByText(s => s.Name) .OrderByDescending(s => s.RouteCount) .OrderBy(s => s.HighestPriority) .ToList() ); } ClearContent(); if (stops.Take(1).Count() == 0) { RouteList.Visibility = Visibility.Visible; RouteList.ItemsSource = full ? routes.Where(o => searchFilter(o)).ToList() : routes.Take(5).ToList(); } else if (routes.Take(1).Count() == 0) { var stops1 = full ? stops.ToList() : stops.Take(5).ToList(); StopList.Visibility = Visibility.Visible; StopList.ItemsSource = stops1.Where(searchFilter).ToList(); } else { var firstRoutes = routes.Where(r => r.Name.Normalize().Contains(searchText.Normalize())).Cast <object>().ToList(); var lastRoutes = routes.Cast <object>().Except(firstRoutes); var routesAndStops = firstRoutes.Concat(stops).Concat(lastRoutes).ToList(); RouteStopList.Visibility = Visibility.Visible; RouteStopList.ItemsSource = full ? routesAndStops.Where(searchFilter).ToList() : routesAndStops.Take(5).ToList(); } SetSearchResult(stops.Select(s => s.Stop), routes); } }
public async Task <IActionResult> Index([FromRoute] string id) { IList <LineScheduleModel> schedule = new List <LineScheduleModel>(); string responseFromServer; int itemId = 1; DateTime timeNow = DateTime.Now; TimeSpan ts = new TimeSpan(24 + timeNow.Hour, timeNow.Minute, 0); TimeSpan daySpan = new TimeSpan(24, 0, 0); string url = sourceURLHead + "/Line/" + id + "/Route/Sequence/inbound" + sourceURLTail; try { responseFromServer = await getResponseAsync(url); } catch (WebException we) { return(Json("[]")); } // Extract naptanId and commonName for each stop of the route try { JObject routeInfo = JObject.Parse(responseFromServer); string mode = (string)routeInfo.SelectToken("mode"); if (mode != "bus") { return(Json("[]")); } IList <StopModel> routeStopsList = new List <StopModel>(); IList <JToken> results = routeInfo["stopPointSequences"][0]["stopPoint"].ToList(); foreach (JToken res in results) { StopModel nid = JsonConvert.DeserializeObject <StopModel>(res.ToString()); routeStopsList.Add(nid); } // Build a schedule for each station foreach (StopModel stop in routeStopsList) { url = sourceURLHead + "/Line/" + id + "/Timetable/" + stop.id + sourceURLTail; try { responseFromServer = await getResponseAsync(url); } catch (WebException we) { responseFromServer = null; } if (responseFromServer != null) { //Here we want to know the time of the last journey for all days [Monday-Friday],[Saturday],[Sunday] JObject lastJourneysSearch = JObject.Parse(responseFromServer); IList <HourMinuteModel> lastJourneyList = new List <HourMinuteModel>(); results = lastJourneysSearch["timetable"]["routes"][0]["schedules"].Children()["lastJourney"].ToList(); foreach (JToken res in results) { HourMinuteModel lj = JsonConvert.DeserializeObject <HourMinuteModel>(res.ToString()); lastJourneyList.Add(lj); } // As soon as we know the time of the last journey, we have to check which schedule to stick to // E.g. if Saturday/Sunday just started, we should follow Friday/Saturday schedules. int actualScheduleIndex = 0; if (timeNow.DayOfWeek == DayOfWeek.Sunday) { if (ts.Days * 24 * 60 < Int32.Parse(lastJourneyList[2].hour) * 60 + Int32.Parse(lastJourneyList[2].minute)) { actualScheduleIndex = 1; } else { actualScheduleIndex = 2; } } if (timeNow.DayOfWeek == DayOfWeek.Saturday) { if (ts.Days * 24 * 60 < Int32.Parse(lastJourneyList[1].hour) * 60 + Int32.Parse(lastJourneyList[1].minute)) { actualScheduleIndex = 0; } else { actualScheduleIndex = 1; } } if (timeNow.DayOfWeek == DayOfWeek.Monday) { if (ts.Days * 24 * 60 < Int32.Parse(lastJourneyList[0].hour) * 60 + Int32.Parse(lastJourneyList[0].minute)) { actualScheduleIndex = 2; } else { actualScheduleIndex = 0; } } // When we know which schedule to use, build the list of arrival times IList <HourMinuteModel> journeysList = new List <HourMinuteModel>(); results = lastJourneysSearch["timetable"]["routes"][0]["schedules"][actualScheduleIndex]["knownJourneys"].Children().ToList(); foreach (JToken res in results) { HourMinuteModel jrn = JsonConvert.DeserializeObject <HourMinuteModel>(res.ToString()); journeysList.Add(jrn); } List <string> stopTimesList = new List <string>(); foreach (HourMinuteModel hm in journeysList) { TimeSpan span = new TimeSpan(Int32.Parse(hm.hour), Int32.Parse(hm.minute), 0); if (span.Days > 0) { span = span - daySpan; } stopTimesList.Add(span.ToString().Substring(0, 5)); } // Create a new LineSchedule object schedule.Add(new LineScheduleModel(itemId++, stop.name, stopTimesList)); } else { List <string> noresult = new List <string>(); noresult.Add("The schedule for the station is not available at the moment"); schedule.Add(new LineScheduleModel(itemId++, stop.name, noresult)); } } } catch (JsonException je) { return(null); } return(Json(schedule)); }
public void SaveToDb(StopModel item) { _chooseBusStopDelayService.SaveToDb(item); //TODO add toast }
public void Navigate(Type pageType, StopModel stop = null) { NavigationService.Navigate(pageType, stop); }
public async Task InitializeAsync() { try { if (Customer.StopId == Guid.Empty) { var items = await new StopItemController().LocalData.List(new SQLControllerListCriteriaModel { Filter = new List <SQLControllerListFilterField> { new SQLControllerListFilterField { FieldName = "ItemType", ValueLBound = ((int)eItemType.Stop).ToString() } } }); Stop = new StopModel { CustimerId = Customer.Id, Customer = Customer, Created = DateTime.Now, Items = new ObservableCollection <StopItemModel>(items), Status = Enums.WorkStatus.Working, User = new UserModel { Id = Guid.Parse("a3dab4d2-81d6-40a9-a63e-a013f825ba71"), FirstName = "Teo", LastName = "Cerda", Password = "******", UserName = "******", Roles = new List <RoleModel> { new RoleModel { Id = Guid.Parse("247e4561-1c3d-49da-aa2d-dd55902ade73"), Name = "Admin" } } } }; } else { Stop = await new StopController().LoadAsync(Customer.StopId); } int weeks = 4; var weeksToRetrieve = DateTime.Now.AddDays(-(int)SelectedDate.DayOfWeek - (6 * weeks)); List <StopModel> stopHistory = new List <StopModel>(); stopHistory = await new StopController().LocalData.List(new SQLControllerListCriteriaModel { Filter = new List <SQLControllerListFilterField> { new SQLControllerListFilterField { FieldName = "Created", ValueLBound = weeksToRetrieve.ToString(), DateKind = Data.Models.Query.SQLControllerListFilterField.DateKindEnum.Localized } } }); if (!stopHistory.Any()) { stopHistory.Add(Stop); } StopHistory = stopHistory; } catch (System.Exception e) { Debug.WriteLine(e); await Message.DisplayAlertAsync(Title, e.Message, "Ok"); } }
public void SaveToDb(StopModel item) { _databaseRepository.SaveStopModel(item); }
private void Stops_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { // If we are running a switch command, don't do anything if (isSwitchCommandRunning) { // Perform re-routing mechanism here since we swapped // the indexes of our stops PerformReroutingOfPoints(); return; } // If we have no more stops, clear our map layers and reset our // center to our default position if (Stops.Count == 0) { // Remove any pushpins MapLayers.Clear(); // Set Center to default position Center = new Geopoint(defaultPosition); return; } // For old items, remove the map elements, for new items, add them if (e.OldItems != null) { foreach (var old in e.OldItems) { StopModel stop = old as StopModel; // Remove our removed stop from the map elements of its corresponding // pushpin if (mapElements.Any(x => ((MapIcon)x).Title == stop.Name)) { mapElements.Remove(mapElements.Where(x => ((MapIcon)x).Title == stop.Name).First()); } } } if (e.NewItems != null) { foreach (var newItem in e.NewItems) { StopModel stop = newItem as StopModel; var stopGeopoint = new Geopoint( new BasicGeoposition() { Latitude = decimal.ToDouble(stop.Latitude), Longitude = decimal.ToDouble(stop.Longitude) }); var poi = new MapIcon { Location = stopGeopoint, NormalizedAnchorPoint = new Point(0.5, 1.0), Title = stop.Name, ZIndex = 0 }; // Add newly created pushpin to our map elements mapElements.Add(poi); } } // Recreate the layer var layer = new MapElementsLayer { ZIndex = 1, MapElements = mapElements }; MapLayers.Clear(); MapLayers.Add(layer); // Perform re-routing mechanism PerformReroutingOfPoints(); }