diff options
| -rw-r--r-- | README.md | 3 | ||||
| -rw-r--r-- | ride/climb.go | 2 | ||||
| -rw-r--r-- | ride/climb_test.go | 8 | ||||
| -rw-r--r-- | ride/ride.go | 15 |
4 files changed, 25 insertions, 3 deletions
@@ -17,8 +17,6 @@ - Get back what is interesting in previous projects - Go bike: - Only tooling for golang, project is different - - Rust bike - - Algorithm + example - Django bike - https://github.com/paulmach/osm - https://github.com/tkrajina/gpxgo @@ -30,6 +28,7 @@ - CI / Tooling - Tests - linter for calls to `make([]..., n)` that then use append +- try this algo: inc end while score inc, then inc start while score inc, again until optimum ## Examples diff --git a/ride/climb.go b/ride/climb.go index bf1dfc9..3b3d6dc 100644 --- a/ride/climb.go +++ b/ride/climb.go @@ -98,7 +98,7 @@ func climbsBetween(points []Point, start int, end int) []Climb { } } // TODO: Use descent to reduce recursion - if highest == start { + if points[highest].distance-points[start].distance < ClimbDistanceMinimum { return climbsBetween(points, start+1, end) } climb := bestClimbBetween(points, start, highest) diff --git a/ride/climb_test.go b/ride/climb_test.go index ec74e56..23c7a2e 100644 --- a/ride/climb_test.go +++ b/ride/climb_test.go @@ -66,6 +66,14 @@ func TestClimbThenFalseFlat(t *testing.T) { assert.Equal(t, "0.0km-2.0km: 2.0km at 7.0% (98 pts - Cat 3)", r.String(climbs[0])) } +func TestSmallClimbWithDescentInsideFalseFlat(t *testing.T) { + r := RideBuilder{precision: 100}.WithSection("10km at 1%").WithSection("2km at 7%").WithSection("1km at -7%").WithSection("10km at 1%").Build() + climbs := r.AllClimbs() + + assert.Len(t, climbs, 1) + assert.Equal(t, "10.0km-12.0km: 2.0km at 7.0% (98 pts - Cat 3)", r.String(climbs[0])) +} + func TestPogacar20220721(t *testing.T) { gpxContent, err := gpx.ParseFile("../examples/2022-07-21.Pogacar.gpx") assert.NoError(t, err) diff --git a/ride/ride.go b/ride/ride.go index 8206793..2f0b78b 100644 --- a/ride/ride.go +++ b/ride/ride.go @@ -44,3 +44,18 @@ func (r *Ride) String(climb Climb) string { score := Score(r.points, climb.start, climb.end) return fmt.Sprintf("%.1fkm-%.1fkm: %.1fkm at %.1f%% (%d pts - %s)", start.distance/1000, end.distance/1000, (end.distance-start.distance)/1000, Slope(start, end)*100, int(score), Category(score)) } + +func (r *Ride) ScoreFromKm(start, end float64) float64 { + i := 0 + j := 0 + for k, p := range r.points { + if i == 0 && p.distance >= start*1000 { + i = k + } + if j == 0 && p.distance >= end*1000 { + j = k + break + } + } + return Score(r.points, i, j) +} |