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.

68 lines
1.7 KiB

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