Skip to content

Commit 0896277

Browse files
author
devbruce
committed
Rename graph varaibles of viz.core.sna, viz.core.sna_sub
1 parent 2b6059f commit 0896277

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

app/viz/core/sna.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,17 @@ def gen_gexf_and_pass_partition_data(
4444
cooccur_matrix = matrix.get('cooccur_matrix')
4545

4646
# Get Graph
47-
G = nx.from_pandas_adjacency(cooccur_matrix)
47+
graph = nx.from_pandas_adjacency(cooccur_matrix)
4848

4949
# Get Sub Data
5050
sub_data = get_sub_data(
51-
graph=G,
51+
graph=graph,
5252
node_num=node_num,
5353
edge_remove_threshold=edge_remove_threshold,
5454
remove_isolated_node=remove_isolated_node,
5555
matrix=matrix
5656
)
57-
sub_G = sub_data.get('sub_graph')
57+
sub_graph = sub_data.get('sub_graph')
5858
tf_sum_dict_sorted = sub_data.get('tf_sum_dict_sorted')
5959

6060
# ------ Set Attributes for gexf file ------ #
@@ -69,24 +69,24 @@ def gen_gexf_and_pass_partition_data(
6969
scaled_weight_dict = dict(scaled_weight_list)
7070

7171
for node in scaled_weight_dict:
72-
sub_G.nodes[node]['viz'] = {'size': scaled_weight_dict[node]}
72+
sub_graph.nodes[node]['viz'] = {'size': scaled_weight_dict[node]}
7373

7474
# Add edge weight
75-
edge_weight_max = max([sub_G[u][v]['weight'] for u, v in sub_G.edges])
76-
for u, v in sub_G.edges:
77-
sub_G[u][v]['viz'] = {'thickness': sub_G[u][v]['weight'] * 35 / edge_weight_max}
75+
edge_weight_max = max([sub_graph[u][v]['weight'] for u, v in sub_graph.edges])
76+
for u, v in sub_graph.edges:
77+
sub_graph[u][v]['viz'] = {'thickness': sub_graph[u][v]['weight'] * 35 / edge_weight_max}
7878

7979
# ------ Set Layout ------ #
8080
# Fruchterman Reingold
8181
if layout == "fr":
82-
pos = nx.spring_layout(sub_G, k=fr_k, iterations=iterations)
82+
pos = nx.spring_layout(sub_graph, k=fr_k, iterations=iterations)
8383
for node in pos:
84-
sub_G.nodes[node]['viz']['position'] = {'x': pos[node][0], 'y': pos[node][1]}
84+
sub_graph.nodes[node]['viz']['position'] = {'x': pos[node][0], 'y': pos[node][1]}
8585

8686
# ForceAtlas2
8787
elif layout == "fa2":
8888
forceatlas2 = ForceAtlas2()
89-
pos = forceatlas2.forceatlas2_networkx_layout(sub_G, iterations=iterations)
89+
pos = forceatlas2.forceatlas2_networkx_layout(sub_graph, iterations=iterations)
9090

9191
for node in pos:
9292
raw_x, raw_y = pos[node]
@@ -95,14 +95,14 @@ def gen_gexf_and_pass_partition_data(
9595
if raw_x < 0: adj_x *= -1
9696
if raw_y < 0: adj_y *= -1
9797
# ----------------- #
98-
sub_G.nodes[node]['viz']['position'] = {'x': adj_x, 'y': adj_y}
98+
sub_graph.nodes[node]['viz']['position'] = {'x': adj_x, 'y': adj_y}
9999
# -------------------------- #
100100

101101
# Generate gexf file
102-
write_gexf(graph=sub_G)
102+
write_gexf(graph=sub_graph)
103103

104104
# ------ Pass partition data to template ------ #
105-
partition = community.best_partition(sub_G)
105+
partition = community.best_partition(sub_graph)
106106
partition_len = max(partition.values()) + 1
107107
node_freq_per_klass = {n: list() for n in range(partition_len)}
108108
for node, klass in partition.items():

app/viz/core/sna_sub.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def get_sub_data(graph, node_num, edge_remove_threshold, remove_isolated_node, m
123123
for i in range(len(term_names)):
124124
tf_sum_dict[term_names[i]] = tf_sum[i]
125125

126-
# Get Top Frequency Nodes to make sub_G
126+
# Get Top Frequency Nodes to make sub_graph
127127
tf_sum_dict_sorted = sorted(tf_sum_dict.items(), key=lambda x: x[1], reverse=True)
128128

129129
# -- Process : Remove Isolated Node -- #
@@ -134,7 +134,7 @@ def get_sub_data(graph, node_num, edge_remove_threshold, remove_isolated_node, m
134134
for node in graph.nodes:
135135
edge_weight_sum=0
136136
for to in graph[node]:
137-
if to in main_network_nodes: # If edge is related to main_nodes, add this edge_weight edge_weight_sum
137+
if to in main_network_nodes: # If edge is related to main_nodes, add its edge_weight edge_weight_sum
138138
edge_weight_sum += graph[node][to]['weight']
139139
if edge_weight_sum == 0:
140140
isolated_nodes.append(node)

0 commit comments

Comments
 (0)