-
Notifications
You must be signed in to change notification settings - Fork 0
/
activity.go
125 lines (116 loc) · 4.92 KB
/
activity.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package main
import (
"encoding/json"
"image"
"time"
maps "github.com/flopp/go-staticmaps"
)
const (
MapWidth = 200
MapHeight = 200
)
type Activity struct {
Id int
Type int
Parent int
StartTime int
EndTime int
Calories float64
CurrentStatus int
ContentJSON string
PointsData string
Content *Content
Image image.Image
}
type Content struct {
TrackId int `json:"track_id"`
Calories int `json:"calorie"`
EndTime int `json:"end_time"`
StartTime int `json:"start_time"`
Distance int `json:"distance"`
SportType int `json:"sport_type"`
Duration int `json:"duration"`
PausedTime int `json:"paused _ime"`
UpdateCount int `json:"update_count"`
ChildList []int `json:"child_list"` // Array of int?
PauseInfo []int `json:"pause_info"` // Array of int?
ParentTrackId int `json:"parent_trackid"`
Speed float64 `json:"speed"`
Pace float64 `json:"pace"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
StepFrequency float64 `json:"step_freq"`
AverageHeartRate int `json:"avg_heart_rate"`
MaxHeartRate int `json:"max_heart_rate"`
MinHeartRate int `json:"min_heart_rate"`
AveragePace float64 `json:"total_pace"`
MaxPace float64 `json:"best_pace"`
MinPace float64 `json:"min_pace"`
AverageSpeed float64 `json:"total_speed"`
MaxSpeed float64 `json:"max_speed"`
MaxStepFrequency float64 `json:"max_step_freq"`
ClimbUp int `json:"climb_up"`
ClimbDown int `json:"climb_down"`
HighAltitude float64 `json:"high_altitude"`
LowAltitude float64 `json:"low_altitude"`
KmPerIndividual int `json:"km_per_individual"`
StepCount int `json:"step_count"`
AverageStride float64 `json:"avg_stride"`
TotalClimbDisacend int `json:"total_climb_disacend"`
MaxCadence int `json:"max_cadence"` // Bicycle cadence
AverageCadence int `json:"ave_cadence"`
DeviceType int `json:"device_type"`
DeviceSource int `json:"device_source"`
SummaryVersion int `json:"summary_version"`
DescendDistance int `json:"descend_distance"`
AscendTime int `json:"ascend_time"`
DescendTime int `json:"descend_time"`
Swolf int `json:"swolf"`
TotalStrokes int `json:"total_strokes"` // Swimming?
TotalTrips int `json:"total_trips"`
AverageStrokeSpeed int `json:"avg_stoke_speed"` // Typo?
MaxStrokeSpeed int `json:"max_stoke_speed"` // Typo?
AverageDistancePerStroke int `json:"avg_dis_per_stroke"`
SwimPoolLength int `json:"swim_pool_length"`
TeValue int `json:"te_value"`
SwimStyle int `json:"swim_style"`
Unit int `json:"unit"`
IntervalType int `json:"interval_type"`
DownhillNum int `json:"downhill_num"`
DownhillMaxAltitudeDescent int `json:"downhill_max_altitude_descend"`
Strokes int `json:"strokes"`
ForeHand int `json "fore_hand"` // Tennis
BackHand int `json:"back_hand"`
Serve int `json:"serve"`
SecHaldStartTime int `json:"sec_half_start_time"`
RopeSkippingTotalCounts int `json:"rope_skipping_total_counts"`
RopeSkippingMaxFrequency int `json:"rope_skipping_max_frequency"`
RopeSkippingAvgFrequency int `json:"rope_skiping_avg_frequency"`
RopeSkippingRestTime int `json:"rope_skipping_rest_time"`
WeatherInfo string `json:"weather_info"`
PersonalBest string `json:"pb"`
Marathon string `json:"marathon"`
Model string `json:"model"`
}
func (a *Activity) ParseContent() {
json.Unmarshal([]byte(a.ContentJSON), &(a.Content))
}
func (a *Activity) GenerateMap() {
ctx := maps.NewContext()
ctx.SetSize(MapWidth, MapHeight)
paths, err := maps.ParsePathString(a.PointsData)
if err != nil {
panic("Couldn't parse path for activity: " + err.Error())
}
path := paths[0]
path.Weight = 1.0
ctx.AddPath(path)
img, err := ctx.Render()
if err != nil {
panic(err)
}
a.Image = img
}
func (c *Content) StartTimeStr() string {
return time.Unix(0, int64(c.StartTime)*int64(time.Millisecond)).Format("January 2, 2006")
}