aboutsummaryrefslogtreecommitdiff
path: root/rideanalysis/attempts.go
blob: faf02e95813460a68cfcbf4bd05ec695c0128eea (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
}