Skip to content

Commit

Permalink
fix(data): Correct gear type identification for running shoes in Stra…
Browse files Browse the repository at this point in the history
…va API

- Added a workaround for a bug in the Strava API that incorrectly returns all gear as bicycles.
- Identified running shoes by checking if the gear ID starts with "g" and set the frame type to "Shoes".
- Updated the `updateGears` function to apply this workaround and correctly set the gear type.

Signed-off-by: Bahattin Çiniç <[email protected]>
  • Loading branch information
bahattincinic committed Jun 8, 2024
1 parent 1e5697b commit 1edd1c3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
11 changes: 10 additions & 1 deletion importer/importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package importer
import (
"context"
"encoding/json"
"strings"

"github.com/bahattincinic/fitwave/config"
"github.com/bahattincinic/fitwave/database"
Expand Down Expand Up @@ -36,14 +37,22 @@ func (im *Importer) updateGears(tx *gorm.DB, gears []client.GearDetailed, user *
var rows []models.Gear

for _, gear := range gears {
frameType := gear.FrameType.String()

// There is a bug in the Strava API that incorrectly returns all gear as bicycles.
// We can identify running shoes by checking if the gear ID starts with "g".
if strings.HasPrefix(gear.Id, "g") {
frameType = "Shoes"
}

rows = append(rows, models.Gear{
Id: gear.Id,
Name: gear.Name,
Primary: gear.Primary,
Distance: gear.Distance,
BrandName: gear.BrandName,
ModelName: gear.ModelName,
FrameType: gear.FrameType.String(),
Type: frameType,
Description: gear.Description,
AthleteID: user.Athlete.Id,
})
Expand Down
4 changes: 2 additions & 2 deletions models/gear.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ type Gear struct {
Distance float64 `json:"distance"`
BrandName string `json:"brand_name"`
ModelName string `json:"model_name"`
FrameType string `json:"frame_type"`
Type string `json:"type"`
Description string `json:"description"`
AthleteID int64
Athlete Athlete `gorm:"foreignkey:AthleteID" json:"athlete"`
Athlete *Athlete `gorm:"foreignkey:AthleteID" json:"athlete"`
}
8 changes: 4 additions & 4 deletions ui/src/pages/AthletesPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
@rowSelect="onRowSelect"
>
<Column field="id" header="ID"></Column>
<Column field="firstname" header="First Name"></Column>
<Column field="lastname" header="Last Name"></Column>
<Column field="country" header="Country"></Column>
<Column field="city" header="City"></Column>
<Column sortable field="firstname" header="First Name"></Column>
<Column sortable field="lastname" header="Last Name"></Column>
<Column sortable field="country" header="Country"></Column>
<Column sortable field="city" header="City"></Column>
<template #empty> No records found </template>
</DataTable>

Expand Down
9 changes: 5 additions & 4 deletions ui/src/pages/GearsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
selectionMode="single"
@rowSelect="onRowSelect"
>
<Column field="id" header="ID"></Column>
<Column field="name" header="Name"></Column>
<Column :field="formatDistance" header="Distance"></Column>
<Column :field="athleteName" header="Athlete"></Column>
<Column sortable field="id" header="ID"></Column>
<Column sortable field="name" header="Name"></Column>
<Column sortable field="type" header="Type"></Column>
<Column sortable :field="formatDistance" header="Distance"></Column>
<Column sortable :field="athleteName" header="Athlete"></Column>
<template #empty> No records found </template>
</DataTable>

Expand Down

0 comments on commit 1edd1c3

Please sign in to comment.