Skip to content

Commit

Permalink
bump github.com/muktihari/fit version from v0.11.1 to v0.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
muktihari committed Apr 5, 2024
1 parent d4bb537 commit 4bfff2b
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 177 deletions.
8 changes: 4 additions & 4 deletions src/wasm/activity-service/activity/fit/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ func createActivityMesg(timestamp time.Time, timezone int, sessionCount uint16)
mesg := factory.CreateMesgOnly(mesgnum.Activity)

activityTypeField := factory.CreateField(mesgnum.Activity, fieldnum.ActivityType)
activityTypeField.Value = uint8(typedef.ActivityAutoMultiSport)
activityTypeField.Value = proto.Uint8(uint8(typedef.ActivityAutoMultiSport))
mesg.Fields = append(mesg.Fields, activityTypeField)

timestampField := factory.CreateField(mesgnum.Activity, fieldnum.ActivityTimestamp)
timestampField.Value = datetime.ToUint32(timestamp)
timestampField.Value = proto.Uint32(datetime.ToUint32(timestamp))
mesg.Fields = append(mesg.Fields, timestampField)

localTimestamp := datetime.ToLocalTime(timestampField.Value, timezone)
localTimestampField := factory.CreateField(mesgnum.Activity, fieldnum.ActivityLocalTimestamp)
localTimestampField.Value = datetime.ToUint32(localTimestamp)
localTimestampField.Value = proto.Uint32(datetime.ToUint32(localTimestamp))
mesg.Fields = append(mesg.Fields, localTimestampField)

sessionCountField := factory.CreateField(mesgnum.Activity, fieldnum.ActivityNumSessions)
sessionCountField.Value = sessionCount
sessionCountField.Value = proto.Uint16(sessionCount)

