aboutsummaryrefslogtreecommitdiff
path: root/ride/climb.go
diff options
context:
space:
mode:
Diffstat (limited to 'ride/climb.go')
-rw-r--r--ride/climb.go38
1 files changed, 22 insertions, 16 deletions
diff --git a/ride/climb.go b/ride/climb.go
index 8852cbf..29a4dcf 100644
--- a/ride/climb.go
+++ b/ride/climb.go
@@ -28,20 +28,19 @@ const (
type categoryInfo struct {
label string
- maxScore float64
+ minScore float64
}
-// categories describes each Category: its display label and the exclusive
-// Cotacol score ceiling it applies to. A score at or above CategoryOne's
-// ceiling is Hors Catégorie.
+// categories describes each Category: its display label and the inclusive
+// Cotacol score floor at which it starts applying. A score at or above
+// CategoryOne's floor is Hors Catégorie; CategoryNo has no floor.
var categories = map[Category]categoryInfo{
- CategoryNo: {label: "NO", maxScore: 35},
- CategoryFour: {label: "Cat 4", maxScore: 80},
- CategoryThree: {label: "Cat 3", maxScore: 180},
- CategoryTwo: {label: "Cat 2", maxScore: 250},
- CategoryOne: {label: "Cat 1", maxScore: 600},
- // Hors Catégorie has no ceiling.
- CategoryHC: {label: "HC", maxScore: math.Inf(+1)},
+ CategoryNo: {label: "NO", minScore: math.Inf(-1)},
+ CategoryFour: {label: "Cat 4", minScore: 35},
+ CategoryThree: {label: "Cat 3", minScore: 80},
+ CategoryTwo: {label: "Cat 2", minScore: 180},
+ CategoryOne: {label: "Cat 1", minScore: 250},
+ CategoryHC: {label: "HC", minScore: 600},
}
// climbDetectionMinimumScore is the climb-detection score below which a
@@ -144,16 +143,23 @@ func (c Category) String() string {
return categories[c].label
}
-// CategoryOf returns the difficulty class of a Cotacol score.
+// CategoryOf returns the difficulty class of a Cotacol score: the category
+// with the highest floor the score reaches.
func CategoryOf(cotacol float64) Category {
- best := CategoryHC
- bestMax := math.Inf(+1)
+ best := CategoryNo
+ bestMin := math.Inf(-1)
+ found := false
for category, info := range categories {
- if cotacol < info.maxScore && info.maxScore < bestMax {
+ if cotacol >= info.minScore && (!found || info.minScore > bestMin) {
best = category
- bestMax = info.maxScore
+ bestMin = info.minScore
+ found = true
}
}
+ if !found {
+ // NaN reaches no floor; preserve the original switch default (HC).
+ return CategoryHC
+ }
return best
}