Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activity can't find WeatherConditions #542

Open
180909 opened this issue Mar 20, 2025 · 1 comment
Open

Activity can't find WeatherConditions #542

180909 opened this issue Mar 20, 2025 · 1 comment

Comments

@180909
Copy link

180909 commented Mar 20, 2025

Activity can't find WeatherConditions

@muktihari
Copy link
Owner

@180909 Do you mean this? What manufacturer+devices produces WeatherConditions in their activity file?

type Activity struct {
FileId mesgdef.FileId // required fields: type, manufacturer, product, serial_number, time_created
// Developer Data Lookup
DeveloperDataIds []*mesgdef.DeveloperDataId
FieldDescriptions []*mesgdef.FieldDescription
// Required Messages
Activity *mesgdef.Activity // required fields: timestamp, num_sessions, type, event, event_type
Sessions []*mesgdef.Session // required fields: timestamp, start_time, total_elapsed_time, sport, event, event_type
Laps []*mesgdef.Lap // required fields: timestamp, event, event_type
Records []*mesgdef.Record // required fields: timestamp
// Optional Messages
UserProfile *mesgdef.UserProfile
DeviceInfos []*mesgdef.DeviceInfo // required fields: timestamp
Events []*mesgdef.Event
Lengths []*mesgdef.Length // required fields: timestamp, event, event_type
SegmentLaps []*mesgdef.SegmentLap
ZonesTargets []*mesgdef.ZonesTarget
Workouts []*mesgdef.Workout
WorkoutSteps []*mesgdef.WorkoutStep
HRs []*mesgdef.Hr
HRVs []*mesgdef.Hrv // required fields: time
GpsMetadatas []*mesgdef.GpsMetadata
TimeInZones []*mesgdef.TimeInZone
Splits []*mesgdef.Split
SplitSummaries []*mesgdef.SplitSummary // entries must be unique within each split_type
Sports []*mesgdef.Sport
// Messages not related to Activity
UnrelatedMessages []proto.Message
}

Actually, this library is composable, it means you can create your own struct and still be able to use this library. Because if we try to guess which messages should be added to filedef.Activity, it will be plenty to choose, different manufacturer may use different messages.

Please see this guide on how to define your own custom file type: https://github.com/muktihari/fit/blob/master/docs/usage.md#using-your-own-custom-file-types

Alternatively, you can embed existing filedef.Activity to your defined struct and add WeatherConditions if you want it that way, choose what works for you:

// Activity is an user-defined activity file.
type Activity struct {
	filedef.Activity  // <- Struct-embedding, so we can use its fields as our own.
	WeatherConditions []*mesgdef.WeatherConditions
}

func (a *Activity) Add(mesg proto.Message) {
	switch mesg.Num {
	case mesgnum.WeatherConditions:
		a.WeatherConditions = append(a.WeatherConditions, mesgdef.NewWeatherConditions(&mesg))
	default:
		a.Activity.Add(mesg) // Pass the other messages to filedef.Activity
	}
}

func (a *Activity) ToFIT(options *mesgdef.Options) proto.FIT {
	for _, v := range a.WeatherConditions {
		a.Activity.Add(v.ToMesg(options)) // <- Put messages to (filedef.Activity).UnrelatedMessages
	}
	return a.Activity.ToFIT(options) // <- Let filedef.Activity to convert all messages into proto.FIT
}

I hope it help, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants