[TASK] add sites filter for outputs

This commit is contained in:
Julian Labus 2018-01-04 14:45:04 +01:00
parent 6e1fcd32ec
commit 83e59745a5
No known key found for this signature in database
GPG Key ID: 8AF209F2C6B3572A
5 changed files with 75 additions and 0 deletions

View File

@ -52,6 +52,9 @@ offline_after = "10m"
# List of nodeids of nodes that should be filtered out, so they won't appear in output
#blacklist = ["00112233445566", "1337f0badead"]
#
# List of site_codes of nodes that should be included in the output
#sites = ["ffhb"]
#
# set has_location to true if you want to include only nodes that have geo-coordinates set
# (setting this to false has no sensible effect, unless you'd want to hide nodes that have coordinates)
#has_location = true
@ -71,6 +74,7 @@ path = "/var/www/html/meshviewer/data/meshviewer.json"
#[nodes.output.meshviewer-ffrgb.filter]
#no_owner = false
#sites = ["ffhb"]
#blacklist = ["00112233445566", "1337f0badead"]
#has_location = true

View File

@ -196,6 +196,7 @@ enable = true
[nodes.output.example.filter]
no_owner = true
blacklist = ["00112233445566", "1337f0badead"]
sites = ["ffhb"]
has_location = true
[nodes.output.example.filter.in_area]
latitude_min = 34.30
@ -222,6 +223,7 @@ For each output format there can be set different filters
[nodes.output.example.filter]
no_owner = true
blacklist = ["00112233445566", "1337f0badead"]
sites = ["ffhb"]
has_location = true
[nodes.output.example.filter.in_area]
latitude_min = 34.30
@ -252,6 +254,16 @@ blacklist = ["00112233445566", "1337f0badead"]
{% endmethod %}
### sites
{% method %}
List of site_codes of nodes that should be included in output
{% sample lang="toml" %}
```toml
sites = ["ffhb"]
```
{% endmethod %}
### has_location
{% method %}
set has_location to true if you want to include only nodes that have geo-coordinates set

View File

@ -18,6 +18,7 @@ func (f filterConfig) filtering(nodesOrigin *runtime.Nodes) *runtime.Nodes {
f.HasLocation(),
f.Blacklist(),
f.InArea(),
f.Sites(),
f.NoOwner(),
}

View File

@ -0,0 +1,24 @@
package all
import "github.com/FreifunkBremen/yanic/runtime"
func (f filterConfig) Sites() filterFunc {
v, ok := f["sites"]
if !ok {
return noFilter
}
list := make(map[string]interface{})
for _, site := range v.([]interface{}) {
list[site.(string)] = true
}
return func(node *runtime.Node) *runtime.Node {
if nodeinfo := node.Nodeinfo; nodeinfo != nil {
if _, ok := list[nodeinfo.System.SiteCode]; ok {
return node
}
}
return nil
}
}

View File

@ -0,0 +1,34 @@
package all
import (
"testing"
"github.com/FreifunkBremen/yanic/data"
"github.com/FreifunkBremen/yanic/runtime"
"github.com/stretchr/testify/assert"
)
func TestFilterSites(t *testing.T) {
assert := assert.New(t)
var config filterConfig
config = map[string]interface{}{}
filterSites := config.Sites()
n := filterSites(&runtime.Node{Nodeinfo: &data.NodeInfo{}})
assert.NotNil(n)
config["sites"] = []interface{}{"ffhb"}
filterSites = config.Sites()
n = filterSites(&runtime.Node{Nodeinfo: &data.NodeInfo{System: data.System{SiteCode: "ffxx"}}})
assert.Nil(n)
n = filterSites(&runtime.Node{Nodeinfo: &data.NodeInfo{System: data.System{SiteCode: "ffhb"}}})
assert.NotNil(n)
n = filterSites(&runtime.Node{})
assert.Nil(n)
}