Show Live/Ended status on LiveTrack sessions
A session's own end timestamp is absent until the activity is actually stopped, so its presence/absence is the status signal — no new data needed, just reading what was already there. Shown as a badge next to the session in the list and in its map hover popup.
This commit is contained in:
1 parent
55607aece9
commit
6b8ea27e22
3 files changed
+47
-5
No files matched your search
@@ -43,6 +43,11 @@ module Maptool
|
||||
# Distance/duration/activity type come from the last track point (its
|
||||
# totals are cumulative for the whole session), name/type from the
|
||||
# session details — nil-safe throughout since either can be missing.
|
||||
#
|
||||
# "active": Garmin doesn't set a session's `end` until the activity is
|
||||
# actually stopped, so its absence means the session is still recording
|
||||
# — inferred from the one (already-ended) session this was built
|
||||
# against, not verified against a session actually caught mid-activity.
|
||||
def self.summarize(result)
|
||||
last = result.points.last || {}
|
||||
session = result.session || {}
|
||||
@@ -51,6 +56,7 @@ module Maptool
|
||||
"activity_type" => last["activityType"],
|
||||
"distance_meters" => last["totalDistanceMeters"],
|
||||
"duration_secs" => last["totalDurationSecs"],
|
||||
"active" => session["end"].nil?,
|
||||
"start" => session["start"],
|
||||
"end" => session["end"],
|
||||
}
|
||||
@@ -145,6 +151,11 @@ if __FILE__ == $0
|
||||
raise "expected $undefined cleaned to nil" unless result.points[0]["totalDistanceMeters"].nil?
|
||||
raise "expected summary from last point" unless summary["activity_type"] == "CYCLING" && summary["distance_meters"] == 5000
|
||||
raise "expected session name in summary" unless summary["session_name"] == "Test Ride"
|
||||
raise "expected inactive: session has an end" if summary["active"]
|
||||
|
||||
ongoing_session = session.merge("end" => nil)
|
||||
ongoing_summary = Maptool::LiveTrackClient.summarize(Maptool::LiveTrackClient::Result.new(points: result.points, session: ongoing_session))
|
||||
raise "expected active: session has no end" unless ongoing_summary["active"]
|
||||
|
||||
no_points = client.send(:search, client.send(:parse_payloads, "<html></html>")) { |n| n["trackPoints"] if n["trackPoints"].is_a?(Array) }
|
||||
raise "expected nil when no trackPoints present" unless no_points.nil?
|
||||
|
||||
Reference in new issue
Block a user