Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix station filter logic for nodes having no children. #232

Merged
merged 2 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions cmd/fdsn-ws/fdsn_station.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const (
ONBEFOREEND = 0
ONAFTERSTART = 0
AFTER = 1

REGEX_ANYTHING = "^.*$"
)

var stationAbbreviations = map[string]string{
Expand Down Expand Up @@ -663,14 +665,20 @@ func (n *NetworkType) doFilter(params []fdsnStationV1Search) bool {

if len(n.Station) == 0 {
// for network nodes without children (though unlikely to happen):
// 1. If the query parameter stops at network level, then the match is done
// 2. Otherwise, we're unable to get a match because of empty children (thus returning false)
// If there are query parameters for furthur levels, and there's no "*" (match anything) in the parameters,
// then it'll be impossible to find a match (because we don't have children)
for _, p := range matchedParams {
if p.StationReg == nil && p.ChannelReg == nil && p.LocationReg == nil {
return true
if p.StationReg != nil && !contains(p.StationReg, REGEX_ANYTHING) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does the regex check add?

Copy link
Contributor Author

@junghao junghao Mar 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See Jerome's comment regarding issue with WTSZ here https://github.com/GeoNet/tickets/issues/12671#issuecomment-1452655370

Short answer is : "*" includes "0 results".

return false
}
if p.ChannelReg != nil && !contains(p.ChannelReg, REGEX_ANYTHING) {
return false
}
if p.LocationReg != nil && !contains(p.LocationReg, REGEX_ANYTHING) {
return false
}
}
return false
return true
}

for _, s := range n.Station {
Expand Down Expand Up @@ -715,15 +723,17 @@ func (s *StationType) doFilter(params []fdsnStationV1Search) bool {

if len(s.Channel) == 0 {
// for station nodes without children:
// 1. If the query parameter stops at station level, then the match is done
// 2. Otherwise, we're unable to get a match (thus returning false)
// If there are query parameters for furthur levels, and there's no "*" (match anything) in the parameters,
// then it'll be impossible to find a match (because we don't have children)
for _, p := range matchedParams {
if p.ChannelReg == nil && p.LocationReg == nil {
return true
if p.ChannelReg != nil && !contains(p.ChannelReg, REGEX_ANYTHING) {
return false
}
if p.LocationReg != nil && !contains(p.LocationReg, REGEX_ANYTHING) {
return false
}
}

return false
return true
}

for _, c := range s.Channel {
Expand Down Expand Up @@ -1007,3 +1017,12 @@ func (d xsdDateTime) MarshalFormatText() string {
b, _ := d.MarshalText()
return string(b)
}

func contains(slice []string, value string) bool {
for _, s := range slice {
if s == value {
return true
}
}
return false
}
17 changes: 17 additions & 0 deletions cmd/fdsn-ws/fdsn_station_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,23 @@ func TestDoFilter(t *testing.T) {
t.Errorf("expected to be emptyu got %v", fdsn)
}

// two station without children, we should see both
query = make(map[string][]string)
fdsn = makeTestFDSN("NZ", "STA1", "", "")
fdsn.Network[0].Station = append(fdsn.Network[0].Station, makeTestStation("STA2"))
query.Set("network", "NZ")
query.Set("station", "STA1,STA2")
query.Set("channel", "*")
if hasValue, err = testCase(&fdsn, query); err != nil {
t.Error(err)
}
if !hasValue {
t.Errorf("expected to be values got empty result")
}
// we should get 2 results
if len(fdsn.Network[0].Station) != 2 {
t.Errorf("expected to be 2 stations got %v", fdsn)
}
}

// helper functions
Expand Down