Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -40,10 +40,9 @@ 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 |
-
|
|
|
44 |
node_colors = {}
|
45 |
-
# Maintain a set to track source nodes
|
46 |
-
source_nodes = set()
|
47 |
|
48 |
|
49 |
for _, row in edge_15.iterrows():
|
@@ -52,12 +51,13 @@ def network_visualizer(city, year, num_nodes):
|
|
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
|
|
|
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
|
|
|
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)
|
|
|
40 |
edge_15 = edges.copy()
|
41 |
teacher_hadiths = edge_15[['Teacher', 'Hadiths']].groupby('Teacher').sum().reset_index()
|
42 |
net = Network()
|
43 |
+
# Create dictionaries to store node roles and colors based on attribute values
|
44 |
+
node_roles = {}
|
45 |
node_colors = {}
|
|
|
|
|
46 |
|
47 |
|
48 |
for _, row in edge_15.iterrows():
|
|
|
51 |
attribute_value = row['Hadiths']
|
52 |
edge_color = value_to_hex(attribute_value)
|
53 |
hadith_count = teacher_hadiths[teacher_hadiths['Teacher'] == source]['Hadiths'].to_list()[0]
|
54 |
+
if source not in node_roles or node_roles[source] == "source":
|
55 |
+
node_roles[source] = "source"
|
56 |
node_colors[source] = value_to_hex(hadith_count)
|
|
|
57 |
net.add_node(source, color=value_to_hex(hadith_count), font={'size': 30, 'color': 'orange'})
|
58 |
|
59 |
+
if target not in node_roles or node_roles[target] == "target":
|
60 |
+
node_roles[target] = "target"
|
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)
|