Ladsgroup added a comment.
I forgot to put the code for this.
name=RL_graph.py
import json
import sys
import random
import math
from collections import defaultdict
import networkx as nx
import matplotlib.pyplot as plt
from networkx.drawing.nx_agraph import graphviz_layout
from networkx.drawing.nx_pydot import write_dot
G = nx.DiGraph()
with open('rl_modules.json', 'r') as f:
wikibase_modules = json.loads(f.read())
with open(sys.argv[1], 'r') as f:
modules = json.loads(f.read())
for i in range(len(modules)):
module = modules[i]
if module[0] not in wikibase_modules:
continue
if len(module) < 3:
G.add_node(module[0])
continue
for module_dep in module[2]:
if modules[module_dep][0] in wikibase_modules:
G.add_edge(module[0], modules[module_dep][0])
print(G.number_of_nodes())
entry_points = []
for node in G.in_degree():
if node[1] == 0:
entry_points.append(node[0])
for entry_point in entry_points:
print(entry_point)
directions = {}
for node in G.nodes():
if node in entry_points:
continue
node_paths = {}
for entry_point in entry_points:
try:
path = nx.shortest_path(G, entry_point, node)
except:
continue
node_paths[entry_point] = path
if len(node_paths) > 1:
print('shared', node)
continue
directions[node] = node_paths
per_entry_point_nodes = defaultdict(set)
for node in directions:
for entry_point in directions[node]:
per_entry_point_nodes[entry_point] =
per_entry_point_nodes[entry_point].union(set(directions[node][entry_point]))
write_dot(G,'G.dot')
sys.exit()
for entry_point in per_entry_point_nodes:
subgraph = G.subgraph(per_entry_point_nodes[entry_point])
size_factor =round(math.sqrt((len(subgraph.nodes())**2 ) / 25))
if size_factor < 3:
size_factor = 3
plt.plot()
fig= plt.figure(figsize=(size_factor*4,size_factor*3))
pos=graphviz_layout(subgraph, prog='dot')
nx.draw(subgraph, pos, with_labels=True)
write_dot(subgraph,'nx_' + entry_point + '.dot')
plt.savefig('nx_' + entry_point + '.png')
`rl_modules.json` is list of names of modules registered by Wikibase so we
can filter and only care about those. and first argument should be the json
file of RL modules (output of startup module in Wikidata). Something like this:
[
[
"site",
"0jxs9iy",
[
1
]
],
.
.
.
]
TASK DETAIL
https://phabricator.wikimedia.org/T232728
EMAIL PREFERENCES
https://phabricator.wikimedia.org/settings/panel/emailpreferences/
To: Ladsgroup
Cc: Agabi10, Rosalie_WMDE, Ladsgroup, Aklapper, Jakob_WMDE, darthmon_wmde,
DannyS712, Nandana, Lahi, Gq86, GoranSMilovanovic, QZanden, LawExplorer,
_jensen, rosalieper, Wikidata-bugs, aude, Lydia_Pintscher, Mbch331
_______________________________________________
Wikidata-bugs mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikidata-bugs