-
Notifications
You must be signed in to change notification settings - Fork 0
/
resources.go
102 lines (87 loc) · 3.18 KB
/
resources.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
package seaweed
import "time"
// APIError represents a Seaweed API error response body.
//
// Note that the Magic Seaweed API may respond with an HTTP status code of 200
// and a response body reporting an error.
type APIError struct {
ErrorResponse ErrorResponse `json:"error_response"`
}
// ErrorResponse represents a Seaweed API error response.
type ErrorResponse struct {
Code int `json:"code"`
ErrorMsg string `json:"error_msg"`
}
// Forecast represents a Seaweed API forecast.
type Forecast struct {
Timestamp int64 `json:"timestamp"`
LocalTimestamp int64 `json:"localTimestamp"`
IssueTimestamp int64 `json:"issueTimestamp"`
FadedRating int `json:"FadedRating"`
SolidRating int `json:"SolidRating"`
Swell Swell `json:"swell"`
Wind Wind `json:"wind"`
Condition Condition `json:"condition"`
Charts Charts `json:"charts"`
}
// IsWeekend returns true if a forecast pertains to a Saturday or a Sunday.
func (f Forecast) IsWeekend() bool {
day := time.Unix(f.LocalTimestamp, 0).UTC().Weekday().String()
if day == "Saturday" || day == "Sunday" {
return true
}
return false
}
// IsDay returns true if a forecast pertains to the day it's passed.
func (f Forecast) IsDay(t time.Time) bool {
day := time.Unix(f.LocalTimestamp, 0).UTC()
return day.Day() == t.Day() && day.Month() == t.Month() && day.Year() == t.Year()
}
// Swell represents a Seaweed API forecast's swell.
type Swell struct {
MinBreakingHeight int `json:"minBreakingHeight"`
AbsMinBreakingHeight float64 `json:"absMinBreakingHeight"`
MaxBreakingHeight int `json:"maxBreakingHeight"`
AbsMaxBreakingHeight float64 `json:"absMaxBreakingHeight"`
Probability int `json:"probability"`
Unit string `json:"unit"`
Components Components `json:"components"`
}
// Components represents a Seaweed API forecast's swell's components.
type Components struct {
Combined Component `json:"combined"`
Primary Component `json:"primary"`
Secondary Component `json:"secondary"`
Tertiary Component `json:"tertiary"`
}
// Component represents a Seaweed API forecast's swell component.
type Component struct {
Height float64 `json:"height"`
Period int `json:"period"`
Direction float64 `json:"direction"`
CompassDirection string `json:"compassDirection"`
}
// Wind represents a Seaweed API forecast's wind.
type Wind struct {
Speed int `json:"speed"`
Direction int64 `json:"direction"`
CompassDirection string `json:"compassDirection"`
Chill int64 `json:"chill"`
Gusts int64 `json:"gusts"`
Unit string `json:"unit"`
}
// Condition represents a Seaweed API forecast's condition.
type Condition struct {
Pressure int64 `json:"pressure"`
Temperature int64 `json:"temperature"`
Weather string `json:"weather"`
Unit string `json:"unit"`
UnitPressure string `json:"unitPressure"`
}
// Charts represents a Seaweed API forecast's charts.
type Charts struct {
Swell string `json:"swell"`
Period string `json:"period"`
Wind string `json:"wind"`
Pressure string `json:"pressure"`
}