Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] improve output (filtering, fix links type, new outputs nodelis…
…t for freifunkapi and meshviewer-ffrgb v10 NextGen)
- Loading branch information
Showing
52 changed files
with
1,682 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package all | ||
|
||
import "github.com/FreifunkBremen/yanic/runtime" | ||
|
||
// 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.Config{}) | ||
filterfuncs := []filterFunc{ | ||
f.HasLocation(), | ||
f.Blacklist(), | ||
f.InArea(), | ||
f.NoOwner(), | ||
} | ||
|
||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package all | ||
|
||
import "github.com/FreifunkBremen/yanic/runtime" | ||
|
||
func (f filterConfig) Blacklist() filterFunc { | ||
v, ok := f["blacklist"] | ||
if !ok { | ||
return noFilter | ||
} | ||
|
||
list := make(map[string]interface{}) | ||
for _, nodeid := range v.([]interface{}) { | ||
list[nodeid.(string)] = true | ||
} | ||
|
||
return func(node *runtime.Node) *runtime.Node { | ||
if nodeinfo := node.Nodeinfo; nodeinfo != nil { | ||
if _, ok := list[nodeinfo.NodeID]; ok { | ||
return nil | ||
} | ||
} | ||
return node | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package all | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/FreifunkBremen/yanic/data" | ||
"github.com/FreifunkBremen/yanic/runtime" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestFilterBlacklist(t *testing.T) { | ||
assert := assert.New(t) | ||
var config filterConfig | ||
|
||
config = map[string]interface{}{} | ||
|
||
filterBlacklist := config.Blacklist() | ||
|
||
n := filterBlacklist(&runtime.Node{Nodeinfo: &data.NodeInfo{}}) | ||
assert.NotNil(n) | ||
|
||
config["blacklist"] = []interface{}{"a", "c"} | ||
filterBlacklist = config.Blacklist() | ||
|
||
n = filterBlacklist(&runtime.Node{Nodeinfo: &data.NodeInfo{NodeID: "a"}}) | ||
assert.Nil(n) | ||
|
||
n = filterBlacklist(&runtime.Node{Nodeinfo: &data.NodeInfo{}}) | ||
assert.NotNil(n) | ||
|
||
n = filterBlacklist(&runtime.Node{}) | ||
assert.NotNil(n) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package all | ||
|
||
import "github.com/FreifunkBremen/yanic/runtime" | ||
|
||
func (f filterConfig) HasLocation() filterFunc { | ||
withLocation, ok := f["has_location"].(bool) | ||
if !ok { | ||
return noFilter | ||
} | ||
return func(node *runtime.Node) *runtime.Node { | ||
if nodeinfo := node.Nodeinfo; nodeinfo != nil { | ||
if withLocation { | ||
if location := nodeinfo.Location; location != nil { | ||
return node | ||
} | ||
} else { | ||
if location := nodeinfo.Location; location == nil { | ||
return node | ||
} | ||
} | ||
} else if !withLocation { | ||
return node | ||
} | ||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package all | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/FreifunkBremen/yanic/data" | ||
"github.com/FreifunkBremen/yanic/runtime" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestFilterHasLocation(t *testing.T) { | ||
assert := assert.New(t) | ||
var config filterConfig | ||
|
||
config = map[string]interface{}{} | ||
|
||
filterHasLocation := config.HasLocation() | ||
n := filterHasLocation(&runtime.Node{Nodeinfo: &data.NodeInfo{ | ||
Location: &data.Location{}, | ||
}}) | ||
assert.NotNil(n) | ||
|
||
config["has_location"] = true | ||
filterHasLocation = config.HasLocation() | ||
|
||
n = filterHasLocation(&runtime.Node{Nodeinfo: &data.NodeInfo{ | ||
Location: &data.Location{}, | ||
}}) | ||
assert.NotNil(n) | ||
|
||
n = filterHasLocation(&runtime.Node{Nodeinfo: &data.NodeInfo{}}) | ||
assert.Nil(n) | ||
|
||
n = filterHasLocation(&runtime.Node{}) | ||
assert.Nil(n) | ||
|
||
config["has_location"] = false | ||
filterHasLocation = config.HasLocation() | ||
|
||
n = filterHasLocation(&runtime.Node{Nodeinfo: &data.NodeInfo{ | ||
Location: &data.Location{}, | ||
}}) | ||
assert.Nil(n) | ||
|
||
n = filterHasLocation(&runtime.Node{Nodeinfo: &data.NodeInfo{}}) | ||
assert.NotNil(n) | ||
|
||
n = filterHasLocation(&runtime.Node{}) | ||
assert.NotNil(n) | ||
} |
Oops, something went wrong.