aboutsummaryrefslogtreecommitdiff
path: root/rideanalysis/attempts.go
diff options
context:
space:
mode:
Diffstat (limited to 'rideanalysis/attempts.go')
-rw-r--r--rideanalysis/attempts.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/rideanalysis/attempts.go b/rideanalysis/attempts.go
new file mode 100644
index 0000000..faf02e9
--- /dev/null
+++ b/rideanalysis/attempts.go
@@ -0,0 +1,29 @@
+package rideanalysis
+
+import (
+ "github.com/martinlehoux/biking_home/official_climb"
+ "github.com/martinlehoux/biking_home/ride"
+)
+
+// Attempts extracts one attempt record per official-climb occurrence: numbered per climb in route order, timestamped from the ride's recorded points.
+func Attempts(rideID int64, analysis Result, parsed ride.Ride) []official_climb.Attempt {
+ occurrences := make(map[int64]int)
+ attempts := make([]official_climb.Attempt, 0)
+ for _, analyzed := range analysis.Climbs {
+ if analyzed.OfficialClimbID == 0 {
+ continue
+ }
+ occurrence := occurrences[analyzed.OfficialClimbID]
+ occurrences[analyzed.OfficialClimbID] = occurrence + 1
+ attempts = append(attempts, official_climb.AttemptFromStats(rideID, occurrence, official_climb.AttemptStats{
+ OfficialClimbID: analyzed.OfficialClimbID,
+ DistanceM: analyzed.DistanceM,
+ ElevationGainM: analyzed.ElevationGainM,
+ SlopePercent: analyzed.SlopePercent,
+ Cotacol: analyzed.Cotacol,
+ StartIndex: analyzed.Interval.Start,
+ EndIndex: analyzed.Interval.End,
+ }, parsed.Timestamps()))
+ }
+ return attempts
+}