Update app.py
Browse files
app.py
CHANGED
@@ -40,16 +40,31 @@ def network_visualizer(city, year, num_nodes):
|
|
40 |
edge_15 = edges.copy()
|
41 |
teacher_hadiths = edge_15[['Teacher', 'Hadiths']].groupby('Teacher').sum().reset_index()
|
42 |
net = Network()
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
for _, row in edge_15.iterrows():
|
44 |
source = row['Teacher']
|
45 |
target = row['Student']
|
46 |
attribute_value = row['Hadiths']
|
47 |
edge_color = value_to_hex(attribute_value)
|
48 |
hadith_count = teacher_hadiths[teacher_hadiths['Teacher'] == source]['Hadiths'].to_list()[0]
|
|
|
|
|
|
|
|
|
49 |
|
50 |
-
|
51 |
-
|
|
|
|
|
52 |
net.add_edge(source, target, color=edge_color, value=attribute_value)
|
|
|
|
|
|
|
53 |
|
54 |
|
55 |
net.barnes_hut(gravity=-5000, central_gravity=0.3, spring_length=200)
|
|
|
40 |
edge_15 = edges.copy()
|
41 |
teacher_hadiths = edge_15[['Teacher', 'Hadiths']].groupby('Teacher').sum().reset_index()
|
42 |
net = Network()
|
43 |
+
# Create a dictionary to store node colors based on attribute values
|
44 |
+
node_colors = {}
|
45 |
+
# Maintain a set to track source nodes
|
46 |
+
source_nodes = set()
|
47 |
+
|
48 |
+
|
49 |
for _, row in edge_15.iterrows():
|
50 |
source = row['Teacher']
|
51 |
target = row['Student']
|
52 |
attribute_value = row['Hadiths']
|
53 |
edge_color = value_to_hex(attribute_value)
|
54 |
hadith_count = teacher_hadiths[teacher_hadiths['Teacher'] == source]['Hadiths'].to_list()[0]
|
55 |
+
if source not in source_nodes:
|
56 |
+
node_colors[source] = value_to_hex(hadith_count)
|
57 |
+
source_nodes.add(source)
|
58 |
+
net.add_node(source, color=value_to_hex(hadith_count), font={'size': 30, 'color': 'orange'})
|
59 |
|
60 |
+
if target not in node_colors:
|
61 |
+
node_colors[target] = value_to_hex(attribute_value)
|
62 |
+
net.add_node(target, color=value_to_hex(attribute_value), font={'size': 20, 'color': 'red'})
|
63 |
+
edge_color = value_to_hex(attribute_value)
|
64 |
net.add_edge(source, target, color=edge_color, value=attribute_value)
|
65 |
+
#net.add_node(source, color=value_to_hex(hadith_count), font = {'size':30, 'color': 'orange'})
|
66 |
+
#net.add_node(target, color=value_to_hex(attribute_value) , font = {'size': 20, 'color': 'red'})
|
67 |
+
#net.add_edge(source, target, color=edge_color, value=attribute_value)
|
68 |
|
69 |
|
70 |
net.barnes_hut(gravity=-5000, central_gravity=0.3, spring_length=200)
|