Skip to content

Commit

Permalink
[TASK] refactoring of filters (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
corny authored and genofire committed Feb 15, 2018
1 parent 0d18667 commit 6b522c6
Show file tree
Hide file tree
Showing 27 changed files with 724 additions and 432 deletions.
3 changes: 3 additions & 0 deletions cmd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ func TestReadConfig(t *testing.T) {
"enable": false,
"nodes_path": "/var/www/html/meshviewer/data/nodes.json",
"graph_path": "/var/www/html/meshviewer/data/graph.json",
"filter": map[string]interface{}{
"no_owner": true,
},
}, meshviewer)

_, err = ReadConfigFile("testdata/config_invalid.toml")
Expand Down
22 changes: 15 additions & 7 deletions config_example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,16 @@ offline_after = "10m"
# For each output format there can be set different filters
#[nodes.output.example.filter]
#
# Set to false, if you want the json files to contain the owner information
# WARNING: if it is not set, it will publish contact information of other persons
# Set to true, if you did not want the json files to contain the owner information
#no_owner = true
#
# 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
Expand All @@ -69,9 +73,11 @@ offline_after = "10m"
enable = true
path = "/var/www/html/meshviewer/data/meshviewer.json"

#[nodes.output.meshviewer-ffrgb.filter]
#no_owner = false
[nodes.output.meshviewer-ffrgb.filter]
# WARNING: if it is not set, it will publish contact information of other persons
no_owner = false
#blacklist = ["00112233445566", "1337f0badead"]
#sites = ["ffhb"]
#has_location = true

#[nodes.output.meshviewer-ffrgb.filter.in_area]
Expand All @@ -96,17 +102,19 @@ nodes_path = "/var/www/html/meshviewer/data/nodes.json"
# path where to store graph.json
graph_path = "/var/www/html/meshviewer/data/graph.json"

#[nodes.output.meshviewer.filter]
#no_owner = false
[nodes.output.meshviewer.filter]
# WARNING: if it is not set, it will publish contact information of other persons
no_owner = true


# definition for nodelist.json
[[nodes.output.nodelist]]
enable = true
path = "/var/www/html/meshviewer/data/nodelist.json"

#[nodes.output.nodelist.filter]
#no_owner = false
[nodes.output.nodelist.filter]
# WARNING: if it is not set, it will publish contact information of other persons
no_owner = true



Expand Down
16 changes: 16 additions & 0 deletions docs/docs_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -235,6 +237,10 @@ longitude_max = 39.72
### no_owner
{% method %}
Set to false, if you want the json files to contain the owner information


**WARNING: if it is not set, it will publish contact information of other persons.**

{% sample lang="toml" %}
```toml
no_owner = true
Expand All @@ -252,6 +258,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
Expand Down
45 changes: 5 additions & 40 deletions output/all/filter.go
Original file line number Diff line number Diff line change
@@ -1,44 +1,9 @@
package all

import (
"github.com/FreifunkBremen/yanic/runtime"
_ "github.com/FreifunkBremen/yanic/output/filter/blacklist"
_ "github.com/FreifunkBremen/yanic/output/filter/haslocation"
_ "github.com/FreifunkBremen/yanic/output/filter/inarea"
_ "github.com/FreifunkBremen/yanic/output/filter/noowner"
_ "github.com/FreifunkBremen/yanic/output/filter/site"
)

// Config Filter
type filterConfig map[string]interface{}

type filterFunc func(*runtime.Node) *runtime.Node

func noFilter(node *runtime.Node) *runtime.Node {
return node
}

// Create Filter
func (f filterConfig) filtering(nodesOrigin *runtime.Nodes) *runtime.Nodes {
nodes := runtime.NewNodes(&runtime.NodesConfig{})
filterfuncs := []filterFunc{
f.HasLocation(),
f.Blacklist(),
f.InArea(),
f.NoOwner(),
}

nodesOrigin.Lock()
defer nodesOrigin.Unlock()

for _, nodeOrigin := range nodesOrigin.List {
//maybe cloning of this object is better?
node := nodeOrigin
for _, f := range filterfuncs {
node = f(node)
if node == nil {
break
}
}

if node != nil {
nodes.AddNode(node)
}
}
return nodes
}
24 changes: 0 additions & 24 deletions output/all/filter_blacklist.go

This file was deleted.

34 changes: 0 additions & 34 deletions output/all/filter_blacklist_test.go

This file was deleted.

26 changes: 0 additions & 26 deletions output/all/filter_haslocation.go

This file was deleted.

50 changes: 0 additions & 50 deletions output/all/filter_haslocation_test.go

This file was deleted.

42 changes: 0 additions & 42 deletions output/all/filter_inarea.go

This file was deleted.

0 comments on commit 6b522c6

Please sign in to comment.