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.

59 lines
1.3 KiB

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