Esempio n. 1
0
func Example() {
	// Read our FIT test file data
	testFile := filepath.Join("testdata", "fitsdk", "Activity.fit")
	testData, err := ioutil.ReadFile(testFile)
	if err != nil {
		fmt.Println(err)
		return
	}

	// Decode the FIT file data
	fit, err := fit.Decode(bytes.NewReader(testData))
	if err != nil {
		fmt.Println(err)
		return
	}

	// Inspect the TimeCreated field in the FileId message
	fmt.Println(fit.FileId.TimeCreated)

	// Inspect the dynamic Product field in the FileId message
	fmt.Println(fit.FileId.GetProduct())

	// Inspect the FIT file type
	fmt.Println(fit.FileType())

	// Get the actual activity
	activity, err := fit.Activity()
	if err != nil {
		fmt.Println(err)
		return
	}

	// Print the latitude and longitude of the first Record message
	for _, record := range activity.Records {
		fmt.Println(record.PositionLat)
		fmt.Println(record.PositionLong)
		break
	}

	// Print the sport of the first Session message
	for _, session := range activity.Sessions {
		fmt.Println(session.Sport)
		break
	}

	// Output:
	// 2012-04-09 21:22:26 +0000 UTC
	// Hrm1
	// Activity
	// 41.51393
	// -73.14859
	// Running
}
Esempio n. 2
0
func ExampleSetLocalTimeZone() {
	testFile := filepath.Join("../testdata", "fitsdk", "Activity.fit")
	testData, err := ioutil.ReadFile(testFile)
	if err != nil {
		fmt.Println(err)
		return
	}

	fit, err := fit.Decode(bytes.NewReader(testData))
	if err != nil {
		fmt.Println(err)
		return
	}

	activity, err := fit.Activity()
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println("Post decode & pre SetLocalTimezone:")
	fmt.Println(activity.Activity.LocalTimestamp)
	err = timeutil.SetLocalTimeZone(fit)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println("Post SetLocalTimezone:")
	fmt.Println(activity.Activity.LocalTimestamp)

	// Output:
	// Post decode & pre SetLocalTimezone:
	// 2012-04-09 17:24:51 -0400 FITLOCAL
	// Post SetLocalTimezone:
	// 2012-04-09 17:24:51 -0400 EDT
}