diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-08-27 08:05:58 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-08-27 08:05:58 +0200 |
| commit | 1e8efcdb7e7747072e83bda3d4a7f0b3810a439d (patch) | |
| tree | 3f60ac83771f6f899bd4b2313af3ae8bc6b68ae7 | |
| parent | e73b7a9ccb4bc61e54d1fdc61b5954879c637d00 (diff) | |
Lint & fix
| -rw-r--r-- | README.md | 3 | ||||
| -rw-r--r-- | mountain_pass/detection.go | 2 | ||||
| -rw-r--r-- | ride/store.go | 12 | ||||
| -rw-r--r-- | strava/sync.go | 3 | ||||
| -rw-r--r-- | web/ride-filters.go | 16 | ||||
| -rw-r--r-- | web/templates.templ | 6 |
6 files changed, 20 insertions, 22 deletions
@@ -163,7 +163,8 @@ Add `github.com/grafana/pyroscope-go` and call `pyroscope.Start` with `ServerAdd - Auto detect new climbs from raw map - Perf - improve GPX parsing and Analyze - - Compact binary or vectorized storage for root + - Compact binary or vectorized storage for root + - Actually might be .fit - Strava - Resync metadata (title) from list - OffClimb diff --git a/mountain_pass/detection.go b/mountain_pass/detection.go index 139bc60..40281f3 100644 --- a/mountain_pass/detection.go +++ b/mountain_pass/detection.go @@ -140,7 +140,7 @@ func MatchClimb(climb ride.Climb, passes []MountainPass, radiusM, elevationToler func nearestCrossing(coords []geodist.Coord, distances, elevations []float64, mountainPass MountainPass) (Crossing, bool) { best := Crossing{Pass: mountainPass, DistanceToM: 1e18} - for i := 0; i < len(coords); i++ { + for i := range coords { distanceKm, _ := geodist.HaversineDistance(coords[i], *mountainPass.Coord) distanceM := distanceKm * 1000 if distanceM < best.DistanceToM { diff --git a/ride/store.go b/ride/store.go index 56cd087..2d022ad 100644 --- a/ride/store.go +++ b/ride/store.go @@ -4,6 +4,7 @@ import ( "database/sql" "fmt" "log/slog" + "strings" "time" "github.com/martinlehoux/kagamigo/kcore" @@ -324,17 +325,18 @@ func BulkUpdateCategories(db *sql.DB, ids []int64, bikeType BikeType, rideType R if !IsValidRideType(string(rideType)) { return 0, fmt.Errorf("invalid ride_type %q", rideType) } - query := "UPDATE rides SET bike_type = ?, ride_type = ?, updated_at = strftime('%Y-%m-%dT%H:%M:%SZ', 'now') WHERE id IN (" + var query strings.Builder + query.WriteString("UPDATE rides SET bike_type = ?, ride_type = ?, updated_at = strftime('%Y-%m-%dT%H:%M:%SZ', 'now') WHERE id IN (") args := []any{string(bikeType), string(rideType)} for i, id := range ids { if i > 0 { - query += "," + query.WriteString(",") } - query += "?" + query.WriteString("?") args = append(args, id) } - query += ")" - result, err := db.Exec(query, args...) + query.WriteString(")") + result, err := db.Exec(query.String(), args...) if err != nil { return 0, err } diff --git a/strava/sync.go b/strava/sync.go index a492a47..b8fa428 100644 --- a/strava/sync.go +++ b/strava/sync.go @@ -147,7 +147,8 @@ func activityGPX(activity Activity, streams activityStreams) ([]byte, error) { for i := range streams.LatLng { point := gpx.GPXPoint{ Latitude: streams.LatLng[i][0], - Longitude: streams.LatLng[i][1]} + Longitude: streams.LatLng[i][1], + } if i < len(streams.Altitude) { point.Elevation = *gpx.NewNullableFloat64(streams.Altitude[i]) } diff --git a/web/ride-filters.go b/web/ride-filters.go index 2282b8d..0bb97d8 100644 --- a/web/ride-filters.go +++ b/web/ride-filters.go @@ -2,6 +2,7 @@ package web import ( "net/url" + "slices" "strconv" "time" @@ -219,7 +220,7 @@ func parseRideRideTypesFilter(values []string) []ride.RideType { continue } rideType := ride.RideType(value) - if containsRideType(set, rideType) { + if slices.Contains(set, rideType) { continue } set = append(set, rideType) @@ -240,21 +241,12 @@ func defaultRideTypes() []ride.RideType { } } -func containsRideType(types []ride.RideType, target ride.RideType) bool { - for _, candidate := range types { - if candidate == target { - return true - } - } - return false -} - func rideTypesEqual(a, b []ride.RideType) bool { if len(a) != len(b) { return false } for _, candidate := range a { - if !containsRideType(b, candidate) { + if !slices.Contains(b, candidate) { return false } } @@ -438,7 +430,7 @@ func rideMatchesFilters(item ride.StoredRide, filters RideFilters) bool { if filters.BikeType != nil && item.BikeType != *filters.BikeType { return false } - if len(filters.RideTypes) > 0 && !containsRideType(filters.RideTypes, item.RideType) { + if len(filters.RideTypes) > 0 && !slices.Contains(filters.RideTypes, item.RideType) { return false } return true diff --git a/web/templates.templ b/web/templates.templ index 6bf0154..8fbed0c 100644 --- a/web/templates.templ +++ b/web/templates.templ @@ -1,5 +1,7 @@ package web +import "slices" + templ Layout(title string, content templ.Component) { <!doctype html> <html lang="en"> @@ -66,7 +68,7 @@ templ RidesContent(data RidesPageData) { <legend>Ride type</legend> <div class="ride-type-options"> for _, opt := range rideTypeOptions { - <label class="ride-type-option"><input type="checkbox" name="ride_type" value={ string(opt) } checked?={ containsRideType(data.Filters.RideTypes, opt) }/><span>{ rideTypeLabels[opt] }</span></label> + <label class="ride-type-option"><input type="checkbox" name="ride_type" value={ string(opt) } checked?={ slices.Contains(data.Filters.RideTypes, opt) }/><span>{ rideTypeLabels[opt] }</span></label> } </div> </fieldset> @@ -136,7 +138,7 @@ templ AnalyticsContent(data AnalyticsPageData) { <legend>Ride type</legend> <div class="ride-type-options"> for _, opt := range rideTypeOptions { - <label class="ride-type-option"><input type="checkbox" name="ride_type" value={ string(opt) } checked?={ containsRideType(data.Filter.RideTypes, opt) }/><span>{ rideTypeLabels[opt] }</span></label> + <label class="ride-type-option"><input type="checkbox" name="ride_type" value={ string(opt) } checked?={ slices.Contains(data.Filter.RideTypes, opt) }/><span>{ rideTypeLabels[opt] }</span></label> } </div> </fieldset> |
