-
Notifications
You must be signed in to change notification settings - Fork 36
/
installed.go
117 lines (92 loc) · 2.35 KB
/
installed.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
package main
import (
"regexp"
"sort"
"strings"
"github.com/GeoNet/delta/meta"
)
func (n *Network) InstalledSensors(set *meta.Set, match *regexp.Regexp, network, prefix string) error {
for _, stn := range set.Stations() {
net, ok := set.Network(stn.Network)
if !ok {
continue
}
if net.Code != network {
continue
}
var sites []Site
for _, site := range set.Sites() {
if site.Station != stn.Code {
continue
}
if !match.MatchString(site.Location) {
continue
}
sensors := make(map[Sensor][]string)
for _, c := range set.Collections(site) {
label := strings.TrimSpace(prefix + " " + c.Component.Type)
sensor := Sensor{
Type: label,
Make: c.InstalledSensor.Make,
Model: c.InstalledSensor.Model,
Azimuth: c.InstalledSensor.Azimuth,
Method: c.InstalledSensor.Method,
Dip: c.InstalledSensor.Dip,
Vertical: c.InstalledSensor.Vertical,
North: c.InstalledSensor.North,
East: c.InstalledSensor.East,
StartDate: c.InstalledSensor.Start,
EndDate: c.InstalledSensor.End,
}
sensors[sensor] = append(sensors[sensor], c.Code())
}
var list []Sensor
for sensor, chans := range sensors {
dedupe := make(map[string]interface{})
for _, c := range chans {
dedupe[c] = true
}
var channels []string
for k := range dedupe {
channels = append(channels, k)
}
sort.Strings(channels)
sensor.Channels = strings.Join(channels, ",")
list = append(list, sensor)
}
sort.Slice(list, func(i, j int) bool {
return list[i].Less(list[j])
})
sites = append(sites, Site{
Code: site.Location,
Latitude: site.Latitude,
Longitude: site.Longitude,
Elevation: site.Elevation,
Depth: site.Depth,
Datum: site.Datum,
Survey: site.Survey,
StartDate: site.Start,
EndDate: site.End,
Sensors: list,
})
}
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
}