-
Notifications
You must be signed in to change notification settings - Fork 2
/
analysis.go
68 lines (59 loc) · 1.38 KB
/
analysis.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
package surflinef
import (
"encoding/json"
"strings"
)
// Analysis is a collection of high-level surf info.
type Analysis struct {
GeneralCondition []string
GeneralText []string
SurfMax []string
SurfMin []string
SurfRange []string
SurfText []string
Units string
}
type iAnalysis struct {
GeneralCondition []string `json:"generalCondition"`
GeneralText []string `json:"generalText"`
SurfMax []json.Number `json:"surfMax"`
SurfMin []json.Number `json:"surfMin"`
SurfRange []string `json:"surfRange"`
SurfText []string `json:"surfText"`
Units string `json:"units"`
}
func (iA iAnalysis) analysis() Analysis {
var fSurfMax []string
for i := range iA.SurfMax {
sm := iA.SurfMax[i].String()
nsm := normalize(sm)
fSurfMax = append(fSurfMax, nsm)
}
var fSurfMin []string
for i := range iA.SurfMin {
sm := iA.SurfMin[i].String()
nsm := normalize(sm)
fSurfMin = append(fSurfMin, nsm)
}
var fGeneralText []string
for i := range iA.GeneralText {
gt := iA.GeneralText[i]
sgt := strings.TrimSpace(gt)
fGeneralText = append(fGeneralText, sgt)
}
return Analysis{
iA.GeneralCondition,
fGeneralText,
fSurfMax,
fSurfMin,
iA.SurfRange,
iA.SurfText,
iA.Units,
}
}
func normalize(sm string) string {
if sm == "" {
return "0"
}
return sm
}