From ff57ebcbe4949b7b53e7c42ecc7916b601a67213 Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Fri, 28 Aug 2026 10:52:03 +0200 Subject: modernize --- README.md | 3 +++ mountain_pass/extract.go | 19 +++++++------------ ride/fit.go | 20 ++++---------------- strava/sync.go | 2 +- 4 files changed, 15 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 8744938..de57310 100644 --- a/README.md +++ b/README.md @@ -165,6 +165,8 @@ go tool pprof -http=:8081 http://localhost:8080/debug/pprof/heap # allocs ## TODO +- http://localhost:8080/rides/436: remove train part? +- also http://localhost:8080/rides/438 - Garmin GPX: elevation, time, temp, HR, cadence - Garmin TCX: stats (cal, HR, time, cadence) + pos, alt, distance, HR, cadence, speed - Garmin FIT: time, sport, lap/split, gps, sensor, events @@ -186,6 +188,7 @@ go tool pprof -http=:8081 http://localhost:8080/debug/pprof/heap # allocs - Ride planning - Road quality (Arbois = 2/5, Roquefavour = 4/5) - Blog with pictures and markdown +- Multi activity (Raid, Tour) ## Resources diff --git a/mountain_pass/extract.go b/mountain_pass/extract.go index ccf8d06..712a3e1 100644 --- a/mountain_pass/extract.go +++ b/mountain_pass/extract.go @@ -7,6 +7,7 @@ import ( "io" "log/slog" "os" + "slices" "strconv" "strings" @@ -168,23 +169,17 @@ func categorizePass(tags osm.Tags, highways []string) string { natural := tags.Find("natural") sport := tags.Find("sport") isHikingNode := natural == "rock" || sport == "climbing" - for _, h := range highways { - if isRoadHighway(h) { - return CategoryRoad - } + if slices.ContainsFunc(highways, isRoadHighway) { + return CategoryRoad } if isHikingNode { return CategoryHiking } - for _, h := range highways { - if h == "track" { - return CategoryTrack - } + if slices.Contains(highways, "track") { + return CategoryTrack } - for _, h := range highways { - if isPathHighway(h) { - return CategoryPath - } + if slices.ContainsFunc(highways, isPathHighway) { + return CategoryPath } return CategoryUnknown } diff --git a/ride/fit.go b/ride/fit.go index 7c4ba2e..760cec1 100644 --- a/ride/fit.go +++ b/ride/fit.go @@ -157,10 +157,7 @@ func EncodeFIT(ride Ride, w io.Writer) error { rec.PositionLong = fit.NewLongitudeDegrees(coord.Lon) // Altitude: scaled (value+500)*5, invalid 0xFFFF elev := ride.Elevations[i] - scaled := int((elev + 500) * 5) - if scaled < 0 { - scaled = 0 - } + scaled := max(int((elev+500)*5), 0) if scaled > 0xFFFE { scaled = 0xFFFE } @@ -168,10 +165,7 @@ func EncodeFIT(ride Ride, w io.Writer) error { rec.EnhancedAltitude = 0xFFFFFFFF if hasHR { - v := int(heartRates[i]) - if v < 0 { - v = 0 - } + v := max(int(heartRates[i]), 0) if v > 254 { v = 254 } @@ -180,10 +174,7 @@ func EncodeFIT(ride Ride, w io.Writer) error { rec.HeartRate = 0xFF } if hasCad { - v := int(cadences[i]) - if v < 0 { - v = 0 - } + v := max(int(cadences[i]), 0) if v > 254 { v = 254 } @@ -192,10 +183,7 @@ func EncodeFIT(ride Ride, w io.Writer) error { rec.Cadence = 0xFF } if hasPower { - v := int(powers[i]) - if v < 0 { - v = 0 - } + v := max(int(powers[i]), 0) if v > 65534 { v = 65534 } diff --git a/strava/sync.go b/strava/sync.go index 4630a1d..34559de 100644 --- a/strava/sync.go +++ b/strava/sync.go @@ -164,7 +164,7 @@ func activityFIT(activity Activity, streams activityStreams) ([]byte, error) { distance := 0.0 var previous *geodist.Coord - for i := 0; i < n; i++ { + for i := range n { coord := geodist.Coord{Lat: streams.LatLng[i][0], Lon: streams.LatLng[i][1]} if previous != nil { _, km := geodist.HaversineDistance(*previous, coord) -- cgit v1.3