-
Notifications
You must be signed in to change notification settings - Fork 0
/
record.go
71 lines (61 loc) · 2.35 KB
/
record.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
65
66
67
68
69
70
71
package healthkit
import (
"encoding/xml"
"fmt"
"strings"
"time"
)
type Record struct {
XMLName xml.Name `xml:"Record"`
Type string `xml:"type,attr"`
Unit string `xml:"unit,attr"`
Value string `xml:"value,attr"`
SourceName string `xml:"sourceName,attr"`
SourceVersion string `xml:"sourceVersion,attr"`
Device string `xml:"device,attr"`
CreationDate string `xml:"creationDate,attr"`
StartDate string `xml:"startDate,attr"`
EndDate string `xml:"endDate,attr"`
MetadataEntry []*MetadataEntry `xml:"MetadataEntry"`
HeartRateVariabilityMetadataList []*HeartRateVariabilityMetadataList `xml:"HeartRateVariabilityMetadataList"`
}
type HeartRateVariabilityMetadataList struct {
XMLName xml.Name `xml:"HeartRateVariabilityMetadataList"`
InstantaneousBeatsPerMinute []*InstantaneousBeatsPerMinute `xml:"InstantaneousBeatsPerMinute"`
}
type InstantaneousBeatsPerMinute struct {
XMLName xml.Name `xml:"InstantaneousBeatsPerMinute"`
Bpm int `xml:"bpm,attr"`
Time string `xml:"time,attr"`
}
func (r *Record) String() string {
return fmt.Sprint(*r)
}
func (r *Record) DeviceMap() map[string]string {
res := make(map[string]string, 5)
s := strings.TrimPrefix(strings.TrimSuffix(r.Device, ">"), "<")
for _, part := range strings.Split(s, ", ") {
pair := strings.Split(part, ":")
if len(pair) != 2 {
continue
}
if len(pair[0]) == 0 || pair[0][0] == '<' {
continue
}
res[pair[0]] = pair[1]
}
return res
}
func (r *Record) CreationDateTime() time.Time {
t, _ := time.Parse(timeFormat, r.CreationDate)
return t
}
func (r *Record) StartDateTime() time.Time {
t, _ := time.Parse(timeFormat, r.StartDate)
return t
}
func (r *Record) EndDateTime() time.Time {
t, _ := time.Parse(timeFormat, r.EndDate)
return t
}
var _ Data = (*Record)(nil)