forked from tormoder/fit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_test.go
64 lines (53 loc) · 1.2 KB
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package fit_test
import (
"bytes"
"fmt"
"io/ioutil"
"path/filepath"
"github.com/tormoder/fit"
)
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.Type())
// 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
}