Skip to content

Commit

Permalink
fix: aggregator missing prefix start with Enhanced
Browse files Browse the repository at this point in the history
  • Loading branch information
muktihari committed Sep 8, 2024
1 parent af19a7e commit 51aafdc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/wasm/activity-service/aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ func Aggregate(dst, src interface{}) {
sum(dv.Field(i), sField) // TotalElapsedTime, TotalCycles, etc.
case strings.HasPrefix(f.Name, "Num") && strings.HasSuffix(f.Name, "s"):
sum(dv.Field(i), sField) // NumSessions, NumLaps, NumSplits, etc.
case strings.HasPrefix(f.Name, "Max"):
max(dv.Field(i), sField) // MaxHeartRate, MaxCadence, etc.
case strings.HasPrefix(f.Name, "Min"):
min(dv.Field(i), sField) // MinHeartRate, MinCadence, etc.
case strings.HasPrefix(f.Name, "Avg"):
avg(dv.Field(i), sField) // AvgHeartRate, AvgCadence, etc.
case strings.HasPrefix(f.Name, "Max") || strings.HasPrefix(f.Name, "EnhancedMax"):
max(dv.Field(i), sField) // MaxHeartRate, MaxCadence, EnhancedMaxRespirationRate, etc.
case strings.HasPrefix(f.Name, "Min") || strings.HasPrefix(f.Name, "EnhancedMin"):
min(dv.Field(i), sField) // MinHeartRate, MinCadence, EnhancedAltitude etc.
case strings.HasPrefix(f.Name, "Avg") || strings.HasPrefix(f.Name, "EnhancedAvg"):
avg(dv.Field(i), sField) // AvgHeartRate, AvgCadence, EnhancedAvgSpeed etc.
default:
fill(dv.Field(i), sField) // Timestamp, Sport, Event, etc.
}
Expand Down
18 changes: 18 additions & 0 deletions src/wasm/activity-service/aggregator/aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,36 @@ func TestAggregate(t *testing.T) {
src: mesgdef.NewSession(nil).SetMaxAltitude(2000),
exp: mesgdef.NewSession(nil).SetMaxAltitude(2000),
},
{
name: "EnhancedMax",
dst: mesgdef.NewSession(nil).SetEnhancedMaxAltitude(1000),
src: mesgdef.NewSession(nil).SetEnhancedMaxAltitude(2000),
exp: mesgdef.NewSession(nil).SetEnhancedMaxAltitude(2000),
},
{
name: "Min",
dst: mesgdef.NewSession(nil).SetMinHeartRate(60),
src: mesgdef.NewSession(nil).SetMinHeartRate(80),
exp: mesgdef.NewSession(nil).SetMinHeartRate(60),
},
{
name: "EnhancedMin",
dst: mesgdef.NewSession(nil).SetEnhancedMinAltitude(60),
src: mesgdef.NewSession(nil).SetEnhancedMinAltitude(80),
exp: mesgdef.NewSession(nil).SetEnhancedMinAltitude(60),
},
{
name: "Avg",
dst: mesgdef.NewSession(nil).SetAvgTemperature(20),
src: mesgdef.NewSession(nil).SetAvgTemperature(22),
exp: mesgdef.NewSession(nil).SetAvgTemperature(21),
},
{
name: "EnhancedAvg",
dst: mesgdef.NewSession(nil).SetEnhancedAvgAltitude(60),
src: mesgdef.NewSession(nil).SetEnhancedAvgAltitude(80),
exp: mesgdef.NewSession(nil).SetEnhancedAvgAltitude(70),
},
{
name: "Fill dst invalid",
dst: mesgdef.NewSession(nil),
Expand Down

0 comments on commit 51aafdc

Please sign in to comment.