public void SetUp() { // // CREATE THE STACK. // List <ActivityPoint> ActivityPointList = new List <ActivityPoint>(); // // CREATE THE MARKER START POINT. // ActivityPoint CreatedPoint = new ActivityPoint(); CreatedPoint.ActivityName = "Marker"; CreatedPoint.PointDateTime = DateTime.UtcNow; CreatedPoint.PointType = ActivityPointType.Start; ActivityPointList.Add(CreatedPoint); // // NORMALIZE. // ActivityPointStack CreatedStack = ActivityPointListNormalizer.Normalize(ActivityPointList.ToArray()); // // GET THE START AND END POINTS. // _StartPoint = CreatedStack.Pop(); _EndPoint = CreatedStack.Pop(); }
public static string CreateLines(ActivityPointStack StackParam) { ActivityPointStack TempStack = new ActivityPointStack(); try { StringBuilder PrintStringBuilder = new StringBuilder(); PrintStringBuilder.AppendLine("ActivityName,PointDateTime,PointType,SequenceNumber"); while (StackParam.IsNotEmpty) { ActivityPoint CurrentPoint = StackParam.Pop(); PrintStringBuilder.AppendLine(CreateLine(CurrentPoint)); TempStack.Push(CurrentPoint); } return(PrintStringBuilder.ToString()); } finally { while (TempStack.IsNotEmpty) { StackParam.Push(TempStack.Pop()); } } }
public void SetUp() { // // CREATE THE STACK. // ActivityPointStack CreatedStack = new ActivityPointStack(); // // CREATE THE END POINT. // _EndPoint = new ActivityPoint(); _EndPoint.ActivityName = "Marker"; _EndPoint.PointDateTime = DateTime.UtcNow; _EndPoint.PointType = ActivityPointType.End; CreatedStack.Push(_EndPoint); // // CREATE THE START POINT. // ActivityPoint StartPoint = new ActivityPoint(); StartPoint.ActivityName = "Marker"; StartPoint.PointDateTime = DateTime.UtcNow; StartPoint.PointType = ActivityPointType.Start; CreatedStack.Push(StartPoint); // // GET THE END POINT. // _EndPoint = ActivityPointListNormalizer.GetEndPoint(StartPoint, CreatedStack); }
public static int GetMatchGrade(ActivityPoint activityPoint, Dictionary <eActivityType, int> preferences) { if (!activityPoint.Accessibility && preferences[eActivityType.Walking] == 1) { return(0); } return(preferences[(eActivityType)Enum.Parse(typeof(eActivityType), activityPoint.Type)]); }
/// <summary> /// Ends the timing for the activity with the specified name. /// </summary> public override void End(string ActivityNameParam) { ActivityPoint CreatedPoint = new ActivityPoint(); CreatedPoint.ActivityName = ActivityNameParam; CreatedPoint.PointDateTime = DateTime.UtcNow; CreatedPoint.PointType = ActivityPointType.End; _ActivityPointList.Add(CreatedPoint); }
public static string CreateLine(ActivityPoint CurrentPoint) { StringBuilder LineBuilder = new StringBuilder(); LineBuilder.Append(CurrentPoint.ActivityName); LineBuilder.Append(","); LineBuilder.Append(CurrentPoint.PointDateTime == null ? "" : CurrentPoint.PointDateTime.Value.ToString("s")); LineBuilder.Append(","); LineBuilder.Append(CurrentPoint.PointType.ToString()); LineBuilder.Append(","); LineBuilder.Append(CurrentPoint.SequenceNumber.ToString()); return(LineBuilder.ToString()); }
public static List <ActivityTimeSlot> TryFindTimeForActivityAndTravel(ActivityPoint activityPoint, TimeWindow freeTimeWindow) { var activityPointAndTravel = new List <ActivityTimeSlot>(); var drivingTimeToActivity = CalcDrivingTime(freeTimeWindow.ActivityBefore?.Activity?.Location, activityPoint.Location); var drivingTimeFromActivity = CalcDrivingTime(activityPoint.Location, freeTimeWindow.ActivityAfter?.Activity?.Location); var duration = (int)activityPoint.AvgSpendingTimeInHours + drivingTimeToActivity + drivingTimeFromActivity; ActivityTimeSlot activityTimeSlot = null; if (duration > freeTimeWindow.TimeSlot.EndTime - freeTimeWindow.TimeSlot.StartTime) { return(null); } if (activityPoint.OpeningTime < freeTimeWindow.TimeSlot.StartTime && freeTimeWindow.TimeSlot.StartTime + duration <= activityPoint.ClosingTime) { activityTimeSlot = new ActivityTimeSlot(new TimeSlot(freeTimeWindow.TimeSlot.StartTime + drivingTimeToActivity, freeTimeWindow.TimeSlot.StartTime + activityPoint.AvgSpendingTimeInHours + drivingTimeToActivity), activityPoint); } if (activityPoint.ClosingTime > freeTimeWindow.TimeSlot.EndTime && freeTimeWindow.TimeSlot.EndTime - duration >= activityPoint.OpeningTime) { activityTimeSlot = new ActivityTimeSlot(new TimeSlot(freeTimeWindow.TimeSlot.EndTime - activityPoint.AvgSpendingTimeInHours - drivingTimeFromActivity, freeTimeWindow.TimeSlot.EndTime - drivingTimeFromActivity), activityPoint); } if (activityPoint.OpeningTime >= freeTimeWindow.TimeSlot.StartTime && activityPoint.OpeningTime + duration <= freeTimeWindow.TimeSlot.EndTime) { activityTimeSlot = new ActivityTimeSlot(new TimeSlot(activityPoint.OpeningTime + drivingTimeToActivity, activityPoint.OpeningTime + activityPoint.AvgSpendingTimeInHours + drivingTimeToActivity), activityPoint); } if (activityTimeSlot == null) { return(null); } var startTime = activityTimeSlot.TimeSlot.StartTime; var endTime = activityTimeSlot.TimeSlot.EndTime; if (drivingTimeToActivity > 0) { activityPointAndTravel.Add(new ActivityTimeSlot(new TimeSlot(startTime - drivingTimeToActivity, startTime), null, true)); } activityPointAndTravel.Add(activityTimeSlot); if (drivingTimeFromActivity > 0) { activityPointAndTravel.Add(new ActivityTimeSlot(new TimeSlot(endTime, endTime + drivingTimeFromActivity), null, true)); } return(activityPointAndTravel); }
public DayOfTrip(int intenseLevel, ActivityPoint mainActivity) { SortedActivities = new List <ActivityTimeSlot>(); LunchHour = 12; DinnerHour = 18; switch (intenseLevel) { case 1: StartHour = 10; EndHour = 19; break; case 2: StartHour = 09; EndHour = 19; break; case 3: StartHour = 09; EndHour = 20; break; case 4: StartHour = 09; EndHour = 21; break; default: StartHour = 08; EndHour = 22; break; } MainActivity = new ActivityTimeSlot(new TimeSlot((int)mainActivity.OpeningTime + 1, (int)mainActivity.OpeningTime + 1 + (int)mainActivity.AvgSpendingTimeInHours), mainActivity); //avoiding collisions if (MainActivity.TimeSlot.IsInTimeSlot(StartHour, StartHour + 1)) //breakfest { StartHour = MainActivity.TimeSlot.StartTime - 1; } if (MainActivity.TimeSlot.IsInTimeSlot(LunchHour, LunchHour + 1)) //lunch { LunchHour = MainActivity.TimeSlot.EndTime; } if (MainActivity.TimeSlot.IsInTimeSlot(DinnerHour, DinnerHour + 1)) //dinner { DinnerHour = MainActivity.TimeSlot.EndTime; } SortedActivities.Add(MainActivity); }
public void SetUp() { // // CREATE THE START POINT. // _StartPoint = new ActivityPoint(); _StartPoint.ActivityName = "DoesNotExist"; _StartPoint.PointDateTime = DateTime.UtcNow; _StartPoint.PointType = ActivityPointType.Start; // // CREATE THE STACK. // _Stack = new ActivityPointStack(); }
public IEnumerable <ActivityPoint> Get() { List <ActivityPoint> dayOfTrip = new List <ActivityPoint>(); ActivityPoint activity1 = new ActivityPoint() { Id = 1, Name = "act1", Accessibility = true, AvgSpendingTimeInHours = 1.5, ClosingTime = 434, Cost = 3.3, Description = "desc1", FromAge = 0, ToAge = 3, GEPSLatitude = 232, GEPSLongtitude = 323, OpeningTime = 31, Opinions = "asds", Rank = 3, Type = "resturant", WebsiteLink = "www.google.com" }; ActivityPoint activity2 = new ActivityPoint() { Id = 2, Name = "act2", Accessibility = true, AvgSpendingTimeInHours = 1.5, ClosingTime = 434, Cost = 3.3, Description = "desc1", FromAge = 0, ToAge = 3, GEPSLatitude = 232, GEPSLongtitude = 323, OpeningTime = 31, Opinions = "asds", Rank = 3, Type = "resturant", WebsiteLink = "www.google.com" }; dayOfTrip.Add(activity1); dayOfTrip.Add(activity2); return(dayOfTrip); }
/// <summary> /// Adds the specified session displayable point. /// </summary> /// <param name="sessionDisplayablePoint">The session displayable point.</param> public void Add(ActivityPoint point) { SessionDisplayablePoint previousPoint = SessionPoints.Count > 0 ? SessionPoints.Last() : null; DateTime startTime = point.TimeStamp; SessionDisplayablePoint sessionDisplayablePoint; TimeSpan elapsedTime = point.TimeStamp - startTime; double?speed = point.Speed; if (speed == null && previousPoint != null && previousPoint.HasPosition && previousPoint.Distance.HasValue && point.Position != LatLong.Empty && point.DistanceInMeters > 0 && elapsedTime.TotalSeconds > 0) { double kilometersTraveled = GeoCalculation.HaversineDistance(previousPoint.Position, point.Position); double hoursElapsed = (elapsedTime - previousPoint.Time).TotalHours; speed = kilometersTraveled / hoursElapsed; } sessionDisplayablePoint = new SessionDisplayablePoint( elapsedTime, point.DistanceInMeters, point.AltitudeInMeters, speed, point.Position); if (GeoCalculation.IsPointNewLeftBottom(BottomLeft, sessionDisplayablePoint.Position.ToPosition()) || GeoCalculation.IsPointNewTopRight(TopRight, sessionDisplayablePoint.Position.ToPosition())) { BottomLeft = sessionDisplayablePoint.Position.ToPosition(); TopRight = sessionDisplayablePoint.Position.ToPosition(); Region = GeoCalculation.BoundsToMapSpan(BottomLeft, TopRight); } SessionPoints.Add(sessionDisplayablePoint); RefreshColors(); }
private XmlElement CreateActivityPointElementWithName(ActivityPoint ActivityPointParam, string ElementNameParam) { XmlElement ActivityPointElement = _MarkerReportDocument.CreateElement(ElementNameParam); // // ACTIVITY NAME. // if (ActivityPointParam.ActivityName != null) { ActivityPointElement.SetAttribute("ActivityName", ActivityPointParam.ActivityName); } // // POINT DATE/TIME. // if (ActivityPointParam.PointDateTime != null) { XmlElement CreatedElement = _MarkerReportDocument.CreateElement("PointDateTime"); CreatedElement.InnerText = ActivityPointParam.PointDateTime.Value.ToString("s"); ActivityPointElement.AppendChild(CreatedElement); } // // POINT TYPE. // { XmlElement CreatedElement = _MarkerReportDocument.CreateElement("PointType"); CreatedElement.InnerText = ActivityPointParam.PointType.ToString(); ActivityPointElement.AppendChild(CreatedElement); } // // SEQUENCE NUMBER. // { XmlElement CreatedElement = _MarkerReportDocument.CreateElement("SequenceNumber"); CreatedElement.InnerText = ActivityPointParam.SequenceNumber.ToString(); ActivityPointElement.AppendChild(CreatedElement); } return(ActivityPointElement); }
public void SetUp() { // // FAKE THE TIMES. // DateTime StartPointDateTime = DateTime.UtcNow; // // CREATE THE STACK. // ActivityPointStack CreatedStack = new ActivityPointStack(); // // CREATE THE MARKER END POINT. // { ActivityPoint CreatedPoint = new ActivityPoint(); CreatedPoint.ActivityName = "Marker"; CreatedPoint.PointDateTime = StartPointDateTime.AddSeconds(1); CreatedPoint.PointType = ActivityPointType.End; CreatedStack.Push(CreatedPoint); } // // CREATE THE MARKER START POINT. // { ActivityPoint CreatedPoint = new ActivityPoint(); CreatedPoint.ActivityName = "Marker"; CreatedPoint.PointDateTime = StartPointDateTime; CreatedPoint.PointType = ActivityPointType.Start; CreatedStack.Push(CreatedPoint); } // // BUILD THE TREE. // _ReportItem = ActivityReportItemTreeFactory.CreateReportItemTree(CreatedStack); }
public static SessionMapInfo Create( IReadOnlyList <ActivityPoint> points, Func <ISessionDisplayablePoint, Color?> colorBaseValueSelector, int markerInterval = int.MaxValue, int displayDistanceInterval = int.MaxValue) { if (points == null || points.Count < 2) { throw new ArgumentException(); } var sessionPoints = new SessionDisplayablePoint[points.Count]; double topLatitude = LatLong.Min.Latitude; double bottomLatitude = LatLong.Max.Latitude; double leftLongitude = LatLong.Max.Longitude; double rightLongitude = LatLong.Min.Longitude; int nextMarkerDistance = markerInterval; int nextDisplayDistance = displayDistanceInterval; SessionDisplayablePoint previousPoint = null; DateTime startTime = points[0].TimeStamp; for (int index = 0; index < points.Count; index++) { ActivityPoint point = points[index]; if (point.Position != LatLong.Empty) { topLatitude = Math.Max(point.Position.Latitude, topLatitude); bottomLatitude = Math.Min(point.Position.Latitude, bottomLatitude); leftLongitude = Math.Min(point.Position.Longitude, leftLongitude); rightLongitude = Math.Max(point.Position.Longitude, rightLongitude); } bool hasMarker = false; if (point.DistanceInMeters > nextMarkerDistance) { hasMarker = true; nextMarkerDistance += markerInterval; } string displayDistance = null; if (point.DistanceInMeters > nextDisplayDistance) { displayDistance = nextDisplayDistance.ToString(); nextDisplayDistance += displayDistanceInterval; } TimeSpan elapsedTime = point.TimeStamp - startTime; double speed = 0; if (previousPoint != null && previousPoint.HasPosition && previousPoint.Distance.HasValue && point.Position != LatLong.Empty && point.DistanceInMeters > 0 && elapsedTime.TotalSeconds > 0) { double kilometersTraveled = GeoCalculation.HaversineDistance(previousPoint.Position, point.Position); double hoursElapsed = (elapsedTime - previousPoint.Time).TotalHours; speed = kilometersTraveled / hoursElapsed; } var currentPoint = sessionPoints[index] = new SessionDisplayablePoint( elapsedTime, point.HeartRate, point.DistanceInMeters, point.AltitudeInMeters, speed, point.Position, hasMarker, displayDistance); Color mapPointColor = colorBaseValueSelector(currentPoint) ?? previousPoint?.MapPointColor ?? Color.Gray; currentPoint.SetPointColor(mapPointColor); previousPoint = currentPoint; } return(new SessionMapInfo( sessionPoints, new Bounds( new Position(bottomLatitude, leftLongitude), new Position(topLatitude, rightLongitude)), previousPoint != null ? (int)previousPoint.Time.TotalSeconds : 0)); }
public ActivityTimeSlot(TimeSlot timeSlot, ActivityPoint activityPoint, bool isTraveling = false) { TimeSlot = timeSlot; Activity = activityPoint; IsTraveling = isTraveling; }
public ActivityPoint[] GetPointsForActivity(int IUID) { var preResult = new SortedDictionary<string, DayPoint>(); var command = connection.CreateCommand(); command.CommandText = "Select Delta, Time from Activity WHERE IUID = $IUID AND time >= datetime('now','-30 days','localtime')"; command.Parameters.AddWithValue("$IUID", IUID); using (var reader = command.ExecuteReader()) { while (reader.Read()) { var delta = reader.GetInt32(0); var day = reader.GetDateTime(1).ToString("yyyy-MM-dd"); if (preResult.ContainsKey(day)) { if (delta > 0) preResult[day].Added += delta; else preResult[day].Removed -= delta; } else { if (delta > 0) preResult.Add(day, new DayPoint { Added = delta, Removed = 0 }); else preResult.Add(day, new DayPoint { Added = 0, Removed = -delta }); } } } command.CommandText = "Select Count from Items WHERE UID = $IUID"; int itemCount; using (var reader = command.ExecuteReader()) { reader.Read(); itemCount = reader.GetInt32(0); } bool isFirstElement = true; DayPoint prevValue = new DayPoint(); foreach (var x in preResult.Reverse()) { var val = x.Value; if (isFirstElement) { val.Count = itemCount; isFirstElement = false; } else { val.Count = prevValue.Count - prevValue.Added + prevValue.Removed; } prevValue = val; } var result = new ActivityPoint[30]; var localDate = DateTime.Now; for (var day = 0; day < 30; day++) { var dayKey = localDate.AddDays(-day).ToString("yyyy-MM-dd"); if (preResult.ContainsKey(dayKey)) { var dayData = preResult[dayKey]; result[day] = new ActivityPoint { Count = dayData.Count, In = dayData.Added, Out = dayData.Removed }; } else { result[day] = new ActivityPoint { Count = -1, In = 0, Out = 0 }; } } result = result.Reverse().ToArray(); if (result[0].Count == -1) result[0].Count = 0; var lastCount = result[0].Count; for (var day = 1; day < 30; day++) { var val = result[day]; if (val.Count == -1) val.Count = lastCount; lastCount = val.Count; } return result; }
/// <summary> /// Creation with ActivityPoints and custom ColorSelector. /// </summary> /// <param name="points">The points.</param> /// <param name="colorBaseValueSelector">The color base value selector.</param> /// <returns></returns> public static SessionMap Create( List <ActivityPoint> points, Func <ISessionDisplayablePoint, Color?> colorBaseValueSelector) { if (points == null) { Debug.WriteLine("SessionMap points is null"); //throw new ArgumentException(); return(null); } // mindestens zwei punkte für Geschwindigkeitsberechnung if (points.Count < 2) { Debug.WriteLine("SessionMap points not greater than 2"); //throw new ArgumentException(); return(null); } var sessionPoints = new SessionDisplayablePoint[points.Count]; double topLatitude = LatLong.Min.Latitude; double bottomLatitude = LatLong.Max.Latitude; double leftLongitude = LatLong.Max.Longitude; double rightLongitude = LatLong.Min.Longitude; SessionDisplayablePoint previousPoint = null; DateTime startTime = points[0].TimeStamp; for (int index = 0; index < points.Count; index++) { ActivityPoint point = points[index]; if (point.Position != LatLong.Empty) { topLatitude = Math.Max(point.Position.Latitude, topLatitude); bottomLatitude = Math.Min(point.Position.Latitude, bottomLatitude); leftLongitude = Math.Min(point.Position.Longitude, leftLongitude); rightLongitude = Math.Max(point.Position.Longitude, rightLongitude); } TimeSpan elapsedTime = point.TimeStamp - startTime; double?speed = point.Speed; if (speed == null && previousPoint != null && previousPoint.HasPosition && previousPoint.Distance.HasValue && point.Position != LatLong.Empty && point.DistanceInMeters > 0 && elapsedTime.TotalSeconds > 0) { double kilometersTraveled = GeoCalculation.HaversineDistance(previousPoint.Position, point.Position); double hoursElapsed = (elapsedTime - previousPoint.Time).TotalHours; speed = kilometersTraveled / hoursElapsed; } var currentPoint = sessionPoints[index] = new SessionDisplayablePoint( elapsedTime, point.DistanceInMeters, point.AltitudeInMeters, speed, point.Position); Color mapPointColor = colorBaseValueSelector(currentPoint) ?? previousPoint?.MapPointColor ?? Color.Gray; currentPoint.SetPointColor(mapPointColor); previousPoint = currentPoint; } return(new SessionMap( sessionPoints.ToList(), new Position(bottomLatitude, leftLongitude), new Position(topLatitude, rightLongitude))); }
public void GetMaxRevoveryTimeTest(ActivityPoint pt, DateTimeOffset now, DateTimeOffset expected) { var actual = pt.GetMaxRevoveryTime(now); Assert.Equal(expected, actual); }
public void GetTotalRecoveryIntervalTest(ActivityPoint pt, TimeSpan expected) { var actual = pt.GetTotalRecoveryInterval(); Assert.Equal(expected, actual); }
public static bool IsNearBy(ActivityPoint activityPoint, Location startPoint, int nearByDistanceKm) { return(LocationUtils.HaversineDistance(new Location(activityPoint.GEPSLatitude, activityPoint.GEPSLongtitude), startPoint) <= nearByDistanceKm); }
public void SetUp() { // // CREATE THE STARTING POINT TIME. // DateTime StartPointDateTime = DateTime.Parse("2018-01-01T00:00:00"); double TimeIncrement = 1d; int SequenceNumber = 0; // // CREATE THE STACK. // ActivityPointStack CreatedStack = new ActivityPointStack(); // // CREATE THE MARKER START POINT. // { ActivityPoint CreatedPoint = new ActivityPoint(); CreatedPoint.ActivityName = "CreatedMarker"; CreatedPoint.PointDateTime = StartPointDateTime.AddSeconds(SequenceNumber * TimeIncrement); CreatedPoint.PointType = ActivityPointType.Start; CreatedPoint.SequenceNumber = SequenceNumber++; CreatedStack.Push(CreatedPoint); } { ActivityPoint CreatedPoint = new ActivityPoint(); CreatedPoint.ActivityName = "P"; CreatedPoint.PointDateTime = StartPointDateTime.AddSeconds(SequenceNumber * TimeIncrement); CreatedPoint.PointType = ActivityPointType.Start; CreatedPoint.SequenceNumber = SequenceNumber++; CreatedStack.Push(CreatedPoint); } { ActivityPoint CreatedPoint = new ActivityPoint(); CreatedPoint.ActivityName = "P"; CreatedPoint.PointDateTime = StartPointDateTime.AddSeconds(SequenceNumber * TimeIncrement); CreatedPoint.PointType = ActivityPointType.End; CreatedPoint.SequenceNumber = SequenceNumber++; CreatedStack.Push(CreatedPoint); } { ActivityPoint CreatedPoint = new ActivityPoint(); CreatedPoint.ActivityName = "Q"; CreatedPoint.PointDateTime = StartPointDateTime.AddSeconds(SequenceNumber * TimeIncrement); CreatedPoint.PointType = ActivityPointType.Start; CreatedPoint.SequenceNumber = SequenceNumber++; CreatedStack.Push(CreatedPoint); } { ActivityPoint CreatedPoint = new ActivityPoint(); CreatedPoint.ActivityName = "Q"; CreatedPoint.PointDateTime = StartPointDateTime.AddSeconds(SequenceNumber * TimeIncrement); CreatedPoint.PointType = ActivityPointType.End; CreatedPoint.SequenceNumber = SequenceNumber++; CreatedStack.Push(CreatedPoint); } { ActivityPoint CreatedPoint = new ActivityPoint(); CreatedPoint.ActivityName = "R"; CreatedPoint.PointDateTime = StartPointDateTime.AddSeconds(SequenceNumber * TimeIncrement); CreatedPoint.PointType = ActivityPointType.Start; CreatedPoint.SequenceNumber = SequenceNumber++; CreatedStack.Push(CreatedPoint); } { ActivityPoint CreatedPoint = new ActivityPoint(); CreatedPoint.ActivityName = "R"; CreatedPoint.PointDateTime = StartPointDateTime.AddSeconds(SequenceNumber * TimeIncrement); CreatedPoint.PointType = ActivityPointType.End; CreatedPoint.SequenceNumber = SequenceNumber++; CreatedStack.Push(CreatedPoint); } // // CREATE THE MARKER END POINT. // { ActivityPoint CreatedPoint = new ActivityPoint(); CreatedPoint.ActivityName = "CreatedMarker"; CreatedPoint.PointDateTime = StartPointDateTime.AddSeconds(SequenceNumber * TimeIncrement); CreatedPoint.PointType = ActivityPointType.End; CreatedPoint.SequenceNumber = SequenceNumber++; CreatedStack.Push(CreatedPoint); } // // BUILD THE TREE. // _ReportItem = ActivityReportItemTreeFactory.CreateReportItemTree(CreatedStack.Flip()); }