1
0

graphStats 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env python2
  2. # You may redistribute this program and/or modify it under the terms of
  3. # the GNU General Public License as published by the Free Software Foundation,
  4. # either version 3 of the License, or (at your option) any later version.
  5. #
  6. # This program is distributed in the hope that it will be useful,
  7. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. # GNU General Public License for more details.
  10. #
  11. # You should have received a copy of the GNU General Public License
  12. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  13. import cjdnsadmin.adminTools as at
  14. import cjdnsadmin.graphMaker as gm
  15. import networkx as nx
  16. import numpy as np
  17. cjdns=at.connect()
  18. root=at.whoami(cjdns)
  19. root=root['IP']
  20. G=gm.makeGraph()
  21. path=nx.single_source_dijkstra(G,root[-4:])
  22. degrees=G.degree()
  23. hops=np.array([path[0][key] for key in path[0].keys()])
  24. deg=np.array([degrees[key] for key in degrees.keys()])
  25. mean_d=deg.mean()
  26. std_d=deg.std()
  27. mean_h=hops.mean()
  28. std_h=hops.std()
  29. print '==================Graph Stats=================='
  30. print 'Number of Nodes: ',len(G.nodes())
  31. print 'Number of Edges: ',len(G.edges())
  32. print 'Maximum Shortest Path Length: ',str(hops.max())
  33. print 'Average Shortest Path Length: ',str(mean_h)[0:5], u'\u00B1',str(std_h)[0:5]
  34. print 'Maximum Number of Connections: ',str(deg.max())
  35. print 'Average Number of Connections: ',str(mean_d)[0:5], u'\u00B1',str(std_d)[0:5]