You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.3 KiB

  1. package main
  2. import (
  3. "gopkg.in/mgo.v2/bson"
  4. )
  5. func upTree(address string, network NetworkModel) NetworkModel {
  6. var upNetwork NetworkModel
  7. //add address node to network
  8. node := NodeModel{}
  9. err := nodeCollection.Find(bson.M{"id": address}).One(&node)
  10. check(err)
  11. if nodeInNodes(network.Nodes, node) == false {
  12. network.Nodes = append(network.Nodes, node)
  13. }
  14. //get edges before the address
  15. edges := []EdgeModel{}
  16. err = edgeCollection.Find(bson.M{"to": address}).All(&edges)
  17. check(err)
  18. for _, e := range edges {
  19. if edgeInEdges(network.Edges, e) == false {
  20. network.Edges = append(network.Edges, e)
  21. }
  22. //get the nodes involved in edges
  23. /*
  24. nodes := []NodeModel{}
  25. err := nodeCollection.Find(bson.M{"id": }).All(&edges)
  26. check(err)
  27. */
  28. if e.From != e.To {
  29. upNetwork = upTree(e.From, network)
  30. for _, upN := range upNetwork.Nodes {
  31. if nodeInNodes(network.Nodes, upN) == false {
  32. network.Nodes = append(network.Nodes, upN)
  33. }
  34. }
  35. for _, upE := range upNetwork.Edges {
  36. if edgeInEdges(network.Edges, upE) == false {
  37. network.Edges = append(network.Edges, upE)
  38. }
  39. }
  40. }
  41. }
  42. return network
  43. }
  44. func addressTree(address string) NetworkModel {
  45. var network NetworkModel
  46. network = upTree(address, network)
  47. return network
  48. }