-
Notifications
You must be signed in to change notification settings - Fork 36
/
envirosensor.go
106 lines (83 loc) · 1.86 KB
/
envirosensor.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
package main
import (
"sort"
"github.com/GeoNet/delta/meta"
)
func (n *Network) EnviroSensor(set *meta.Set, enviro string, label string) error {
net, ok := set.Network(enviro)
if !ok {
return nil
}
valid := make(map[string]interface{})
for _, f := range set.Features() {
valid[f.Station] = true
}
for _, stn := range set.Stations() {
if _, ok := valid[stn.Code]; !ok {
continue
}
if stn.Network != enviro {
continue
}
var sites []Site
for _, site := range set.Sites() {
if site.Station != stn.Code {
continue
}
var sensors []Sensor
for _, v := range set.InstalledSensors() {
if v.Station != site.Station {
continue
}
if v.Location != site.Location {
continue
}
sensors = append(sensors, Sensor{
Type: label,
Make: v.Make,
Model: v.Model,
Azimuth: v.Azimuth,
Method: v.Method,
Dip: v.Dip,
Vertical: v.Vertical,
North: v.North,
East: v.East,
StartDate: v.Start,
EndDate: v.End,
})
}
sort.Slice(sensors, func(i, j int) bool {
return sensors[i].Less(sensors[j])
})
sites = append(sites, Site{
Code: site.Location,
Latitude: site.Latitude,
Longitude: site.Longitude,
Elevation: site.Elevation,
Datum: site.Datum,
Survey: site.Survey,
StartDate: site.Start,
EndDate: site.End,
Sensors: sensors,
})
}
sort.Slice(sites, func(i, j int) bool {
return sites[i].Less(sites[j])
})
n.Stations = append(n.Stations, Station{
Code: stn.Code,
Network: net.External,
Name: stn.Name,
Description: net.Description,
Latitude: stn.Latitude,
Longitude: stn.Longitude,
Elevation: stn.Elevation,
Depth: stn.Depth,
Datum: stn.Datum,
StartDate: stn.Start,
EndDate: stn.End,
Sites: sites,
})
}
return nil
}