Skip to content

Commit 801454e

Browse files
authored
fix: simplify and ensure correctness of data aggregation (#112)
* chore: bump fit sdk version * chore: copy aggregator from github.com/muktihari/fit * fix: simplify and ensure correctness of data aggregation * bump fit sdk version to v0.21.3 * go mod tidy * fix: aggregator missing prefix start with Enhanced * chore: clean up aggregator code documentation * fix: add missing time gap from the previous changes when combining * bump: fit sdk to v0.21.5
1 parent 630c8a8 commit 801454e

File tree

12 files changed

+1501
-360
lines changed

12 files changed

+1501
-360
lines changed

NOTICE

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This project includes code originally licensed under the BSD-3-Clause license.
2+
Original copyright notice and license text are retained in the included code files.
3+
- src/wasm/activity-service/aggregator

src/wasm/activity-service/activity/fit/fit.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/muktihari/fit/profile/typedef"
3131
"github.com/muktihari/fit/proto"
3232
"github.com/openivity/activity-service/activity"
33+
"github.com/openivity/activity-service/aggregator"
3334
"github.com/openivity/activity-service/mem"
3435
"github.com/openivity/activity-service/service"
3536
"golang.org/x/exp/slices"
@@ -243,11 +244,11 @@ func (s *DecodeEncoder) recalculateSummary(ses *activity.Session) {
243244
continue
244245
}
245246
lapFromRecords := activity.NewLapFromRecords(records[:pos], ses.Sport)
246-
lap.ReplaceValues(&lapFromRecords)
247+
aggregator.Fill(lap.Lap, lapFromRecords.Lap)
247248
records = records[pos:]
248249
}
249250
sesFromLaps := activity.NewSessionFromLaps(ses.Laps)
250-
ses.ReplaceValues(&sesFromLaps)
251+
aggregator.Fill(ses, sesFromLaps.Session)
251252
ses.Summarize()
252253
}
253254

src/wasm/activity-service/activity/lap.go

+2-93
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/muktihari/fit/profile/basetype"
2424
"github.com/muktihari/fit/profile/mesgdef"
2525
"github.com/muktihari/fit/profile/typedef"
26+
"github.com/openivity/activity-service/aggregator"
2627
"github.com/openivity/activity-service/strutils"
2728
)
2829

@@ -183,31 +184,7 @@ func NewLapFromRecords(records []Record, sport typedef.Sport) Lap {
183184
// NewLapFromSession creates new lap from a session.
184185
func NewLapFromSession(session *Session) Lap {
185186
lap := CreateLap(nil)
186-
187-
lap.Sport = session.Sport
188-
lap.SubSport = session.SubSport
189-
lap.Timestamp = session.Timestamp
190-
lap.StartTime = session.StartTime
191-
lap.TotalMovingTime = session.TotalMovingTime
192-
lap.TotalElapsedTime = session.TotalElapsedTime
193-
lap.TotalTimerTime = session.TotalTimerTime
194-
lap.TotalDistance = session.TotalDistance
195-
lap.TotalAscent = session.TotalAscent
196-
lap.TotalDescent = session.TotalDescent
197-
lap.TotalCalories = session.TotalCalories
198-
lap.AvgSpeed = session.AvgSpeed
199-
lap.MaxSpeed = session.MaxSpeed
200-
lap.AvgHeartRate = session.AvgHeartRate
201-
lap.MaxHeartRate = session.MaxHeartRate
202-
lap.AvgCadence = session.AvgCadence
203-
lap.MaxCadence = session.MaxCadence
204-
lap.AvgPower = session.AvgPower
205-
lap.MaxPower = session.MaxPower
206-
lap.AvgTemperature = session.AvgTemperature
207-
lap.MaxTemperature = session.MaxTemperature
208-
lap.AvgAltitude = session.AvgAltitude
209-
lap.MaxAltitude = session.MaxAltitude
210-
187+
aggregator.Replace(lap.Lap, session.Session)
211188
return lap
212189
}
213190

@@ -216,74 +193,6 @@ func (l *Lap) IsBelongToThisLap(t time.Time) bool {
216193
return isBelong(t, l.StartTime, l.EndTime())
217194
}
218195

219-
// ReplaceValues replaces values with the corresponding values in the given lap.
220-
func (l *Lap) ReplaceValues(lap *Lap) {
221-
if l == nil || lap == nil {
222-
return
223-
}
224-
225-
if !lap.StartTime.IsZero() {
226-
l.StartTime = lap.StartTime
227-
}
228-
if lap.TotalElapsedTime != basetype.Uint32Invalid {
229-
l.TotalElapsedTime = lap.TotalElapsedTime
230-
}
231-
if lap.TotalMovingTime != basetype.Uint32Invalid {
232-
l.TotalMovingTime = lap.TotalMovingTime
233-
}
234-
if lap.TotalTimerTime != basetype.Uint32Invalid {
235-
l.TotalTimerTime = lap.TotalTimerTime
236-
}
237-
if lap.TotalDistance != basetype.Uint32Invalid {
238-
l.TotalDistance = lap.TotalDistance
239-
}
240-
if lap.TotalCalories != basetype.Uint16Invalid {
241-
l.TotalCalories = lap.TotalCalories
242-
}
243-
if lap.TotalAscent != basetype.Uint16Invalid {
244-
l.TotalAscent = lap.TotalAscent
245-
}
246-
if lap.TotalDescent != basetype.Uint16Invalid {
247-
l.TotalDescent = lap.TotalDescent
248-
}
249-
if lap.AvgSpeed != basetype.Uint16Invalid {
250-
l.AvgSpeed = lap.AvgSpeed
251-
}
252-
if lap.MaxSpeed != basetype.Uint16Invalid {
253-
l.MaxSpeed = lap.MaxSpeed
254-
}
255-
if lap.AvgHeartRate != basetype.Uint8Invalid {
256-
l.AvgHeartRate = lap.AvgHeartRate
257-
}
258-
if lap.MaxHeartRate != basetype.Uint8Invalid {
259-
l.MaxHeartRate = lap.MaxHeartRate
260-
}
261-
if lap.AvgCadence != basetype.Uint8Invalid {
262-
l.AvgCadence = lap.AvgCadence
263-
}
264-
if lap.MaxCadence != basetype.Uint8Invalid {
265-
l.MaxCadence = lap.MaxCadence
266-
}
267-
if lap.AvgPower != basetype.Uint16Invalid {
268-
l.AvgPower = lap.AvgPower
269-
}
270-
if lap.MaxPower != basetype.Uint16Invalid {
271-
l.MaxPower = lap.MaxPower
272-
}
273-
if lap.AvgTemperature != basetype.Sint8Invalid {
274-
l.AvgTemperature = lap.AvgTemperature
275-
}
276-
if lap.MaxTemperature != basetype.Sint8Invalid {
277-
l.MaxTemperature = lap.MaxTemperature
278-
}
279-
if lap.AvgAltitude != basetype.Uint16Invalid {
280-
l.AvgAltitude = lap.AvgAltitude
281-
}
282-
if lap.MaxAltitude != basetype.Uint16Invalid {
283-
l.MaxAltitude = lap.MaxAltitude
284-
}
285-
}
286-
287196
// MarshalAppendJSON appends the JSON format encoding of Lap to b, returning the result.
288197
func (l *Lap) MarshalAppendJSON(b []byte) []byte {
289198
b = append(b, '{')

0 commit comments

Comments
 (0)