-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtask.go
More file actions
158 lines (131 loc) · 3.67 KB
/
task.go
File metadata and controls
158 lines (131 loc) · 3.67 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package xctrack
import (
"fmt"
"regexp"
"strconv"
)
// Constants.
const (
Extension = ".xctsk"
MIMEType = "application/xctsk"
Version = 1
)
var timeRegexp = regexp.MustCompile(`\A"(\d\d):(\d\d):(\d\d)Z"\z`)
// An Direction is a direction.
type Direction string
// Directions.
const (
DirectionEnter Direction = "ENTER"
DirectionExit Direction = "EXIT"
)
// An EarthModel is an Earth model.
type EarthModel string
// Earth models.
const (
EarthModelWGS84 EarthModel = "WGS84"
EarthModelFAISphere EarthModel = "FAI_SPHERE"
)
// A Goal is a goal.
type Goal struct {
Type GoalType `json:"type,omitempty"`
Deadline *TimeOfDay `json:"deadline,omitempty"`
}
// A GoalType is a goal type.
type GoalType string
// Goal types.
const (
GoalTypeCylinder GoalType = "CYLINDER"
GoalTypeLine GoalType = "LINE"
)
// An SSS is a start of speed section.
type SSS struct {
Type SSSType `json:"type"`
Direction Direction `json:"direction"`
TimeGates []*TimeOfDay `json:"timeGates,omitempty"`
}
// An SSSType is a start of speed section type.
type SSSType string
// Start of speed section types.
const (
SSSTypeRace SSSType = "RACE"
SSSTypeElapsedTime SSSType = "ELAPSED-TIME"
)
// A Takeoff is a takeoff.
type Takeoff struct {
TimeOpen *TimeOfDay `json:"timeOpen,omitempty"`
TimeClose *TimeOfDay `json:"timeClose,omitempty"`
}
// A Task is an XC Track task, see
// http://xctrack.org/Competition_Interfaces.html.
type Task struct {
TaskType TaskType `json:"taskType"`
Version int `json:"version"`
EarthModel EarthModel `json:"earthModel,omitempty"`
Turnpoints []*Turnpoint `json:"turnpoints"`
Takeoff *Takeoff `json:"takeoff,omitempty"`
SSS *SSS `json:"sss,omitempty"`
Goal *Goal `json:"goal,omitempty"`
}
// A TaskType is a task type.
type TaskType string
// Task types.
const (
TaskTypeClassic TaskType = "CLASSIC"
TaskTypeWaypoints TaskType = "W"
TaskTypeWaypointList TaskType = "WPTLIST"
)
// A TimeOfDay is a time of day.
type TimeOfDay struct {
Hour int
Minute int
Second int
}
// A Turnpoint is a turnpoint.
type Turnpoint struct {
Type TurnpointType `json:"type,omitempty"`
Radius int `json:"radius"`
Waypoint Waypoint `json:"waypoint"`
}
// A TurnpointType is a turnpoint type.
type TurnpointType string
// Turnpoint types.
const (
TurnpointTypeNone TurnpointType = ""
TurnpointTypeTakeoff TurnpointType = "TAKEOFF"
TurnpointTypeSSS TurnpointType = "SSS"
TurnpointTypeESS TurnpointType = "ESS"
)
// A Waypoint is a waypoint.
type Waypoint struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Lat float64 `json:"lat"`
Lon float64 `json:"lon"`
AltSmoothed int `json:"altSmoothed,omitzero"`
}
// A WaypointList is a list of Waypoints.
type WaypointList struct {
TaskType TaskType `json:"taskType"`
Version int `json:"version"`
Points []Waypoint `json:"points"`
}
// An invalidTimeOfDayError is an invalid time of day.
type invalidTimeOfDayError string
func (e invalidTimeOfDayError) Error() string {
return fmt.Sprintf("invalid time: %q", string(e))
}
// MarshalJSON implements encoding/json.Marshaler.
func (t *TimeOfDay) MarshalJSON() ([]byte, error) {
return fmt.Appendf(make([]byte, 0, 10), "\"%02d:%02d:%02dZ\"", t.Hour, t.Minute, t.Second), nil
}
// UnmarshalJSON implements encoding/json.Unmarshaler.
func (t *TimeOfDay) UnmarshalJSON(b []byte) error {
m := timeRegexp.FindSubmatch(b)
if m == nil {
return invalidTimeOfDayError(b)
}
t.Hour, _ = strconv.Atoi(string(m[1]))
t.Minute, _ = strconv.Atoi(string(m[2]))
t.Second, _ = strconv.Atoi(string(m[3]))
return nil
}