protected override void Calculate() { var cachedProperty = GetFromCache(); if (cachedProperty != null) { value = cachedProperty.Value; return; } double?sum = 0; for (var i = Start.SegmentIndex; i <= End.SegmentIndex; i++) { var startPL = new ParameterizedLocation(i, 0); var endPL = new ParameterizedLocation(i, Session.Route.Segments[i].Waypoints.Count - 1); if (startPL < Start) { startPL = Start; } if (endPL > End) { endPL = End; } var startAltitude = Session.Route.GetAttributeFromParameterizedLocation(WaypointAttribute.Altitude, startPL); var endAltitude = Session.Route.GetAttributeFromParameterizedLocation(WaypointAttribute.Altitude, endPL); if (startAltitude == null || endAltitude == null) { sum = null; break; } sum += endAltitude.Value - startAltitude.Value; } value = sum; AddToCache(); }
protected override void Calculate() { var cachedProperty = GetFromCache(); if (cachedProperty != null) { value = cachedProperty.Value; return; } double? sum = 0; for (var i = Start.SegmentIndex; i <= End.SegmentIndex; i++) { var startPL = new ParameterizedLocation(i, 0); var endPL = new ParameterizedLocation(i, Session.Route.Segments[i].Waypoints.Count - 1); if (startPL < Start) startPL = Start; if (endPL > End) endPL = End; var startAltitude = Session.Route.GetAttributeFromParameterizedLocation(WaypointAttribute.Altitude, startPL); var endAltitude = Session.Route.GetAttributeFromParameterizedLocation(WaypointAttribute.Altitude, endPL); if (startAltitude == null || endAltitude == null) { sum = null; break; } sum += endAltitude.Value - startAltitude.Value; } value = sum; AddToCache(); }
private CutRouteAction(Session session, ParameterizedLocation parameterizedLocation, DateTime?time, CutType cutType) { this.session = session; this.parameterizedLocation = parameterizedLocation; this.cutType = cutType; this.time = time; }
private ParameterizedLocation GetParameterizedLocationFromMouseLocation(int x) { double?xValue = graph.XToValue(x); if (xValue < graph.XAxisMinValue || xValue > graph.XAxisMaxValue) { xValue = null; } ParameterizedLocation pl = null; if (xValue != null) { DateTime time; switch (graph.XAxisAttribute) { case DomainAttribute.TimeOfDay: time = new DateTime((long)(xValue.Value * TimeSpan.TicksPerSecond)).ToUniversalTime(); pl = graph.Session.Route.GetParameterizedLocationFromTime(time, true); break; case DomainAttribute.ElapsedTime: time = graph.Session.Route.FirstWaypoint.Time.AddTicks((long)xValue.Value * TimeSpan.TicksPerSecond); pl = graph.Session.Route.GetParameterizedLocationFromTime(time); break; case DomainAttribute.Distance: pl = graph.Session.Route.GetParameterizedLocationFromDistance(xValue.Value); break; } } return(pl); }
protected override void Calculate() { var cachedProperty = GetFromCache(); if (cachedProperty != null) { value = cachedProperty.Value; return; } var sum = new TimeSpan(); for (var i = Start.SegmentIndex; i <= End.SegmentIndex; i++) { var startPL = new ParameterizedLocation(i, 0); var endPL = new ParameterizedLocation(i, Session.Route.Segments[i].Waypoints.Count - 1); if (startPL < Start) { startPL = Start; } if (endPL > End) { endPL = End; } sum += Session.Route.GetTimeFromParameterizedLocation(endPL) - Session.Route.GetTimeFromParameterizedLocation(startPL); } value = sum; AddToCache(); }
protected override void Calculate() { var pl = new ParameterizedLocation(Start); var nodes = new List<HRNode>(); while (pl <= End) { var hr = Session.Route.GetAttributeFromParameterizedLocation(WaypointAttribute.HeartRate, pl); if(hr.HasValue) { var nodeType = NodeType.Intermediate; if (Session.Route.IsFirstPLInSegment(pl)) nodeType = NodeType.Begin; if (Session.Route.IsLastPLInSegment(pl)) nodeType = NodeType.End; nodes.Add(new HRNode() { HR = hr.Value, Time = Session.Route.GetTimeFromParameterizedLocation(pl), NodeType = nodeType }); } else { value = null; return; } if (pl >= End) break; pl = Session.Route.GetNextPLNode(pl, ParameterizedLocation.Direction.Forward); if (pl > End) pl = new ParameterizedLocation(End); } if (nodes.Count > 0) { nodes[0].NodeType = NodeType.Begin; nodes[nodes.Count - 1].NodeType = NodeType.End; } var heartbeats = 0.0; var totalDuration = 0.0; for(var i=1; i<nodes.Count; i++) { double duration = 0; switch(nodes[i].NodeType) { case NodeType.Begin: duration = (nodes[i + 1].Time - nodes[i].Time).TotalSeconds / 2; break; case NodeType.End: duration = (nodes[i].Time - nodes[i-1].Time).TotalSeconds / 2; break; case NodeType.Intermediate: duration = (nodes[i].Time - nodes[i-1].Time).TotalSeconds / 2 + (nodes[i + 1].Time - nodes[i].Time).TotalSeconds / 2; break; } heartbeats += duration*nodes[i].HR/60; totalDuration += duration; } value = (double?)(totalDuration == 0 ? 0 : heartbeats / totalDuration * 60); AddToCache(); }
protected override void Calculate() { var cachedProperty = GetFromCache(); if (cachedProperty != null) { value = cachedProperty.Value; return; } var pl = new ParameterizedLocation(Start); var nodes = new List<Node>(); while (pl <= End) { var directionDeviationToNextLap = Session.Route.GetAttributeFromParameterizedLocation(WaypointAttribute.DirectionDeviationToNextLap, pl); var nodeType = NodeType.Intermediate; if (Session.Route.IsFirstPLInSegment(pl)) nodeType = NodeType.Begin; if (Session.Route.IsLastPLInSegment(pl)) nodeType = NodeType.End; nodes.Add(new Node() { DirectionDeviationToNextLap = directionDeviationToNextLap.Value, Time = Session.Route.GetTimeFromParameterizedLocation(pl), NodeType = nodeType }); if (pl >= End) break; pl = Session.Route.GetNextPLNode(pl, ParameterizedLocation.Direction.Forward); if (pl > End) pl = new ParameterizedLocation(End); } if (nodes.Count > 0) { nodes[0].NodeType = NodeType.Begin; nodes[nodes.Count - 1].NodeType = NodeType.End; } var sum = 0.0; var totalDuration = 0.0; for (var i = 0; i < nodes.Count; i++) { double duration = 0; switch (nodes[i].NodeType) { case NodeType.Begin: duration = (nodes[i + 1].Time - nodes[i].Time).TotalSeconds / 2; break; case NodeType.End: duration = (nodes[i].Time - nodes[i - 1].Time).TotalSeconds / 2; break; case NodeType.Intermediate: duration = (nodes[i].Time - nodes[i - 1].Time).TotalSeconds / 2 + (nodes[i + 1].Time - nodes[i].Time).TotalSeconds / 2; break; } sum += duration * nodes[i].DirectionDeviationToNextLap; totalDuration += duration; } value = (double?)(totalDuration == 0 ? 0 : sum / totalDuration); AddToCache(); }
public void Export() { var writerSettings = new XmlWriterSettings { Encoding = Encoding.UTF8, Indent = true, IndentChars = " " }; var writer = XmlWriter.Create(OutputStream, writerSettings); var formatter = new Formatter(); var cacheManager = new RoutePropertyCacheManager(); if (writer != null) { writer.WriteStartDocument(); writer.WriteStartElement("Route"); int segmentCount = 0; foreach (var segment in Session.Route.Segments) { writer.WriteStartElement("Segment"); var waypoints = Session.Route.GetEquallySpacedWaypoints(segment.FirstWaypoint.Time, segment.LastWaypoint.Time, Settings.SamplingInterval, Settings.ZeroTime); var lastPl = new ParameterizedLocation(segmentCount, 0); foreach (var waypoint in waypoints) { writer.WriteStartElement("Sample"); var pl = Session.Route.GetParameterizedLocationFromTime(waypoint.Time, lastPl, ParameterizedLocation.Direction.Forward); var locations = new RouteLocations(pl); foreach (var lpType in Settings.RoutePropertyTypes) { if (lpType.Selected) { RetrieveExternalPropertyDelegate dlg = new ExternalRoutePropertyRetriever(Session.Settings).RetrieveExternalProperty; var lp = Activator.CreateInstance(lpType.RoutePropertyType, Session, locations, dlg) as RouteProperty; if (lp != null) { lp.CacheManager = cacheManager; if (lp.ContainsValue) { var attributeName = GetCamelCaseString(lpType.RoutePropertyType.Name); var attributeValue = lp.ToString(formatter); writer.WriteAttributeString(attributeName, attributeValue); } } } } writer.WriteEndElement(); lastPl = pl; } writer.WriteEndElement(); segmentCount++; } writer.WriteEndElement(); writer.Close(); } }
protected override void Calculate() { var cachedProperty = GetFromCache(); if (cachedProperty != null) { value = cachedProperty.Value; return; } var currentLongLat = Session.Route.GetLocationFromParameterizedLocation(End); var lastPL = new ParameterizedLocation(End); ParameterizedLocation thisPL; ParameterizedLocation thresholdPL; double lastNodeDistance = 0; double thisNodeDistance = 0; while (true) { thisPL = Session.Route.GetNextPLNode(lastPL, ParameterizedLocation.Direction.Backward); if (thisPL == null || Session.Route.IsFirstPLInSegment(thisPL) || thisPL < Start) { break; } var longLat = Session.Route.GetLocationFromParameterizedLocation(thisPL); thisNodeDistance = LinearAlgebraUtil.DistancePointToPointLongLat(longLat, currentLongLat); if (thisNodeDistance > DistanceThreshold) { break; } lastPL = thisPL; lastNodeDistance = thisNodeDistance; } if (thisPL == null) { thisPL = new ParameterizedLocation(Start.SegmentIndex, 0); } if (Session.Route.IsFirstPLInSegment(thisPL)) { thresholdPL = thisPL; } else if (thisPL < Start) { thresholdPL = new ParameterizedLocation(Start); } else { var t = thisNodeDistance - lastNodeDistance == 0 ? 1 : (DistanceThreshold - lastNodeDistance) / (thisNodeDistance - lastNodeDistance); thresholdPL = new ParameterizedLocation(thisPL.SegmentIndex, lastPL.Value - t * (lastPL.Value - thisPL.Value)); } value = Session.Route.GetTimeFromParameterizedLocation(End) - Session.Route.GetTimeFromParameterizedLocation(thresholdPL); AddToCache(); }
protected override void Calculate() { var cachedProperty = GetFromCache(); if (cachedProperty != null) { value = cachedProperty.Value; return; } if (!Session.Route.ContainsWaypointAttribute(WaypointAttribute.MapReadingDuration)) { value = TimeSpan.Zero; } else { var pl = Locations.Start; DateTime?previousEndReadingTime = null; var totalTime = TimeSpan.Zero; var count = 0; while (true) { if (pl.Value == 0) { previousEndReadingTime = null; // reset when entering new segment } var w = pl.IsNode ? Session.Route.Segments[pl.SegmentIndex].Waypoints[(int)pl.Value] : Session.Route.CreateWaypointFromParameterizedLocation(pl); if (w.MapReadingState == BusinessEntities.MapReadingState.EndReading) { previousEndReadingTime = w.Time; } if (w.MapReadingState == BusinessEntities.MapReadingState.StartReading && previousEndReadingTime.HasValue) { totalTime += w.Time - previousEndReadingTime.Value; count++; } if (pl >= Locations.End) { break; } pl++; if (pl > Locations.End) { pl = new ParameterizedLocation(Locations.End); } } value = new TimeSpan(count == 0 ? 0 : totalTime.Ticks / count); } AddToCache(); }
protected override void Calculate() { var cachedProperty = GetFromCache(); if (cachedProperty != null) { value = cachedProperty.Value; return; } var sum = 0.0; var pl = new ParameterizedLocation(Start); double? previousAltitude = 0; // try to get value of close location from cache if(HasCache) { var closestProperty = CacheManager.GetLastAdded(GetType(), Locations); if(closestProperty != null) { if(closestProperty.Value != null) sum = (double)closestProperty.Value; pl = new ParameterizedLocation(closestProperty.Locations.IsSpan ? closestProperty.Locations.End : closestProperty.Locations.Location); previousAltitude = Session.Route.GetAttributeFromParameterizedLocation(WaypointAttribute.Altitude, pl); pl = Session.Route.GetNextPLNode(pl, ParameterizedLocation.Direction.Forward); } } while (pl != null && pl <= End) { var altitude = Session.Route.GetAttributeFromParameterizedLocation(WaypointAttribute.Altitude, pl); if (pl != Start && !Session.Route.IsFirstPLInSegment(pl)) { if (altitude.HasValue) { if (altitude > previousAltitude) sum += altitude.Value - previousAltitude.Value; } else { value = null; return; } } previousAltitude = altitude; if (pl >= End) break; pl = Session.Route.GetNextPLNode(pl, ParameterizedLocation.Direction.Forward); if (pl > End) pl = new ParameterizedLocation(End); } value = (double?)sum; AddToCache(); }
protected override void Calculate() { var cachedProperty = GetFromCache(); if (cachedProperty != null) { value = cachedProperty.Value; return; } if (!Session.Route.ContainsWaypointAttribute(WaypointAttribute.MapReadingDuration)) { value = null; } else { var pl = Locations.Start; var previousStartReadingTime = default(DateTime); double previousStartReadingDistance = 0; var totalTime = TimeSpan.Zero; var totalDistance = 0.0; while (true) { var w = pl.IsNode ? Session.Route.Segments[pl.SegmentIndex].Waypoints[(int)pl.Value] : Session.Route.CreateWaypointFromParameterizedLocation(pl); if (w.MapReadingState == BusinessEntities.MapReadingState.StartReading || (w.MapReadingState == BusinessEntities.MapReadingState.Reading && pl == Locations.Start)) { previousStartReadingTime = w.Time; previousStartReadingDistance = (double)w.Attributes[WaypointAttribute.Distance]; } if ((w.MapReadingState == BusinessEntities.MapReadingState.EndReading && pl != Locations.Start) || (w.MapReadingState == BusinessEntities.MapReadingState.Reading && pl == Locations.End)) { totalTime += w.Time - previousStartReadingTime; totalDistance += (double)w.Attributes[WaypointAttribute.Distance] - previousStartReadingDistance; } if (pl >= Locations.End) { break; } pl = Session.Route.GetNextPLNode(pl, ParameterizedLocation.Direction.Forward); if (pl > Locations.End) { pl = new ParameterizedLocation(Locations.End); } } value = totalDistance == 0 ? (TimeSpan?)null : TimeSpan.FromSeconds(totalTime.TotalSeconds / (totalDistance / 1000)); } AddToCache(); }
protected override void Calculate() { var cachedProperty = GetFromCache(); if (cachedProperty != null) { value = cachedProperty.Value; return; } double? max = null; var pl = new ParameterizedLocation(Start); // try to get value of close location from cache if (HasCache) { var closestProperty = CacheManager.GetLastAdded(GetType(), Locations); if (closestProperty != null) { if (closestProperty.Value != null) max = (double)closestProperty.Value; pl = new ParameterizedLocation(closestProperty.Locations.IsSpan ? closestProperty.Locations.End : closestProperty.Locations.Location); pl = Session.Route.GetNextPLNode(pl, ParameterizedLocation.Direction.Forward); } } while (pl <= End) { var power = Session.Route.GetAttributeFromParameterizedLocation(WaypointAttribute.Power, pl); if (power.HasValue) { if (!max.HasValue || power.Value > max.Value) max = power.Value; } else { value = null; return; } if (pl >= End) break; pl = Session.Route.GetNextPLNode(pl, ParameterizedLocation.Direction.Forward); if (pl > End) pl = new ParameterizedLocation(End); } if(max.HasValue) value = max.Value; AddToCache(); }
protected override void Calculate() { var cachedProperty = GetFromCache(); if (cachedProperty != null) { value = cachedProperty.Value; return; } var currentLongLat = Session.Route.GetLocationFromParameterizedLocation(Start); var lastPL = new ParameterizedLocation(Start); ParameterizedLocation thisPL; ParameterizedLocation thresholdPL; double lastNodeDistance = 0; double thisNodeDistance = 0; while (true) { thisPL = Session.Route.GetNextPLNode(lastPL, ParameterizedLocation.Direction.Forward); if (thisPL == null || Session.Route.IsLastPLInSegment(thisPL) || thisPL > End) break; var longLat = Session.Route.GetLocationFromParameterizedLocation(thisPL); thisNodeDistance = LinearAlgebraUtil.DistancePointToPointLongLat(longLat, currentLongLat); if (thisNodeDistance > DistanceThreshold) break; lastPL = thisPL; lastNodeDistance = thisNodeDistance; } if (thisPL == null) thisPL = new ParameterizedLocation(Start.SegmentIndex, Session.Route.Segments[Start.SegmentIndex].Waypoints.Count - 1); if (Session.Route.IsLastPLInSegment(thisPL)) { thresholdPL = thisPL; } else if (thisPL > End) { thresholdPL = new ParameterizedLocation(End); } else { var t = thisNodeDistance - lastNodeDistance == 0 ? 1 : (DistanceThreshold - lastNodeDistance) / (thisNodeDistance - lastNodeDistance); thresholdPL = new ParameterizedLocation(thisPL.SegmentIndex, lastPL.Value + t * (thisPL.Value - lastPL.Value)); } value = Session.Route.GetTimeFromParameterizedLocation(thresholdPL) - Session.Route.GetTimeFromParameterizedLocation(Start); AddToCache(); }
public RouteProperty GetClosest(Type routePropertyType, RouteLocations locations, ParameterizedLocation.Direction direction) { if (!cache.ContainsKey(routePropertyType)) { return(null); } var cacheSection = cache[routePropertyType]; RouteProperty closestRouteProperty = null; ParameterizedLocation closestPL = null; if (locations.IsSpan) { foreach (var item in cacheSection) { if (item.Key.Start == locations.Start // need to have same start && (closestPL == null || (direction == ParameterizedLocation.Direction.Forward && item.Key.End >= locations.End && item.Key.End < closestPL) || (direction == ParameterizedLocation.Direction.Backward && item.Key.End <= locations.End && item.Key.End > closestPL) )) { closestPL = item.Key.End; closestRouteProperty = item.Value; } } } else { foreach (var item in cacheSection) { if (closestPL == null || (direction == ParameterizedLocation.Direction.Forward && item.Key.Location >= locations.Location && item.Key.Location < closestPL) || (direction == ParameterizedLocation.Direction.Backward && item.Key.Location <= locations.Location && item.Key.Location > closestPL) ) { closestPL = item.Key.End; closestRouteProperty = item.Value; } } } return(closestRouteProperty); }
protected override void Calculate() { var cachedProperty = GetFromCache(); if (cachedProperty != null) { value = cachedProperty.Value; return; } if (!Session.Route.ContainsWaypointAttribute(WaypointAttribute.MapReadingDuration)) { value = TimeSpan.Zero; } else { var pl = Locations.Start; DateTime? previousEndReadingTime = null; var totalTime = TimeSpan.Zero; var count = 0; while(true) { if(pl.Value == 0) previousEndReadingTime = null; // reset when entering new segment var w = pl.IsNode ? Session.Route.Segments[pl.SegmentIndex].Waypoints[(int) pl.Value] : Session.Route.CreateWaypointFromParameterizedLocation(pl); if(w.MapReadingState == BusinessEntities.MapReadingState.EndReading) { previousEndReadingTime = w.Time; } if (w.MapReadingState == BusinessEntities.MapReadingState.StartReading && previousEndReadingTime.HasValue) { totalTime += w.Time - previousEndReadingTime.Value; count++; } if (pl >= Locations.End) break; pl++; if (pl > Locations.End) pl = new ParameterizedLocation(Locations.End); } value = new TimeSpan(count == 0 ? 0 : totalTime.Ticks / count); } AddToCache(); }
protected override void Calculate() { var cachedProperty = GetFromCache(); if (cachedProperty != null) { value = cachedProperty.Value; return; } if (!Session.Route.ContainsWaypointAttribute(WaypointAttribute.MapReadingDuration)) { value = 0; } else { var count = 0; var pl = Locations.Start; while (true) { var w = pl.IsNode ? Session.Route.Segments[pl.SegmentIndex].Waypoints[(int)pl.Value] : Session.Route.CreateWaypointFromParameterizedLocation(pl); if (w.MapReadingState == BusinessEntities.MapReadingState.StartReading || (w.MapReadingState == BusinessEntities.MapReadingState.Reading && pl == Locations.Start)) { count++; } if (pl >= Locations.End) { break; } pl = Session.Route.GetNextPLNode(pl, ParameterizedLocation.Direction.Forward); if (pl > Locations.End) { pl = new ParameterizedLocation(Locations.End); } } value = count; } AddToCache(); }
protected override void Calculate() { var cachedProperty = GetFromCache(); if (cachedProperty != null) { value = cachedProperty.Value; return; } var sum = new TimeSpan(); for (var i = Start.SegmentIndex; i <= End.SegmentIndex; i++) { var startPL = new ParameterizedLocation(i, 0); var endPL = new ParameterizedLocation(i, Session.Route.Segments[i].Waypoints.Count-1); if (startPL < Start) startPL = Start; if (endPL > End) endPL = End; sum += Session.Route.GetTimeFromParameterizedLocation(endPL) - Session.Route.GetTimeFromParameterizedLocation(startPL); } value = sum; AddToCache(); }
public RouteProperty GetClosest(Type routePropertyType, RouteLocations locations, ParameterizedLocation.Direction direction) { if (!cache.ContainsKey(routePropertyType)) return null; var cacheSection = cache[routePropertyType]; RouteProperty closestRouteProperty = null; ParameterizedLocation closestPL = null; if (locations.IsSpan) { foreach (var item in cacheSection) { if (item.Key.Start == locations.Start // need to have same start && (closestPL == null || (direction == ParameterizedLocation.Direction.Forward && item.Key.End >= locations.End && item.Key.End < closestPL) || (direction == ParameterizedLocation.Direction.Backward && item.Key.End <= locations.End && item.Key.End > closestPL) )) { closestPL = item.Key.End; closestRouteProperty = item.Value; } } } else { foreach (var item in cacheSection) { if (closestPL == null || (direction == ParameterizedLocation.Direction.Forward && item.Key.Location >= locations.Location && item.Key.Location < closestPL) || (direction == ParameterizedLocation.Direction.Backward && item.Key.Location <= locations.Location && item.Key.Location > closestPL) ) { closestPL = item.Key.End; closestRouteProperty = item.Value; } } } return closestRouteProperty; }
protected override void Calculate() { var cachedProperty = GetFromCache(); if (cachedProperty != null) { value = cachedProperty.Value; return; } if (!Session.Route.ContainsWaypointAttribute(WaypointAttribute.MapReadingDuration)) { value = 0; } else { var count = 0; var pl = Locations.Start; while (true) { var w = pl.IsNode ? Session.Route.Segments[pl.SegmentIndex].Waypoints[(int)pl.Value] : Session.Route.CreateWaypointFromParameterizedLocation(pl); if (w.MapReadingState == BusinessEntities.MapReadingState.StartReading || (w.MapReadingState == BusinessEntities.MapReadingState.Reading && pl == Locations.Start)) { count++; } if (pl >= Locations.End) break; pl = Session.Route.GetNextPLNode(pl, ParameterizedLocation.Direction.Forward); if (pl > Locations.End) pl = new ParameterizedLocation(Locations.End); } value = count; } AddToCache(); }
public CircleTimeAtEndOfSpan(Session session, ParameterizedLocation start, ParameterizedLocation end, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, start, end, retrieveExternalProperty) { }
public Speed(Session session, ParameterizedLocation location, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, location, retrieveExternalProperty) { }
public AverageMapReadingTime(Session session, ParameterizedLocation start, ParameterizedLocation end, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, start, end, retrieveExternalProperty) { }
public void AddLap(ParameterizedLocation parameterizedLocation, bool showLapTimeForm) { var time = CurrentSession.Route.GetTimeFromParameterizedLocation(parameterizedLocation); time = time.AddTicks(-time.Ticks % TimeSpan.TicksPerSecond); // truncate to nearest second if (showLapTimeForm) { using (var form = new LapTimeForm { InitialTime = time, Session = CurrentSession }) { if (form.ShowDialog() != DialogResult.OK) return; time = form.Time; } } if (!CurrentSession.Laps.Exists(time)) { ExecuteAction(new AddLapAction(new Lap(time, LapType.Lap), CurrentSession)); DrawMap(MapDrawingFlags.Route | MapDrawingFlags.Markers); } }
protected override void Calculate() { var cachedProperty = GetFromCache(); if (cachedProperty != null) { value = cachedProperty.Value; return; } if (!Session.Route.ContainsWaypointAttribute(WaypointAttribute.MapReadingDuration)) { value = null; } else { var pl = Locations.Start; var previousEndReadingTime = default(DateTime); double previousEndReadingDistance = 0; var totalTime = TimeSpan.Zero; var totalDistance = 0.0; while (true) { var w = pl.IsNode ? Session.Route.Segments[pl.SegmentIndex].Waypoints[(int)pl.Value] : Session.Route.CreateWaypointFromParameterizedLocation(pl); if (w.MapReadingState == BusinessEntities.MapReadingState.EndReading || (w.MapReadingState == BusinessEntities.MapReadingState.NotReading && pl == Locations.Start)) { previousEndReadingTime = w.Time; previousEndReadingDistance = (double)w.Attributes[WaypointAttribute.Distance]; } if ((w.MapReadingState == BusinessEntities.MapReadingState.StartReading && pl != Locations.Start) || (w.MapReadingState == BusinessEntities.MapReadingState.NotReading && pl == Locations.End)) { totalTime += w.Time - previousEndReadingTime; totalDistance += (double)w.Attributes[WaypointAttribute.Distance] - previousEndReadingDistance; } if (pl >= Locations.End) break; pl = Session.Route.GetNextPLNode(pl, ParameterizedLocation.Direction.Forward); if (pl > Locations.End) pl = new ParameterizedLocation(Locations.End); } value = totalDistance == 0 ? (TimeSpan?)null : TimeSpan.FromSeconds(Math.Min(86400, totalTime.TotalSeconds) /* to prevent overflow */ / (totalDistance / 1000)); } AddToCache(); }
public AveragePaceWhenNotReadingMapFromStart(Session session, ParameterizedLocation location, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, location, retrieveExternalProperty) { }
public AveragePaceWhenNotReadingMap(Session session, ParameterizedLocation start, ParameterizedLocation end, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, start, end, retrieveExternalProperty) { }
public AverageTimeBetweenMapReadings(Session session, ParameterizedLocation start, ParameterizedLocation end, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, start, end, retrieveExternalProperty) { }
public AltitudeDifferenceFromStart(Session session, ParameterizedLocation location, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, location, retrieveExternalProperty) { }
public AverageTimeBetweenMapReadingsFromStart(Session session, ParameterizedLocation location, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, location, retrieveExternalProperty) { }
public RouteToStraightLine(Session session, ParameterizedLocation start, ParameterizedLocation end, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, start, end, retrieveExternalProperty) { }
public RouteMouseHoverEventArgs(ParameterizedLocation parameterizedLocation, bool isClose) { ParameterizedLocation = parameterizedLocation; IsClose = isClose; }
public NumberOfMapReadings(Session session, ParameterizedLocation start, ParameterizedLocation end, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, start, end, retrieveExternalProperty) { }
protected override void Calculate() { var cachedProperty = GetFromCache(); if (cachedProperty != null) { value = cachedProperty.Value; return; } var sum = 0.0; var pl = new ParameterizedLocation(Start); double?previousAltitude = 0; // try to get value of close location from cache if (HasCache) { var closestProperty = CacheManager.GetLastAdded(GetType(), Locations); if (closestProperty != null) { if (closestProperty.Value != null) { sum = (double)closestProperty.Value; } pl = new ParameterizedLocation(closestProperty.Locations.IsSpan ? closestProperty.Locations.End : closestProperty.Locations.Location); previousAltitude = Session.Route.GetAttributeFromParameterizedLocation(WaypointAttribute.Altitude, pl); pl = Session.Route.GetNextPLNode(pl, ParameterizedLocation.Direction.Forward); } } while (pl != null && pl <= End) { var altitude = Session.Route.GetAttributeFromParameterizedLocation(WaypointAttribute.Altitude, pl); if (pl != Start && !Session.Route.IsFirstPLInSegment(pl)) { if (altitude.HasValue) { if (altitude < previousAltitude) { sum += previousAltitude.Value - altitude.Value; } } else { value = null; return; } } previousAltitude = altitude; if (pl >= End) { break; } pl = Session.Route.GetNextPLNode(pl, ParameterizedLocation.Direction.Forward); if (pl > End) { pl = new ParameterizedLocation(End); } } value = sum; AddToCache(); }
public NumberOfMapReadingsFromStart(Session session, ParameterizedLocation location, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, location, retrieveExternalProperty) { }
public AverageMapReadingTimeFromStart(Session session, ParameterizedLocation location, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, location, retrieveExternalProperty) { }
public void Cut(ParameterizedLocation parameterizedLocation, DateTime? time) { if (!time.HasValue) time = CurrentSession.Route.GetTimeFromParameterizedLocation(parameterizedLocation); using (var form = new RouteCutForm { InitialTime = time.Value }) { double distance = CurrentSession.Route.GetAttributeFromParameterizedLocation(WaypointAttribute.Distance, parameterizedLocation). Value; double totalDistance = CurrentSession.Route.LastWaypoint.Attributes[WaypointAttribute.Distance].Value; form.CutType = (distance < totalDistance/2 ? CutType.Before : CutType.After); if (form.ShowDialog() == DialogResult.OK) { mouseHoverHandle = null; var action = new CutRouteAction(CurrentSession, form.Time, form.CutType); ExecuteAction(action); DrawMap(MapDrawingFlags.Route | MapDrawingFlags.Markers); } } }
public Altitude(Session session, ParameterizedLocation location, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, location, retrieveExternalProperty) { }
protected override void Calculate() { var pl = new ParameterizedLocation(Start); var nodes = new List <CadenceNode>(); while (pl <= End) { var cadence = Session.Route.GetAttributeFromParameterizedLocation(WaypointAttribute.Cadence, pl); if (cadence.HasValue) { var nodeType = NodeType.Intermediate; if (Session.Route.IsFirstPLInSegment(pl)) { nodeType = NodeType.Begin; } if (Session.Route.IsLastPLInSegment(pl)) { nodeType = NodeType.End; } nodes.Add(new CadenceNode() { Cadence = cadence.Value, Time = Session.Route.GetTimeFromParameterizedLocation(pl), NodeType = nodeType }); } else { value = null; return; } if (pl >= End) { break; } pl = Session.Route.GetNextPLNode(pl, ParameterizedLocation.Direction.Forward); if (pl > End) { pl = new ParameterizedLocation(End); } } if (nodes.Count > 0) { nodes[0].NodeType = NodeType.Begin; nodes[nodes.Count - 1].NodeType = NodeType.End; } var revolutions = 0.0; var totalDuration = 0.0; for (var i = 1; i < nodes.Count; i++) { double duration = 0; switch (nodes[i].NodeType) { case NodeType.Begin: duration = (nodes[i + 1].Time - nodes[i].Time).TotalSeconds / 2; break; case NodeType.End: duration = (nodes[i].Time - nodes[i - 1].Time).TotalSeconds / 2; break; case NodeType.Intermediate: duration = (nodes[i].Time - nodes[i - 1].Time).TotalSeconds / 2 + (nodes[i + 1].Time - nodes[i].Time).TotalSeconds / 2; break; } revolutions += duration * nodes[i].Cadence / 60; totalDuration += duration; } value = (double?)(totalDuration == 0 ? 0 : revolutions / totalDuration * 60); AddToCache(); }
public CircleTimeForward(Session session, ParameterizedLocation location, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, location, retrieveExternalProperty) { }
public AltitudeDifference(Session session, ParameterizedLocation start, ParameterizedLocation end, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, start, end, retrieveExternalProperty) { }
protected RouteFromStartProperty(Session session, ParameterizedLocation location, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, new RouteLocations(location), retrieveExternalProperty) { }
protected override void Calculate() { var cachedProperty = GetFromCache(); if (cachedProperty != null) { value = cachedProperty.Value; return; } double?min = null; var pl = new ParameterizedLocation(Start); // try to get value of close location from cache if (HasCache) { var closestProperty = CacheManager.GetLastAdded(GetType(), Locations); if (closestProperty != null) { if (closestProperty.Value != null) { min = (double)closestProperty.Value; } pl = new ParameterizedLocation(closestProperty.Locations.IsSpan ? closestProperty.Locations.End : closestProperty.Locations.Location); pl = Session.Route.GetNextPLNode(pl, ParameterizedLocation.Direction.Forward); } } while (pl <= End) { var hr = Session.Route.GetAttributeFromParameterizedLocation(WaypointAttribute.HeartRate, pl); if (hr.HasValue) { if (!min.HasValue || hr.Value < min.Value) { min = hr.Value; } } else { value = null; return; } if (pl >= End) { break; } pl = Session.Route.GetNextPLNode(pl, ParameterizedLocation.Direction.Forward); if (pl > End) { pl = new ParameterizedLocation(End); } } if (min.HasValue) { value = min.Value; } AddToCache(); }
public AscentFromStart(Session session, ParameterizedLocation location, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, location, retrieveExternalProperty) { }
public MinHeartRate(Session session, ParameterizedLocation start, ParameterizedLocation end, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, start, end, retrieveExternalProperty) { }
public Ascent(Session session, ParameterizedLocation start, ParameterizedLocation end, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, start, end, retrieveExternalProperty) { }
protected RouteMomentaneousProperty(Session session, ParameterizedLocation location, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, new RouteLocations(location), retrieveExternalProperty) { }
public RouteToStraightLineFromStart(Session session, ParameterizedLocation location, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, location, retrieveExternalProperty) { }
private void HandleMouseHover(ParameterizedLocation pl, bool showMarker) { if (showMarker && pl != null) { UpdateMomentaneousInfo(pl); } else { ResetMomentaneousInfo(); } }
public SessionParameterizedLocationEventArgs(Session session, ParameterizedLocation parameterizedLocation) { Session = session; ParameterizedLocation = parameterizedLocation; }
private void UpdateMomentaneousInfo(ParameterizedLocation pl) { // TODO: backbuffering? // TODO: toolstrip back color? At least some sort of top line that separates it from above var g = momentaneousInfoPanelBackBufferGraphics; g.Clear(momentaneousInfoPanel.BackColor); g.TextRenderingHint = TextRenderingHint.AntiAlias; var lightPen = new Pen(SystemColors.ControlLight, 1F); var darkPen = new Pen(SystemColors.ControlDark, 1F); g.DrawLine(darkPen, 0, 0, momentaneousInfoPanelBackBuffer.Width - 1, 0); if (pl != null) { Route r = canvas.CurrentSession.Route; var lapStartPL = r.GetLapStartParameterizedLocation(pl); foreach (var selectableRoutePropertyType in ApplicationSettings.MomentaneousInfoPropertyTypes) { if (selectableRoutePropertyType.Selected) { RetrieveExternalPropertyDelegate dlg = new ExternalRoutePropertyRetriever(canvas.CurrentSession.Settings).RetrieveExternalProperty; var property = Activator.CreateInstance(selectableRoutePropertyType.RoutePropertyType, canvas.CurrentSession, new RouteLocations(lapStartPL, pl), dlg) as RouteProperty; if (property != null ) { var templateString = Strings.ResourceManager.GetString("RoutePropertyNameAndValue_" + property.GetType().Name) ?? property.GetType().Name + ": {0}"; var text = property.Value != null ? string.Format(templateString, property) : string.Format(templateString, "-"); if (momentaneousInfoLabelRectangles.ContainsKey(selectableRoutePropertyType.RoutePropertyType)) // this should not be needed, but people seem to have problem with "The given key was not present in the dictionary. (mscorlib)" { var rect = momentaneousInfoLabelRectangles[selectableRoutePropertyType.RoutePropertyType]; g.DrawString(text, momentaneousInfoPanel.Font, Brushes.Black, rect.Location); // draw separator g.DrawLine(lightPen, rect.Right + momentaneousInfoLabelPadding.Right, rect.Top, rect.Right + momentaneousInfoLabelPadding.Right, rect.Bottom); g.DrawLine(darkPen, rect.Right + momentaneousInfoLabelPadding.Right + 1, rect.Top, rect.Right + momentaneousInfoLabelPadding.Right + 1, rect.Bottom); } } } } } lightPen.Dispose(); darkPen.Dispose(); CopyMomentaneousInfoBackBufferToScreen(); }
public void Cut(ParameterizedLocation parameterizedLocation) { Cut(parameterizedLocation, null); }
protected RouteSpanProperty(Session session, ParameterizedLocation start, ParameterizedLocation end, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, new RouteLocations(start, end), retrieveExternalProperty) { }
public void DrawActiveHandle(ParameterizedLocation pl) { // mouse hover over route if (activeHandle != null) { // reset handle drawer to standard handle drawer activeHandle.MarkerDrawer = CurrentSession.Settings.MarkerDrawers[MarkerType.Handle]; } activeHandle = null; activeLap = null; PointD routeLocation = CurrentSession.AdjustedRoute.GetLocationFromParameterizedLocation(pl); if (pl != null) { GeneralMatrix transformationMatrix = CurrentSession.GetTransformationMatrixFromParameterizedLocation(pl); mouseHoverHandle = new Handle(pl, routeLocation, transformationMatrix, CurrentSession.Settings.MarkerDrawers[MarkerType.MouseHover]); } else { mouseHoverHandle = null; } DrawMap(MapDrawingFlags.Markers); }
public AverageStraightLinePace(Session session, ParameterizedLocation start, ParameterizedLocation end, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, start, end, retrieveExternalProperty) { }
public AverageCadenceFromStart(Session session, ParameterizedLocation location, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, location, retrieveExternalProperty) { }
public AverageStraightLinePaceFromStart(Session session, ParameterizedLocation location, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, location, retrieveExternalProperty) { }
public AverageCadence(Session session, ParameterizedLocation start, ParameterizedLocation end, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, start, end, retrieveExternalProperty) { }
public MinHeartRateFromStart(Session session, ParameterizedLocation location, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, location, retrieveExternalProperty) { }