/// <summary> /// If route begins with walking sections, they are missing arrival and departure times /// This method, finds first driveSection, and backwards inserts times in walksections /// </summary> /// <param name="foundRoute"></param> private void FindMissingTimesInFirstWalkRoutes(ref RoutePath foundRoute) { if (foundRoute != null) { // fistly find the first RouteSectionDrive int i = 0; while ((foundRoute.RouteSections[i] is RouteSectionWalk) & i < foundRoute.RouteSections.Count - 1) { i++; } if ((i > 0) & (i < foundRoute.RouteSections.Count)) { // sections found! RouteSection section = foundRoute.RouteSections[i]; long departureTime = section.Stops.First().Time; // walk backwards to fill our times in walking sections! for (var s = i - 1; s >= 0; s--) { // a walk section has two stops! var arrivalStop = foundRoute.RouteSections[s].Stops[1]; arrivalStop.Time = departureTime; var departureStop = foundRoute.RouteSections[s].Stops[0]; departureStop.Time = departureTime - (foundRoute.RouteSections[s] as RouteSectionWalk).WalkTime; departureTime = departureStop.Time; } } } }
public ActionResult EditSection(RouteSection rs) { if (ModelState.IsValid) { db.Entry(rs).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("ManageSection")); } return(View(rs)); }
/// <summary> /// Creates a new MSB3 with all sections empty. /// </summary> public MSB3() { Models = new ModelSection(); Events = new EventSection(); Regions = new PointSection(); Routes = new RouteSection(); Layers = new LayerSection(); Parts = new PartsSection(); PartsPoses = new PartsPoseSection(); BoneNames = new BoneNameSection(); }
public ActionResult EditSection(int id = 0) { ViewBag.Routes = new SelectList(db.Routes, "routeID", "routeName"); RouteSection rs = db.RouteSections.Find(id); if (rs == null) { return(HttpNotFound()); } return(View(rs)); }
/// <summary> /// Adds a new section to the database. /// </summary> /// <param name="name">Name of the section.</param> /// <param name="routeHallId">The id of the routeHall the section is in.</param> public void AddSection(string name, int?routeHallId) { RouteSection section = new RouteSection { Name = name, RouteHall = GetRouteHallById(routeHallId) }; _dbContext.RouteSections.Add(section); _dbContext.SaveChanges(); }
/// <summary> /// Archives a section if all the routes in the section are archived. /// </summary> /// <param name="sectionId">Id that matches the section to be archived.</param> public void ArchiveSection(int?sectionId) { RouteSection section = _dbContext.RouteSections.Include(s => s.Routes) .ThenInclude(s => s.Route) .First(s => s.RouteSectionID == sectionId); if (section.Routes.All(r => r.Route.Archived)) { section.Archived = true; _dbContext.RouteSections.Update(section); _dbContext.SaveChanges(); } }
public ActionResult CreateRouteSection([Bind(Include = "sectionID,sectionStart,sectionEnd,sectionDistance,routeID")] RouteSection routeSection) { if (ModelState.IsValid) { PointOfInterest pointOfInterest = db.PointOfInterests.Find(routeSection.POI_ID); routeSection.PointOfInterests.Add(pointOfInterest); db.RouteSections.Add(routeSection); db.SaveChanges(); return(RedirectToAction("CreateRouteSection", routeSection.routeID)); } //ViewBag.achievementID = new SelectList(db.Achievements, "achievementID", "achievementName", route.achievementID); ViewBag.POI_ID = new SelectList(db.PointOfInterests, "POI_ID", "POI_Name", routeSection.POI_ID); return(View(routeSection)); }
public Section(string routeId, string routePathId, int index, RouteSection section) { RouteId = routeId; RoutePathId = routePathId; Index = index; SequenceNumber = section.SequenceNumber; MinimumRunningTime = section.MinimumRunningTime; ResourcesOccupied = section.ResourceOccupations.Any() ? section.ResourceOccupations.Select(r => r.ResourceId).ToArray() : new string[0]; Penalty = section.Penalty ?? 0; AlternativeMarkerAtEntry = section.AlternativeMarkerAtEntry; AlternativeMarkerAtExit = section.AlternativeMarkerAtExit; SectionMarker = section.SectionMarkers?.FirstOrDefault(); Key = GetKey(RouteId, SequenceNumber); }
public static GeoRoute Parse(string geoJsonFeatureCollection) { var routeSections = new List <RouteSection>(); var lastDistance = 0f; var lastTime = TimeSpan.Zero; var featureCollection = JsonConvert.DeserializeObject <FeatureCollection>(geoJsonFeatureCollection); foreach (var feature in featureCollection.Features) { if (feature.Type == GeoJSON.Net.GeoJSONObjectType.Feature && feature.Geometry.Type == GeoJSON.Net.GeoJSONObjectType.LineString) { var section = new RouteSection(); section.FromDistance = lastDistance; section.FromTime = lastTime; if (feature.Properties.TryGetValue("name", out var name)) { section.Name = (string)name; } else { section.Name = "N/A"; } section.ToDistance = float.Parse((string)feature.Properties["distance"]); section.ToTime = TimeSpan.FromSeconds(double.Parse((string)feature.Properties["time"])); var lineString = feature.Geometry as LineString; foreach (var coordinate in lineString.Coordinates) { var position = coordinate as GeographicPosition; section.Coordinates.Add(new GeoCoordinate(position.Latitude, position.Longitude)); } routeSections.Add(section); lastDistance = section.ToDistance; lastTime = section.ToTime; } } return(new GeoRoute(routeSections)); }
/// <summary> /// Register routes contained in Web.Config to the RouteTable /// </summary> public void Init(HttpApplication application) { if (first) { // Get the Routes from Web.config RouteSection config = (RouteSection)ConfigurationManager.GetSection("system.web/routeTable"); if (config == null) { return; } // Add each Route to RouteTable using (RouteTable.Routes.GetWriteLock()) { RouteTable.Routes.Clear(); foreach (RouteElement element in config.Routes) { var dataTokens = new RouteValueDictionary { { "EntityType", element.EntityType }, }; // handle special case of SEName. Break it into parts, so Routing parser can understand multi-dash Urls if (element.Url.Contains("-{SEName}")) { string Url = element.Url.Replace("-{SEName}", "-{SEPart1}-{SEPart2}-{SEPart3}-{SEPart4}-{SEPart5}-{SEPart6}-{SEPart7}-{SEPart8}-{SEPart9}-{SEPart10}-{SEPart11}-{SEPart12}-{SEPart13}-{SEPart14}-{SEPart15}-{SEPart16}-{SEPart17}-{SEPart18}-{SEPart19}-{SEPart20}-{SEPart21}-{SEPart22}-{SEPart23}-{SEPart24}-{SEPart25}-{SEPart26}-{SEPart27}-{SEPart28}-{SEPart29}-{SEPart30}"); for (int c = 30; c >= 0; c--) { RouteTable.Routes.Add(element.Name + c.ToString(), new Route(Url, null, null, dataTokens, new WebFormRouteHandler(element.VirtualPath, element.CheckPhysicalUrlAccess))); Url = Url.Replace("-{SEPart" + c.ToString() + "}", string.Empty); } } var route = new Route(element.Url, new WebFormRouteHandler(element.VirtualPath, element.CheckPhysicalUrlAccess)); route.DataTokens = dataTokens; RouteTable.Routes.Add(element.Name, route); } } } first = false; }
/// <summary> /// Adds the given route to the given sections by their sectionId. /// </summary> /// <param name="route">The route to be added to the sections.</param> /// <param name="sectionIds">The ids of the sections where the route is to be added.</param> public void AddRouteToSections(Route route, List <int> sectionIds) { if (sectionIds == null) { return; } foreach (var sectionId in sectionIds) { RouteSection section = _dbContext.RouteSections.Include(h => h.RouteHall) .First(s => s.RouteSectionID == sectionId); section.Routes.Add(new RouteSectionRelation { RouteSection = section, Route = route }); } _dbContext.SaveChanges(); }
public void RouteSectionTest() { var json = @"{ ""sequence_number"": 1, ""route_alternative_marker_at_exit"": [ ""M1"" ], ""section_marker"": [ ""A"" ], ""resource_occupations"": [ { ""resource"": ""A1"", ""occupation_direction"": null }, { ""resource"": ""AB"", ""occupation_direction"": null } ], ""penalty"": null, ""starting_point"": ""A"", ""minimum_running_time"": ""PT53S"", ""ending_point"": ""A"" }"; try { var obj = new RouteSection(); obj.FromJson(json); Assert.AreEqual(obj.SequenceNumber, 1); Assert.AreEqual(obj.RouteAlternativeMarkersAtExit[0], "M1"); Assert.AreEqual(obj.SectionMarkers[0], "A"); } catch (Exception ex) { Assert.Fail(ex.Message); } }
public ActionResult CreateRouteSection(int?id) { //ViewBag.routeID = new SelectList(db.Routes, "routeID"); //Route route = db.Routes.Find(id); //if (id == null) //{ // return new HttpStatusCodeResult(HttpStatusCode.BadRequest); //} Route route = db.Routes.Find(id); if (route == null) { return(HttpNotFound()); } //ViewBag.RouteID = id; RouteSection routeSection = new RouteSection(); routeSection.routeID = route.routeID; ViewBag.RouteName = route.routeName; ViewBag.POI_ID = new SelectList(db.PointOfInterests, "POI_ID", "POI_Name"); return(View(routeSection)); }
/// <summary> /// Archives all routes in the section by the given sectionId. /// </summary> /// <param name="sectionId">Id that matches the section where all the routes should be archived.</param> public void ArchiveAllRoutesInSection(int?sectionId) { List <RouteSectionRelation> relations = _dbContext.RouteSectionRelations .Include(rs => rs.Route) .Include(rs => rs.RouteSection) .Where(rs => rs.RouteSectionID == sectionId) .ToList(); RouteSection section = _dbContext.RouteSections .Include(s => s.Routes) .FirstOrDefault(s => s.RouteSectionID == sectionId); if (section?.Routes?.Count > 0) { foreach (RouteSectionRelation relation in relations) { relation.Route.Archived = true; _dbContext.Routes.Update(relation.Route); } _dbContext.SaveChanges(); } }
private void AddSection(int index, string routeId, string pathId, RouteSection routeSection) { var key = Section.GetKey(routeId, routeSection.SequenceNumber); _sections.Add(key, new Section(routeId, pathId, index, routeSection)); var section = _sections[key]; var edge = this.AddEdge(section.EntryMarker, section.SectionMarker, section.ExitMarker); edge.Attr.Id = key; if (!_nodes.ContainsKey(section.EntryMarker)) { _nodes.Add(section.EntryMarker, new Node(section.EntryMarker)); } if (!_nodes.ContainsKey(section.ExitMarker)) { _nodes.Add(section.ExitMarker, new Node(section.ExitMarker)); } _nodes[section.EntryMarker].OutputEdgeIds.Add(key); _nodes[section.ExitMarker].InputEdgeIds.Add(key); }
public ActionResult SectionDetails() { RouteSection rs = db.RouteSections.First(); return(View(rs)); }
internal override void Read(BinaryReaderEx br) { br.BigEndian = false; br.AssertASCII("MSB "); br.AssertInt32(1); // Header size/data start br.AssertInt32(0x10); // Probably bytes, just guessing br.AssertByte(0); br.AssertByte(0); br.AssertByte(1); br.AssertByte(0xFF); Entries entries = default; long nextSectionOffset = br.Position; while (nextSectionOffset != 0) { br.Position = nextSectionOffset; int unk1 = br.ReadInt32(); int offsets = br.ReadInt32() - 1; long typeOffset = br.ReadInt64(); string type = br.GetUTF16(typeOffset); switch (type) { case "MODEL_PARAM_ST": Models = new ModelSection(br, unk1); entries.Models = Models.Read(br, offsets); break; case "EVENT_PARAM_ST": Events = new EventSection(br, unk1); entries.Events = Events.Read(br, offsets); break; case "POINT_PARAM_ST": Regions = new PointSection(br, unk1); entries.Regions = Regions.Read(br, offsets); break; case "ROUTE_PARAM_ST": Routes = new RouteSection(br, unk1); entries.Routes = Routes.Read(br, offsets); break; case "LAYER_PARAM_ST": Layers = new LayerSection(br, unk1); entries.Layers = Layers.Read(br, offsets); break; case "PARTS_PARAM_ST": Parts = new PartsSection(br, unk1); entries.Parts = Parts.Read(br, offsets); break; case "MAPSTUDIO_PARTS_POSE_ST": PartsPoses = new PartsPoseSection(br, unk1, offsets); break; case "MAPSTUDIO_BONE_NAME_STRING": BoneNames = new BoneNameSection(br, unk1); entries.BoneNames = BoneNames.Read(br, offsets); break; default: throw new NotImplementedException($"Unimplemented section: {type}"); } nextSectionOffset = br.ReadInt64(); } DisambiguateNames(entries.Events); DisambiguateNames(entries.Models); DisambiguateNames(entries.Parts); DisambiguateNames(entries.Regions); Events.GetNames(this, entries); Parts.GetNames(this, entries); Regions.GetNames(this, entries); }
/// <summary> /// Egy adott szomszédossági mátrixban (a mátrix elemei gráf csomópontok, a térkép pontjai az /// indexeikkel vannak reprezentálve) /// megkeresi a start-csomópont pont és a cél-csomópont között a legrövidebb utat /// </summary> /// <param name="adjacencyMatrix">szomszédossági mátrix, gráf-csomópontok</param> /// <param name="startVertex">kezdő csomópont, a kezdő pont indexe</param> /// <param name="endVertex">cél csomópont, a cél pont indexe</param> /// <param name="pointsA">a térkép pontjainak listája</param> /// <param name="str">egy sztring, mely megmondja, hogy egy szintes a keresés: "", /// liftet kell használni: "lifttel", vagy lépcsőt kell használni: "lépcsőn"</param> /// <param name="L">a szintek közötti különbség</param> /// <returns>a legrövideb utat képező szakaszok listáját adja vissza</returns> public static List <RouteSection> dijkstraPath(float[,] adjacencyMatrix, int startVertex, int endVertex, List <PointF> pointsA, string str, int L) { int nVertices = adjacencyMatrix.GetLength(0); float[] shortestDistances = new float[nVertices]; bool[] added = new bool[nVertices]; for (int vertexIndex = 0; vertexIndex < nVertices; vertexIndex++) { shortestDistances[vertexIndex] = float.MaxValue; added[vertexIndex] = false; } shortestDistances[startVertex] = 0; int[] parents = new int[nVertices]; parents[startVertex] = NO_PARENT; PointF[] parentPoints = new PointF[nVertices]; for (int i = 1; i < nVertices; i++) { int nearestVertex = -1; float shortestDistance = float.MaxValue; for (int vertexIndex = 0; vertexIndex < nVertices; vertexIndex++) { if (!added[vertexIndex] && shortestDistances[vertexIndex] < shortestDistance) { nearestVertex = vertexIndex; shortestDistance = shortestDistances[vertexIndex]; } } if (nearestVertex != -1) { added[nearestVertex] = true; } else { Console.WriteLine("üres mátrixszal nem tudunk dolgozni"); } for (int vertexIndex = 0; vertexIndex < nVertices; vertexIndex++) { float edgeDistance = adjacencyMatrix[nearestVertex, vertexIndex]; //nearestvertex: -1 vertexindex:0 if (edgeDistance > 0 && ((shortestDistance + edgeDistance) < shortestDistances[vertexIndex])) { parents[vertexIndex] = nearestVertex; parentPoints[vertexIndex] = pointsA[nearestVertex]; shortestDistances[vertexIndex] = shortestDistance + edgeDistance; } } } List <RouteSection> RouteList = new List <RouteSection>(); List <PointF> myList = setSolution(startVertex, endVertex, parents, pointsA); if (startVertex != endVertex) { String flag = "N"; String flagOrient = ""; RouteSection rs = new RouteSection(); RouteList.Add(rs); RouteList[0].setOrder(1); RouteList[0].setStartPoint(myList[0]); int m = pointsA.IndexOf(myList[0]); int n = pointsA.IndexOf(myList[1]); float dist = adjacencyMatrix[m, n]; RouteList[0].setDistance(dist); RouteList[0].setMessage(" Haladjon előre " + dist + " métert -> "); if (myList[0].X - myList[1].X > 0) { flag = "W"; } else if (myList[0].X - myList[1].X < 0) { flag = "E"; } else if (myList[0].X - myList[1].X < 0) { flag = "N"; } else if (myList[0].X - myList[1].X > 0) { flag = "S"; } for (int i = 1; i < myList.Count - 1; i++) { RouteSection ro_se = new RouteSection(); RouteList.Add(ro_se); RouteList[i].setOrder(i + 1); RouteList[i].setStartPoint(myList[i]); RouteList[i - 1].setEndPoint(myList[i]); float fx = myList[i + 1].X - myList[i].X; float fy = myList[i + 1].Y - myList[i].Y; switch (flag) { case "N": if (fx < 0) { flag = "W"; flagOrient = " Forduljon balra."; } else if (fx > 0) { flag = "E"; flagOrient = " Forduljon jobbra."; } if (fy < 0) { flag = "N"; flagOrient = ""; } break; case "S": if (fx < 0) { flag = "W"; flagOrient = " Forduljon jobbra."; } else if (fx > 0) { flag = "E"; flagOrient = " Forduljon balra."; } if (fy > 0) { flag = "S"; flagOrient = ""; } break; case "E": if (fx > 0) { flag = "E"; flagOrient = ""; } if (fy < 0) { flag = "N"; flagOrient = " Forduljon balra."; } else if (fy > 0) { flag = "S"; flagOrient = " Forduljon jobbra."; } break; case "W": if (fx < 0) { flag = "W"; flagOrient = ""; } if (fy < 0) { flag = "N"; flagOrient = " Forduljon jobbra."; } else if (fy > 0) { flag = "S"; flagOrient = " Forduljon balra."; } break; } m = pointsA.IndexOf(myList[i]); n = pointsA.IndexOf(myList[i + 1]); dist = adjacencyMatrix[m, n]; RouteList[i].setDistance(dist); RouteList[i].setMessage(" " + flagOrient + " Haladjon előre " + dist + " métert -> "); } if (!str.Equals("")) { string strUtil; if (L > 0) { strUtil = "fel"; } else { strUtil = "le"; L = -L; } RouteList[myList.Count - 2].setEndPoint(myList[myList.Count - 1]); string myString = " Menjen " + strUtil + " a " + str + " " + L + " emeletet. "; RouteList[myList.Count - 2].setMessage(RouteList[myList.Count - 2].Message + myString); } else { RouteList[myList.Count - 2].setEndPoint(myList[myList.Count - 1]); RouteList[myList.Count - 2].setMessage(RouteList[myList.Count - 2].Message + " Megérkezett a célhoz! "); } } else { string strStayInOnePlace; if (!str.Equals("")) { string strUtil; if (L > 0) { strUtil = "fel"; } else { strUtil = "le"; L = -L; } strStayInOnePlace = " Menjen " + strUtil + " a " + str + " " + L + " emeletet. "; RouteSection rs = new RouteSection(1, pointsA[startVertex], pointsA[startVertex], 0, strStayInOnePlace); rs.setMessage(strStayInOnePlace); rs.setOrder(1); RouteList.Add(rs); } else { strStayInOnePlace = " Megérkezett a célhoz! "; RouteSection rs = new RouteSection(1, pointsA[startVertex], pointsA[startVertex], 0, strStayInOnePlace); rs.setMessage(strStayInOnePlace); rs.setOrder(1); RouteList.Add(rs); } } return(RouteList); }
public ActionResult Index() { User user = GetUser(); //Using a Cookie here HttpCookie cookie = new HttpCookie("UserID"); cookie["ID"] = user.userID.ToString(); cookie["Gender"] = user.gender; DateTime currentYear = DateTime.Now; DateTime birthYear = user.dateOfBirth; cookie["Distance"] = user.totDistanceTravelled.ToString(); cookie["Age"] = (currentYear.Year - birthYear.Year).ToString(); Response.Cookies.Add(cookie); ////////////////////////////////// //Stephen Added ViewBag.Distance = int.Parse(user.totDistanceTravelled.ToString()); DashboardModel data = new DashboardModel() { achievements = user.Achievements.Reverse().Take(10).ToList(), leaderboard = db.RouteLeaderboards.OrderByDescending(item => item.participantDistance).Take(5).ToList(), currentRoute = db.Routes.OrderByDescending(item => item.routeID).FirstOrDefault() }; List <DistanceLog> distances = db.DistanceLogs.ToList(); double total = 0; foreach (DistanceLog distance in distances) { total += distance.logDistance; } data.distance = total; if (data.currentRoute != null) { List <RouteSection> sections = data.currentRoute.RouteSections.ToList(); int pos = 0; double currentDist = 0; for (int i = 0; i < sections.Count; i++) { RouteSection routeSection = sections[i]; currentDist += routeSection.sectionDistance; if (total < currentDist) { pos = i - 1; break; } } if (pos >= 0) { PointOfInterest poi = sections[pos].PointOfInterests.FirstOrDefault(); data.currentPOI = poi; Image image = poi.Image; ViewBag.Image = "data:" + image.imageContentType + ";base64," + Convert.ToBase64String(image.imageData); } else { data.currentPOI = null; } } else { data.currentPOI = null; } return(View(data)); }