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) powers, _ := parsed.Powers() 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(), powers)) } return attempts }