return mesg
}
18 changes: 6 additions & 12 deletions src/wasm/activity-service/activity/fit/creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,10 @@ func NewCreator(mesg proto.Message) activity.Creator {

switch field.Num {
case fieldnum.FileIdManufacturer:
manufacturer, ok := field.Value.(uint16)
if !ok {
continue
}
manufacturer := field.Value.Uint16()
m.Manufacturer = &manufacturer
case fieldnum.FileIdProduct:
product, ok := field.Value.(uint16)
if !ok {
continue
}
product := field.Value.Uint16()
m.Product = &product
case fieldnum.FileIdTimeCreated:
m.TimeCreated = datetime.ToTime(field.Value)
Expand All @@ -44,19 +38,19 @@ func convertCreatorToMesg(cre *activity.Creator) proto.Message {
mesg := factory.CreateMesgOnly(mesgnum.FileId)

fileTypeField := factory.CreateField(mesgnum.FileId, fieldnum.FileIdType)
fileTypeField.Value = uint8(typedef.FileActivity)
fileTypeField.Value = proto.Uint8(uint8(typedef.FileActivity))
mesg.Fields = append(mesg.Fields, fileTypeField)

manufacturerField := factory.CreateField(mesgnum.FileId, fieldnum.FileIdManufacturer)
manufacturerField.Value = uint16(*cre.Manufacturer)
manufacturerField.Value = proto.Uint16(*cre.Manufacturer)
mesg.Fields = append(mesg.Fields, manufacturerField)

productField := factory.CreateField(mesgnum.FileId, fieldnum.FileIdProduct)
productField.Value = uint16(*cre.Product)
productField.Value = proto.Uint16(*cre.Product)
mesg.Fields = append(mesg.Fields, productField)

timeCreatedField := factory.CreateField(mesgnum.FileId, fieldnum.FileIdTimeCreated)
timeCreatedField.Value = datetime.ToUint32(cre.TimeCreated)
timeCreatedField.Value = proto.Uint32(datetime.ToUint32(cre.TimeCreated))
mesg.Fields = append(mesg.Fields, timeCreatedField)

return mesg
Expand Down
102 changes: 51 additions & 51 deletions src/wasm/activity-service/activity/fit/lap.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,88 +25,88 @@ func NewLap(mesg proto.Message) *activity.Lap {
case fieldnum.LapStartTime:
lap.StartTime = datetime.ToTime(field.Value)
case fieldnum.LapTotalMovingTime:
totalMovingTime, ok := field.Value.(uint32)
if !ok || totalMovingTime == basetype.Uint32Invalid {
totalMovingTime := field.Value.Uint32()
if totalMovingTime == basetype.Uint32Invalid {
continue
}
lap.TotalMovingTime = float64(totalMovingTime) / 1000
case fieldnum.LapTotalElapsedTime:
totalElapsedTime, ok := field.Value.(uint32)
if !ok || totalElapsedTime == basetype.Uint32Invalid {
totalElapsedTime := field.Value.Uint32()
if totalElapsedTime == basetype.Uint32Invalid {
continue
}
lap.TotalElapsedTime = float64(totalElapsedTime) / 1000
case fieldnum.LapTotalDistance:
totalDistance, ok := field.Value.(uint32)
if !ok || totalDistance == basetype.Uint32Invalid {
totalDistance := field.Value.Uint32()
if totalDistance == basetype.Uint32Invalid {
continue
}
lap.TotalDistance = float64(totalDistance) / 100
case fieldnum.LapTotalAscent:
totalAscent, ok := field.Value.(uint16)
if !ok || totalAscent == basetype.Uint16Invalid {
totalAscent := field.Value.Uint16()
if totalAscent == basetype.Uint16Invalid {
continue
}
lap.TotalAscent = totalAscent
case fieldnum.LapTotalDescent:
totalDescent, ok := field.Value.(uint16)
if !ok || totalDescent == basetype.Uint16Invalid {
totalDescent := field.Value.Uint16()
if totalDescent == basetype.Uint16Invalid {
continue
}
lap.TotalDescent = totalDescent
case fieldnum.LapTotalCalories:
totalCalories, ok := field.Value.(uint16)
if !ok || totalCalories == basetype.Uint16Invalid {
totalCalories := field.Value.Uint16()
if totalCalories == basetype.Uint16Invalid {
continue
}
lap.TotalCalories = totalCalories
case fieldnum.LapAvgSpeed:
avgSpeed, ok := field.Value.(uint16)
if !ok || avgSpeed == basetype.Uint16Invalid {
avgSpeed := field.Value.Uint16()
if avgSpeed == basetype.Uint16Invalid {
continue
}
fAvgSpeed := float64(avgSpeed) / 1000
lap.AvgSpeed = &fAvgSpeed
case fieldnum.LapMaxSpeed:
maxSpeed, ok := field.Value.(uint16)
if !ok || maxSpeed == basetype.Uint16Invalid {
maxSpeed := field.Value.Uint16()
if maxSpeed == basetype.Uint16Invalid {
continue
}
fMaxSpeed := float64(maxSpeed) / 1000
lap.MaxSpeed = &fMaxSpeed
case fieldnum.LapAvgCadence:
avgCadence, ok := field.Value.(uint8)
if !ok || avgCadence == basetype.Uint8Invalid {
avgCadence := field.Value.Uint8()
if avgCadence == basetype.Uint8Invalid {
continue
}
lap.AvgCadence = &avgCadence
case fieldnum.LapMaxCadence:
maxCadence, ok := field.Value.(uint8)
if !ok || maxCadence == basetype.Uint8Invalid {
maxCadence := field.Value.Uint8()
if maxCadence == basetype.Uint8Invalid {
continue
}
lap.MaxCadence = &maxCadence
case fieldnum.LapAvgHeartRate:
avgHeartRate, ok := field.Value.(uint8)
if !ok || avgHeartRate == basetype.Uint8Invalid {
avgHeartRate := field.Value.Uint8()
if avgHeartRate == basetype.Uint8Invalid {
continue
}
lap.AvgHeartRate = &avgHeartRate
case fieldnum.LapMaxHeartRate:
maxHeartRate, ok := field.Value.(uint8)
if !ok || maxHeartRate == basetype.Uint8Invalid {
maxHeartRate := field.Value.Uint8()
if maxHeartRate == basetype.Uint8Invalid {
continue
}
lap.MaxHeartRate = &maxHeartRate
case fieldnum.LapAvgPower:
avgPower, ok := field.Value.(uint16)
if !ok || avgPower == basetype.Uint16Invalid {
avgPower := field.Value.Uint16()
if avgPower == basetype.Uint16Invalid {
continue
}
lap.AvgPower = &avgPower
case fieldnum.LapMaxPower:
maxPower, ok := field.Value.(uint16)
if !ok || maxPower == basetype.Uint16Invalid {
maxPower := field.Value.Uint16()
if maxPower == basetype.Uint16Invalid {
continue
}
lap.MaxPower = &maxPower
Expand All @@ -121,12 +121,12 @@ func convertLapToMesg(lap *activity.Lap) proto.Message {

if !lap.Timestamp.IsZero() {
field := factory.CreateField(mesgnum.Lap, fieldnum.LapTimestamp)
field.Value = datetime.ToUint32(lap.Timestamp)
field.Value = proto.Uint32(datetime.ToUint32(lap.Timestamp))
mesg.Fields = append(mesg.Fields, field)
}
if !lap.StartTime.IsZero() {
field := factory.CreateField(mesgnum.Lap, fieldnum.LapStartTime)
field.Value = datetime.ToUint32(lap.StartTime)
field.Value = proto.Uint32(datetime.ToUint32(lap.StartTime))
mesg.Fields = append(mesg.Fields, field)
}
if lap.Sport != "" {
Expand All @@ -135,17 +135,17 @@ func convertLapToMesg(lap *activity.Lap) proto.Message {
sport = typedef.SportGeneric
}
field := factory.CreateField(mesgnum.Lap, fieldnum.LapSport)
field.Value = uint8(sport)
field.Value = proto.Uint8(uint8(sport))
mesg.Fields = append(mesg.Fields, field)
}
if lap.TotalMovingTime != 0 {
field := factory.CreateField(mesgnum.Lap, fieldnum.LapTotalMovingTime)
field.Value = scaleoffset.DiscardAny(lap.TotalMovingTime, field.Type.BaseType(), field.Scale, field.Offset)
field.Value = scaleoffset.DiscardValue(lap.TotalMovingTime, field.Type.BaseType(), field.Scale, field.Offset)
mesg.Fields = append(mesg.Fields, field)
}
if lap.TotalElapsedTime != 0 {
field := factory.CreateField(mesgnum.Lap, fieldnum.LapTotalElapsedTime)
field.Value = scaleoffset.DiscardAny(lap.TotalElapsedTime, field.Type.BaseType(), field.Scale, field.Offset)
field.Value = scaleoffset.DiscardValue(lap.TotalElapsedTime, field.Type.BaseType(), field.Scale, field.Offset)
mesg.Fields = append(mesg.Fields, field)

totalTimerTimeField := factory.CreateField(mesgnum.Lap, fieldnum.LapTotalTimerTime)
Expand All @@ -154,91 +154,91 @@ func convertLapToMesg(lap *activity.Lap) proto.Message {
}
if lap.TotalDistance != 0 {
field := factory.CreateField(mesgnum.Lap, fieldnum.LapTotalDistance)
field.Value = scaleoffset.DiscardAny(lap.TotalDistance, field.Type.BaseType(), field.Scale, field.Offset)
field.Value = scaleoffset.DiscardValue(lap.TotalDistance, field.Type.BaseType(), field.Scale, field.Offset)
mesg.Fields = append(mesg.Fields, field)
}
if lap.TotalAscent != 0 {
field := factory.CreateField(mesgnum.Lap, fieldnum.LapTotalAscent)
field.Value = lap.TotalAscent
field.Value = proto.Uint16(lap.TotalAscent)
mesg.Fields = append(mesg.Fields, field)
}
if lap.TotalDescent != 0 {
field := factory.CreateField(mesgnum.Lap, fieldnum.LapTotalDescent)
field.Value = lap.TotalDescent
field.Value = proto.Uint16(lap.TotalDescent)
mesg.Fields = append(mesg.Fields, field)
}
if lap.TotalCalories != 0 {
field := factory.CreateField(mesgnum.Lap, fieldnum.LapTotalCalories)
field.Value = lap.TotalCalories
field.Value = proto.Uint16(lap.TotalCalories)
mesg.Fields = append(mesg.Fields, field)
}
if lap.AvgSpeed != nil {
field := factory.CreateField(mesgnum.Lap, fieldnum.LapAvgSpeed)
field.Value = scaleoffset.DiscardAny(*lap.AvgSpeed, field.Type.BaseType(), field.Scale, field.Offset)
field.Value = scaleoffset.DiscardValue(*lap.AvgSpeed, field.Type.BaseType(), field.Scale, field.Offset)
mesg.Fields = append(mesg.Fields, field)
}
if lap.MaxSpeed != nil {
field := factory.CreateField(mesgnum.Lap, fieldnum.LapMaxSpeed)
field.Value = scaleoffset.DiscardAny(*lap.MaxSpeed, field.Type.BaseType(), field.Scale, field.Offset)
field.Value = scaleoffset.DiscardValue(*lap.MaxSpeed, field.Type.BaseType(), field.Scale, field.Offset)
mesg.Fields = append(mesg.Fields, field)
}
if lap.AvgHeartRate != nil {
field := factory.CreateField(mesgnum.Lap, fieldnum.LapAvgHeartRate)
field.Value = *lap.AvgHeartRate
field.Value = proto.Uint8(*lap.AvgHeartRate)
mesg.Fields = append(mesg.Fields, field)
}
if lap.MaxHeartRate != nil {
field := factory.CreateField(mesgnum.Lap, fieldnum.LapMaxHeartRate)
field.Value = *lap.MaxHeartRate
field.Value = proto.Uint8(*lap.MaxHeartRate)
mesg.Fields = append(mesg.Fields, field)
}
if lap.AvgCadence != nil {
field := factory.CreateField(mesgnum.Lap, fieldnum.LapAvgCadence)
field.Value = *lap.AvgCadence
field.Value = proto.Uint8(*lap.AvgCadence)
mesg.Fields = append(mesg.Fields, field)
}
if lap.MaxCadence != nil {
field := factory.CreateField(mesgnum.Lap, fieldnum.LapMaxCadence)
field.Value = *lap.MaxCadence
field.Value = proto.Uint8(*lap.MaxCadence)
mesg.Fields = append(mesg.Fields, field)
}
if lap.AvgPower != nil {
field := factory.CreateField(mesgnum.Lap, fieldnum.LapAvgPower)
field.Value = *lap.AvgPower
field.Value = proto.Uint16(*lap.AvgPower)
mesg.Fields = append(mesg.Fields, field)
}
if lap.MaxPower != nil {
field := factory.CreateField(mesgnum.Lap, fieldnum.LapMaxPower)
field.Value = *lap.MaxPower
field.Value = proto.Uint16(*lap.MaxPower)
mesg.Fields = append(mesg.Fields, field)
}
if lap.AvgTemperature != nil {
field := factory.CreateField(mesgnum.Lap, fieldnum.LapAvgTemperature)
field.Value = *lap.AvgTemperature
field.Value = proto.Int8(*lap.AvgTemperature)
mesg.Fields = append(mesg.Fields, field)
}
if lap.MaxTemperature != nil {
field := factory.CreateField(mesgnum.Lap, fieldnum.LapMaxTemperature)
field.Value = *lap.MaxTemperature
field.Value = proto.Int8(*lap.MaxTemperature)
mesg.Fields = append(mesg.Fields, field)
}
if lap.AvgAltitude != nil {
field := factory.CreateField(mesgnum.Lap, fieldnum.LapAvgAltitude)
field.Value = scaleoffset.DiscardAny(*lap.AvgAltitude, field.Type.BaseType(), field.Scale, field.Offset)
field.Value = scaleoffset.DiscardValue(*lap.AvgAltitude, field.Type.BaseType(), field.Scale, field.Offset)
mesg.Fields = append(mesg.Fields, field)
}
if lap.MaxAltitude != nil {
field := factory.CreateField(mesgnum.Lap, fieldnum.LapMaxAltitude)
field.Value = scaleoffset.DiscardAny(*lap.MaxAltitude, field.Type.BaseType(), field.Scale, field.Offset)
field.Value = scaleoffset.DiscardValue(*lap.MaxAltitude, field.Type.BaseType(), field.Scale, field.Offset)
mesg.Fields = append(mesg.Fields, field)
}

eventField := factory.CreateField(mesgnum.Lap, fieldnum.LapEvent)
eventField.Value = uint8(typedef.EventLap)
eventField.Value = proto.Uint8(uint8(typedef.EventLap))
mesg.Fields = append(mesg.Fields, eventField)

eventTypeField := factory.CreateField(mesgnum.Lap, fieldnum.LapEventType)
eventTypeField.Value = uint8(typedef.EventTypeStop)
eventTypeField.Value = proto.Uint8(uint8(typedef.EventTypeStop))
mesg.Fields = append(mesg.Fields, eventTypeField)

return mesg
Expand Down
Loading

0 comments on commit 4bfff2b

Please sign in to comment.