private static void ReadPassenger(XElement passengerSetElement) { EntityData.PassengerDict = new Dictionary <string, PassengerPlot.Passenger>(); foreach (XElement element in passengerSetElement.Elements("Passenger")) { Passenger pa = new PassengerPlot.Passenger() { ID = element.Attribute("ID").Value, Name = element.Attribute("Name").Value }; EntityData.PassengerDict.Add(pa.ID, pa); foreach (XElement eventElement in element.Element("EventList").Elements()) { PassengerEvent e = null; switch (eventElement.Name.LocalName) { case "PassengerPrivateTripEvent": PassengerPrivateTripEvent ept = new PassengerPrivateTripEvent() { Location = System.Windows.Point.Parse(eventElement.Attribute("Location").Value) }; pa.EventList.Add(ept); e = ept; break; case "PassengerActivityEvent": PassengerActivityEvent ea = new PassengerActivityEvent() { ActivityName = eventElement.Attribute("ActivityName").Value, Location = System.Windows.Point.Parse(eventElement.Attribute("Location").Value) }; pa.EventList.Add(ea); e = ea; break; case "PassengerTripEvent": PassengerTripEvent et = new PassengerTripEvent() { AttachedCarriage = EntityData.CarriageList[eventElement.Attribute("AttachedCarriageReferenceVehicleID").Value] }; pa.EventList.Add(et); e = et; break; default: break; } e.Time = Convert.ToInt32(eventElement.Attribute("Time").Value); e.Type = (PassengerEventTypes)Enum.Parse(typeof(PassengerEventTypes), eventElement.Attribute("Type").Value); e.TripType = (TripTypes)Enum.Parse(typeof(TripTypes), eventElement.Attribute("TripType").Value); } } }
private Point CalculateEventLocation(PassengerEvent e) { if (e is PassengerActivityEvent) { return(((PassengerActivityEvent)e).Location); } else if (e is PassengerPrivateTripEvent) { return(((PassengerPrivateTripEvent)e).Location); } else if (e is PassengerTripEvent) { PassengerTripEvent pte = e as PassengerTripEvent; return(pte.AttachedCarriage.GetLocationByTime(e.Time)); } else { return(new Point(-1, -1)); } }
private void PresolvePassengerEventData(string directory) { System.IO.FileStream fs = new System.IO.FileStream(directory + "output/1.seperatePersons.txt", System.IO.FileMode.Open); System.IO.StreamReader sr = new System.IO.StreamReader(fs); sr.ReadLine(); string l = sr.ReadLine(); PassengerEvent lastEvent = null; string lastStationName = ""; int passengerSequence = 0; while (l != null && l.Trim() != "") { string[] data = l.Split('\t'); if (data[5] == "pt interaction") { l = sr.ReadLine(); continue; } Passenger passenger; if (!EntityData.PassengerDict.ContainsKey(data[1])) { passenger = new PassengerPlot.Passenger() { ID = data[1], Name = (passengerSequence++).ToString() }; EntityData.PassengerDict.Add(data[1], passenger); } else { passenger = EntityData.PassengerDict[data[1]]; } PassengerEvent currentEvent; if (data[4] == "actend" || data[4] == "actstart") { currentEvent = AddActivityEvent(passenger, data[4], data[5], (int)Convert.ToDouble(data[2])); } else { currentEvent = SearchCarriage(passenger, data[4], data[5], (int)Convert.ToDouble(data[2])); } if (lastEvent != null && lastEvent.Time != currentEvent.Time && (lastEvent.Type == PassengerEventTypes.ActivityEnd || lastEvent.Type == PassengerEventTypes.TripEnd) && (currentEvent.Type == PassengerEventTypes.ActivityStart || currentEvent.Type == PassengerEventTypes.TripStart)) { bool isOnPublicTrip = false; if (lastEvent is PassengerTripEvent && currentEvent is PassengerTripEvent) { PassengerTripEvent lastPtEvent = lastEvent as PassengerTripEvent; PassengerTripEvent currentPtEvent = currentEvent as PassengerTripEvent; if (lastPtEvent.AttachedCarriage.ID == currentPtEvent.AttachedCarriage.ID) { isOnPublicTrip = true; } } if (!isOnPublicTrip) { AddPrivateTrip(passenger, lastEvent, lastStationName, currentEvent, data[6]); } } lastStationName = data[6]; passenger.EventList.Add(currentEvent); lastEvent = currentEvent; l = sr.ReadLine(); } sr.Close(); fs.Close(); }