-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmetrics.py
56 lines (33 loc) · 988 Bytes
/
metrics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Metrics
# Import libraries
import networkx as nx
import re
from Queue import Queue
import time
import sys
import matplotlib.pyplot as plt
import numpy as np
G = nx.read_gpickle('./graph_pickles/graphTPain.pickle')
print("Number of nodes in graph:")
print(nx.number_of_nodes(G))
shortestPathLengths = nx.shortest_path_length(G, source ='spotify:artist:3aQeKQSyrW4qWr35idm0cy')
distances = shortestPathLengths.values()
histogram = [0] * 10
# Calculate distances
for i in range(len(distances)):
histogram[distances[i]] += 1
print histogram
print(len(shortestPathLengths))
"""
G = nx.read_gpickle('beethoven.pickle')
# Create tree of nodes to display in html
beethovenTree = nx.bfs_tree(G, source = 'spotify:artist:2wOqMjp9TyABvtHdOSOTUS')
# Output as a pickle file
nx.write_gpickle(beethovenTree, 'beethovenTree.pickle')
G = nx.read_gpickle('beethovenTree.pickle')
print("Is this a tree?")
print(nx.is_tree(G))
print(nx.info(G));
nx.draw_networkx(G)
plt.show()
"""