-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.go
181 lines (158 loc) · 4.14 KB
/
models.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
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package accuweather
import (
"time"
"github.com/PlatformOfTrust/connector-accuweather/models"
)
type AirAndPollenValue struct {
Category string
CategoryValue int
Name string
Type string
Value float32
}
type GeoPositionResponse struct {
Key string `json:"Key"`
}
type UnitValue struct {
Unit string
UnitType int
Value float32
}
func (u *UnitValue) GetValue() float32 {
switch u.Unit {
case "cm":
return u.Value * 10
case "km/h":
return u.Value / 3.6
default:
return u.Value
}
}
func Avg(vals ...float32) float32 {
var sum float32
for _, v := range vals {
sum += v
}
return sum / float32(len(vals))
}
type Wind struct {
Direction Direction
Speed UnitValue
}
type WindCurrent struct {
Direction Direction
Speed MetricUnitValue
}
type Direction struct {
Degrees float32
}
type Day struct {
CloudCover float32
Ice UnitValue
Rain UnitValue
RainProbability float32
SnowProbability float32
Snow UnitValue
Wind Wind
}
type Temperature struct {
Maximum UnitValue
Minimum UnitValue
}
type DailyForecast struct {
AirAndPollen []AirAndPollenValue
Date time.Time
Day Day
Night Day
Temperature Temperature
RealFeelTemperature Temperature
}
type Forecast struct {
DailyForecasts []DailyForecast
}
func (f Forecast) MapToPot() []models.Forecast {
var res []models.Forecast
for _, day := range f.DailyForecasts {
fc := models.Forecast{
CloudCoverage: Avg(day.Day.CloudCover, day.Night.CloudCover),
DateTime: day.Date,
RainProbability: Avg(
day.Day.RainProbability,
day.Night.RainProbability,
),
RainVolume: Avg(
day.Day.Rain.GetValue(),
day.Night.Rain.GetValue(),
),
SnowProbability: Avg(
day.Day.SnowProbability,
day.Night.SnowProbability,
),
SnowVolume: Avg(
day.Day.Snow.GetValue(),
day.Night.Snow.GetValue(),
),
Temp: Avg(
day.Temperature.Maximum.GetValue(),
day.Temperature.Minimum.GetValue(),
),
TempMin: day.Temperature.Minimum.GetValue(),
TempMax: day.Temperature.Maximum.GetValue(),
TempFeel: Avg(
day.RealFeelTemperature.Maximum.GetValue(),
day.RealFeelTemperature.Minimum.GetValue(),
),
TempMinFeel: day.RealFeelTemperature.Minimum.GetValue(),
TempMaxFeel: day.RealFeelTemperature.Maximum.GetValue(),
WindSpeed: Avg(day.Day.Wind.Speed.GetValue(), day.Night.Wind.Speed.GetValue()),
WindDirection: Avg(day.Day.Wind.Direction.Degrees, day.Night.Wind.Direction.Degrees),
}
res = append(res, fc)
}
return res
}
type MetricUnitValue struct {
Metric UnitValue
}
type MetricTemperature struct {
Maximum MetricUnitValue
Minimum MetricUnitValue
}
type TemperatureSummary struct {
Past24HourRange MetricTemperature
}
type PrecipitationSummary struct {
Precipitation MetricUnitValue
}
type CurrentCondition struct {
LocalObservationDateTime time.Time
Temperature MetricUnitValue
TemperatureSummary TemperatureSummary
RealFeelTemperature MetricUnitValue
CloudCover float32
RelativeHumidity float32
Ice UnitValue
RainProbability float32
Snow UnitValue
Wind WindCurrent
PrecipitationSummary PrecipitationSummary
}
func (f CurrentCondition) MapToPot() []models.Forecast {
return []models.Forecast{
models.Forecast{
CloudCoverage: f.CloudCover,
DateTime: f.LocalObservationDateTime,
Humidity: f.RelativeHumidity,
Temp: f.Temperature.Metric.GetValue(),
TempMax: f.TemperatureSummary.Past24HourRange.Maximum.Metric.GetValue(),
TempMin: f.TemperatureSummary.Past24HourRange.Minimum.Metric.GetValue(),
TempFeel: f.RealFeelTemperature.Metric.GetValue(),
TempMaxFeel: f.RealFeelTemperature.Metric.GetValue(),
TempMinFeel: f.RealFeelTemperature.Metric.GetValue(),
WindDirection: f.Wind.Direction.Degrees,
WindSpeed: f.Wind.Speed.Metric.GetValue(),
RainProbability: f.RainProbability,
RainVolume: f.PrecipitationSummary.Precipitation.Metric.GetValue(),
},
}
}