private List <TripData> ParseTripData(IFormFile file) { var tripData = new List <TripData>(); var reader = new BinaryReader(file.OpenReadStream()); var tripEntry = new byte[EntrySize]; int readChars = 0; _signals = _db.SignalMap.ToList(); //Seek over null entry reader.BaseStream.Seek(EntrySize, SeekOrigin.Begin); //Initial read readChars = reader.Read(tripEntry, 0, EntrySize); while (readChars >= EntrySize) { var tripItem = new TripData { Mvid = tripEntry[0], Timestamp = GetEntryTimestamp(tripEntry), SignalType = GetSignal(tripEntry), Value = GetValue(tripEntry) }; tripData.Add(tripItem); readChars = reader.Read(tripEntry, 0, EntrySize); } return(tripData); }
protected override object Converter(JToken trips) { var tripData = new TripData() { Day = DateTime.Parse(trips.Path), Trips = new List <Trip>() }; foreach (var item in trips.Children <JObject>()) { tripData.LastUpdate = item.Value <DateTime>("lastUpdate"); var tripList = item.Value <JArray>("trips"); foreach (var trip in tripList.Children <JObject>()) { var tripToAdd = new Trip() { Id = trip.Value <string>("id"), TripId = trip.Value <int>("tripId"), RouteId = trip.Value <int>("routeId"), TripHeadsign = trip.Value <string>("tripHeadsign"), TripShortName = trip.Value <string>("tripShortName"), DirectionId = trip.Value <int>("directionId"), ActivationDate = trip.Value <DateTime>("activationDate") }; tripData.Trips.Add(tripToAdd); } } return(tripData); }
public void DeleteTrip(TripData model) { using (var db = new DataContext()) { db.Remove(model); db.SaveChanges(); } }
private void Button_Click_1(object sender, RoutedEventArgs e) { //GeoServiceReference.GeoServiceClient client = new GeoServiceReference.GeoServiceClient(); //int r = client.GetTripCountInTime("1392864673070"); // post var request1 = (HttpWebRequest)WebRequest.Create("http://localhost:1292/GeoService.svc/UpdateTripData"); request1.Method = "POST"; request1.ContentType = "text/json"; var tripDataSerializer = new DataContractJsonSerializer(typeof(TripData)); var tripData = new TripData { eventType = "begin", tripId = 12345, lat = 10.0, lng = 11.0, fare = 9, epoch = 123456 }; string body; using (var memoryStream = new MemoryStream()) using (var reader2 = new StreamReader(memoryStream)) { tripDataSerializer.WriteObject(memoryStream, tripData); memoryStream.Position = 0; body = reader2.ReadToEnd(); } using (var streamWriter = new StreamWriter(request1.GetRequestStream())) { streamWriter.Write(body); } HttpWebResponse response1 = request1.GetResponse() as HttpWebResponse; Stream stream1 = response1.GetResponseStream(); StreamReader reader1 = new StreamReader(stream1); string r1 = reader1.ReadToEnd(); // get var request = (HttpWebRequest)WebRequest.Create("http://localhost:1292/GeoService.svc/TripCountInTime/123456"); HttpWebResponse response = request.GetResponse() as HttpWebResponse; Stream stream = response.GetResponseStream(); StreamReader reader = new StreamReader(stream); string r = reader.ReadToEnd(); }
public void TripDataTestSetup() { var timeStart = new DateTime(2009, 01, 01, 4, 20, 00); var timeEnd = new DateTime(2009, 01, 01, 6, 27, 1); string startlng = "50"; string startlat = "50"; string maxSpeed = "80"; string fuelEff = "0"; string fuelLevel = "50"; string endlng = "70"; string endlat = "70"; tripData = new TripData(timeStart, timeEnd, maxSpeed, endlat, endlng, fuelEff, fuelLevel, startlat, startlng); nullTripData = new TripData(timeStart, null, maxSpeed, endlat, endlng, fuelEff, fuelLevel, startlat, startlng); }
public void AddTrip(TripData data) { if (data.eventType == "begin" && !startTrip.Contains(data.tripId)) { startTrip.Add(data.tripId); } else if (data.eventType == "end" && !endTrip.Contains(data.tripId)) { endTrip.Add(data.tripId); } if (!trips.Contains(data.tripId)) { trips.Add(data.tripId); } }
public void SaveTrip(TripData model) { using (var db = new DataContext()) { if (model.TripDataId > 0) { db.Attach(model); db.Update(model); } else { db.Add(model); } db.SaveChanges(); } }
private TripData CalculateSpped(string name, Trip trip) { var time = trip.End - trip.Start; var mph = trip.Distance / Math.Round(time.TotalHours, 2); mph = Math.Round(mph, 0, MidpointRounding.AwayFromZero); var result = new TripData() { Name = name, Hours = time.TotalHours, Miles = trip.Distance, MilesPerHour = mph, ValidTrip = mph > minSpeed && mph < maxSpeed }; return(result); }
private void saveClient_Click(object sender, RoutedEventArgs e) { NewTrip = new TripData { CustomerName = ClientName.Text, CustomerPhone1 = PhoneNumber.Text, TripStartTime = Convert.ToDateTime(PickTime.Time.ToString()), IsTripStarted = false, IsTripComplete = false, IsPaymentComplete = false, TripType = SelectedJobType, Mode = SelectedPayMode }; DiagResult = ContentDialogResult.Primary; this.Hide(); }
// Adding a trip to tree node based on the current location of the trip public bool Insert(TripData data, Trip trip) { if (!ContainedRegion.Contains(data.lat, data.lng)) { return(false); } if (!this.TreeNodeData.Trips.Contains(data.tripId)) { if (this.Count < this.Capacity) { this.TreeNodeData.AddTrip(data); this.Count += 1; return(true); } if (this.NorthWest == null) { this.divide(); } if (this.NorthWest.Insert(data, trip)) { return(true); } if (this.NorthEast.Insert(data, trip)) { return(true); } if (this.SouthWest.Insert(data, trip)) { return(true); } if (this.SouthEast.Insert(data, trip)) { return(true); } } else { this.TreeNodeData.AddTrip(data); } return(true); }
public async static Task <List <TripData> > getScheduleOfTrip(String routeID, int direction_id, string tripID, string stop) { string url = globalURL + "/schedules?filter[date]=" + getLocalTime() + "&filter[direction_id]=" + direction_id + "&filter[route]=" + routeID + "&filter[trip]=" + tripID + "&filter[stop]=" + stop + "&sort=departure_time"; string response = await DataFetcher.fetchData(url); TripBundle raw_data = JsonConvert.DeserializeObject <TripBundle>(response); List <TripData> tripList = new List <TripData>(); for (int i = 0; i < raw_data.data.Length; i++) { TripData _trip = raw_data.data[i]; tripList.Add(_trip); } return(tripList); }
TripsWithBusStops Map(BusLineData busLine, ExpeditionData expeditionObject, TripData tripData, BusStopData busStopData, StopInTripData stopInTripData) { var tripsWithBusStops = new TripsWithBusStops() { Day = busLine.Day, Trips = new List <Trip>() }; busLine.Routes.ForEach(route => { var tripListByRouteId = tripData.Trips.Where(x => x.RouteId == route.RouteId).ToList(); tripListByRouteId.ForEach(tripByRouteId => { var expedition = expeditionObject.Expeditions .FirstOrDefault(exp => exp.RouteId == tripByRouteId.RouteId && exp.TripId == tripByRouteId.TripId && (exp.StartDate.Date == busLine.Day.Date || exp.StartDate.Date < busLine.Day.Date)); if (expedition == null || expedition.TechnicalTrip) { return; } tripsWithBusStops.Trips.Add( new Trip() { Id = tripByRouteId.Id, TripId = tripByRouteId.TripId, RouteId = tripByRouteId.RouteId, AgencyId = route.AgencyId, BusLineName = route.RouteShortName, MainRoute = expedition.MainRoute, TripHeadsign = tripByRouteId.TripHeadsign, DirectionId = tripByRouteId.DirectionId, Stops = _stopHelper.GetStopList(tripByRouteId, stopInTripData.StopsInTrip.Where(x => x.RouteId == tripByRouteId.RouteId && x.TripId == tripByRouteId.TripId).ToList(), expedition.MainRoute, busStopData.Stops) }); }); }); tripsWithBusStops.Trips = tripsWithBusStops.Trips.OrderBy(x => x.BusLineName).ToList(); return(tripsWithBusStops); }
/// <summary> /// Update the Trip data in the data store. /// NOTE: again in a real system, this need to deal with db/cache. /// </summary> /// <param name="epoch"></param> public void UpdateTrip(TripData data) { // update the trip count based on time // lock it for multithreading issues lock (this.TripCountInTime) { if (this.TripCountInTime.ContainsKey(data.epoch)) { this.TripCountInTime[data.epoch] += 1; } else { this.TripCountInTime.Add(data.epoch, 1); } } // update the trip list this.updateTripList(data); }
private void updateTripList(TripData data) { Trip trip; if (this.trips.ContainsKey(data.tripId)) { trip = this.trips[data.tripId]; } else { trip = new Trip(); this.trips.Add(data.tripId, trip); } trip.Fare = data.fare; trip.AddToLocationList(data.lat, data.lng, data.eventType); this.treeRoot.Insert(data, trip); }
internal void AddTourData(ITashaMode dat, ITripChain chain, int replication, IZone accessStationZone, INetworkData autoNetwork, ITripComponentData transitNetwork, SparseArray <IZone> _zones) { bool first = true; var stnZoneNumber = accessStationZone.ZoneNumber; var stnIndex = _zones.GetFlatIndex(accessStationZone.ZoneNumber); foreach (var trip in chain.Trips) { if (trip.Mode == dat) { if (!_tripData.TryGetValue(trip, out TripData data)) { data = new TripData(); } data.Add(first, stnZoneNumber, CalculateDATTime(_zones, autoNetwork, transitNetwork, (trip.Purpose == Activity.Home ? trip.TripStartTime : trip.ActivityStartTime) , trip.OriginalZone, stnIndex, trip.DestinationZone, first)); _tripData[trip] = data; first = false; } } }
public ScheduleTime(Schedule departure_schedule, TripData arrival_schedule) { this.DepartingTime = departure_schedule.attributes.departure_time.ToString("hh:mm"); this.ArriveTime = arrival_schedule.attributes.arrival_time.ToString("hh:mm"); }
public void addSchedule(Schedule depature_schedule, TripData arrival_schedule) { this.DisplayScheduleTimes.Add(new ScheduleTime(depature_schedule, arrival_schedule)); }
public async void getTripData(View view) { //TODO use global preference instead var numTripsToDisplay = 20; var prefs = Application.Context.GetSharedPreferences("settings", FileCreationMode.Private); var prefEditor = prefs.Edit(); if (!MojioConnectionHelper.isClientLoggedIn()) { await MojioConnectionHelper.setupMojioConnection(prefs); } if (firstStart) { firstStart = false; Globals.client.PageSize = 500; //Gets 15 results MojioResponse <Results <Trip> > response = await Globals.client.GetAsync <Trip> (); Results <Trip> result = response.Data; //var results = view.FindViewById<TextView> (Resource.Id.tripResults); tripIndex = 0; fuelEcon = 0.0; tripIndex--; list = new List <TripData> (); //iterate over each trip to create TripData for each existing trip. foreach (Trip trip in result.Data) { try { fuelEcon += (double)trip.FuelEfficiency; tripIndex++; TripData td = new TripData(trip.StartTime, trip.EndTime, trip.MaxSpeed.Value.ToString(), trip.EndLocation.Lat.ToString(), trip.EndLocation.Lng.ToString(), trip.FuelEfficiency.ToString(), trip.FuelLevel.ToString(), trip.StartLocation.Lat.ToString(), trip.StartLocation.Lng.ToString()); //add new trip to beginning of list, so they are in most recent first order list.Insert(0, td); } catch (Exception e) { Console.WriteLine("Exception:" + e); } } } prefEditor.PutString("speed", "disabled"); int i = 1; var firstTrip = true; var tripsDisplayed = 0; // programmatically create a view widget for each trip LinearLayout linlay = view.FindViewById <LinearLayout> (Resource.Id.linearLayout28); // remove all old children Console.Write("NUMCHILDREN: " + linlay.ChildCount); for (int j = linlay.ChildCount - 1; j >= 0; j--) { linlay.RemoveViewAt(j); } //places all the UI elements foreach (TripData td in list) { if (tripsDisplayed > numTripsToDisplay) { break; } else { tripsDisplayed++; } // get most recent time if (firstTrip) { lastTime = td.startDate + " @ " + td.startTime; firstTrip = false; } else { // drive divider first for every one except for first card var space = new Space(Application.Context) { LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, 10) }; var divider = new LinearLayout(Application.Context) { LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, 1) }; divider.SetBackgroundColor(Resources.GetColor(17170432)); //darker grey //add divider then space for padding linlay.AddView(divider); linlay.AddView(space); } ImageView mapButton = new ImageView(Application.Context); mapButton.SetImageResource(Resource.Drawable.mapButton); mapButton.SetAdjustViewBounds(true); mapButton.Click += delegate { var tripviewActivity = new Intent(Activity, typeof(tripviewActivity)); // Create bundle to send to tripViewActivity Bundle extras = new Bundle(); extras.PutString("endlat", (td.endlocationlat)); extras.PutString("endlng", (td.endlocationlng)); extras.PutString("startlat", (td.startlocationlat)); extras.PutString("startlng", (td.startlocationlng)); extras.PutString("fuelEfficiency", (td.fuelEfficiency)); extras.PutString("fuelLevel", (td.fuelLevel)); extras.PutString("startTime", (td.startTime)); extras.PutString("startDate", (td.startDate)); extras.PutString("maxSpeed", (td.maxSpeed)); extras.PutString("endTime", (td.endDateTime)); tripviewActivity.PutExtra("extras", extras); StartActivity(tripviewActivity); }; linlay.AddView(mapButton); TextView tv = new TextView(Application.Context); tv.Text = td.startDate + " @ " + td.startTime; tv.TextSize = 30; //tv.Elevation = 4; tv.SetPadding(5, 5, 5, 5); //tv.SetBackgroundColor (Android.Graphics.Color.ParseColor("#BBDEFB")); tv.SetTextColor(Resources.GetColor(Resource.Color.black_text)); linlay.AddView(tv); i++; LinearLayout innerll1 = new LinearLayout(Application.Context); innerll1.Orientation = Android.Widget.Orientation.Horizontal; innerll1.Id = i + 5000; //innerll1.Elevation = 4; innerll1.SetPadding(5, 5, 5, 5); //innerll1.SetBackgroundColor (Android.Graphics.Color.ParseColor("#BBDEFB")); ImageView iv1 = new ImageView(Application.Context); iv1.SetImageResource(Resource.Drawable.stopwatch); iv1.SetMaxHeight(50); iv1.SetColorFilter(Resources.GetColor(Resource.Color.accent)); iv1.SetAdjustViewBounds(true); innerll1.AddView(iv1); TextView tv1 = new TextView(Application.Context); tv1.Text = " " + td.tripLength; tv1.TextSize = 20; tv1.SetTextColor(Resources.GetColor(Resource.Color.secondary_text)); innerll1.AddView(tv1); linlay.AddView(innerll1); LinearLayout innerll2 = new LinearLayout(Application.Context); innerll2.Orientation = Android.Widget.Orientation.Horizontal; //innerll2.Elevation = 4; innerll2.SetPadding(5, 5, 5, 5); //innerll2.SetBackgroundColor (Android.Graphics.Color.ParseColor("#BBDEFB")); ImageView iv2 = new ImageView(Application.Context); iv2.SetImageResource(Resource.Drawable.speedometer); iv2.SetMaxHeight(50); iv2.SetColorFilter(Resources.GetColor(Resource.Color.accent)); iv2.SetAdjustViewBounds(true); innerll2.AddView(iv2); TextView tv2 = new TextView(Application.Context); tv2.Text = " " + td.maxSpeed; tv2.TextSize = 20; //tv2.Elevation = 4; tv2.SetTextColor(Resources.GetColor(Resource.Color.secondary_text)); innerll2.AddView(tv2); linlay.AddView(innerll2); Space spc = new Space(Application.Context); spc.SetMinimumHeight(14); linlay.AddView(spc); } var fuelEfficiecny = view.FindViewById <TextView> (Resource.Id.fuelUsage); var lastTripTime = view.FindViewById <TextView> (Resource.Id.lastTripTime); var fe = Math.Round((fuelEcon / tripIndex), 1); fuelEfficiecny.Text = " " + fe + " L/100km"; lastTripTime.Text = " " + lastTime; }
private void updateSchedules() { viewModel.DisplayScheduleTimes.Clear(); int arrival_index = ScheduleArrivalPicker.SelectedIndex; int departure_index = ScheduleDeparturePicker.SelectedIndex; if (departure_index >= 0) { string selectedDepatureStationName = viewModel.StationList[departure_index]; string routeID = viewModel.SelectedRoute; if (arrival_index < 0) { foreach (Schedule schedule in Database.RouteSchedules[routeID]) { if (schedule.attributes.departure_time > DateTime.Now && schedule.relationships.stop.id.Equals(selectedDepatureStationName)) { viewModel.addSchedule(schedule); } } } else { string selectedArrivalStationName = viewModel.StationList[arrival_index]; Schedule departureSchedule; string tripID; int cnt = 0; int maxcount = 10; viewModel.IsBusy = true; foreach (Schedule schedule in Database.RouteSchedules[routeID]) { if (schedule.attributes.departure_time > DateTime.Now && schedule.relationships.stop.id.Equals(selectedDepatureStationName)) { departureSchedule = schedule; tripID = schedule.relationships.trip.id; Task.Run(async() => { TripData trip_data = null; List <TripData> tripInfo = await DataQuery.getScheduleOfTrip(routeID, viewModel.RouteDirection.direction_id, tripID, selectedArrivalStationName); foreach (TripData temp_trip in tripInfo) { if (temp_trip.relationships.trip.data.id.Equals(tripID)) { trip_data = temp_trip; break; } } viewModel.addSchedule(departureSchedule, trip_data); cnt++; }).Wait(); if (cnt > maxcount) { break; } } } viewModel.IsBusy = false; } } }
// Pre load some fake trip data for testing purpose. private void PreLoadTrips() { // trip id: 1 var tripData = new TripData() { eventType = "begin", tripId = 1, lat = 10.0, lng = 11.0, epoch = 10000 }; this.UpdateTrip(tripData); tripData = new TripData() { eventType = "update", tripId = 1, lat = 400.0, lng = 100.0, epoch = 10001 }; this.UpdateTrip(tripData); tripData = new TripData() { eventType = "end", tripId = 1, lat = 550.0, lng = 80.0, fare = 9, epoch = 10002 }; this.UpdateTrip(tripData); // trip id: 2 tripData = new TripData() { eventType = "begin", tripId = 2, lat = 10.0, lng = 300.0, epoch = 10000 }; this.UpdateTrip(tripData); tripData = new TripData() { eventType = "update", tripId = 2, lat = 350.0, lng = 320.0, epoch = 10001 }; this.UpdateTrip(tripData); tripData = new TripData() { eventType = "end", tripId = 2, lat = 200.0, lng = 600.0, fare = 10, epoch = 10002 }; this.UpdateTrip(tripData); // trip id: 3 tripData = new TripData() { eventType = "begin", tripId = 3, lat = 650.0, lng = 100.0, epoch = 10000 }; this.UpdateTrip(tripData); tripData = new TripData() { eventType = "update", tripId = 3, lat = 670.0, lng = 330.0, epoch = 10001 }; this.UpdateTrip(tripData); tripData = new TripData() { eventType = "end", tripId = 3, lat = 680.0, lng = 550.0, fare = 11, epoch = 10002 }; this.UpdateTrip(tripData); // trip id: 4 tripData = new TripData() { eventType = "begin", tripId = 4, lat = 400.0, lng = 800.0, epoch = 10004 }; this.UpdateTrip(tripData); tripData = new TripData() { eventType = "update", tripId = 4, lat = 490.0, lng = 690.0, epoch = 10005 }; this.UpdateTrip(tripData); tripData = new TripData() { eventType = "end", tripId = 4, lat = 560.0, lng = 820.0, fare = 12, epoch = 10006 }; this.UpdateTrip(tripData); // trip id: 5 tripData = new TripData() { eventType = "begin", tripId = 5, lat = 450.0, lng = 300.0, epoch = 10004 }; this.UpdateTrip(tripData); tripData = new TripData() { eventType = "update", tripId = 5, lat = 560.0, lng = 560.0, epoch = 10005 }; this.UpdateTrip(tripData); tripData = new TripData() { eventType = "end", tripId = 5, lat = 650.0, lng = 650.0, fare = 13, epoch = 10006 }; this.UpdateTrip(tripData); // trip id: 6 tripData = new TripData() { eventType = "begin", tripId = 6, lat = 450.0, lng = 900.0, epoch = 10008 }; this.UpdateTrip(tripData); tripData = new TripData() { eventType = "update", tripId = 6, lat = 600.0, lng = 720.0, epoch = 10009 }; this.UpdateTrip(tripData); tripData = new TripData() { eventType = "end", tripId = 6, lat = 900.0, lng = 400.0, fare = 14, epoch = 10010 }; this.UpdateTrip(tripData); }
public HomeController(ILoggerFactory factory) { tripData = new TripData(factory); }
// Called by the established pub/sub channel public void UpdateTripData(TripData data) { // add to the trips indexed by time. this.trips.UpdateTrip(data); }