Spaces:
Sleeping
Sleeping
testing hierarchal graph format
Browse files
app.py
CHANGED
|
@@ -94,59 +94,46 @@ def visualize_isnad(taraf_num, yaxis):
|
|
| 94 |
isnad_hadith['Student'] = isnad_hadith['Student'].apply(lambda x: x[0] if len(x)==1 else 'ููุงู')
|
| 95 |
|
| 96 |
end_nodes = df['End Transmitter ID'].tolist()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
net = Network(directed =True)
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
student_info = narrator_bios[narrator_bios['Rawi ID'] == int(row['Destination'])]
|
| 103 |
-
|
| 104 |
-
teacher_narrations = teacher_info['Number of Narrations'].to_list()
|
| 105 |
-
if len(teacher_narrations):
|
| 106 |
-
teacher_narrations = teacher_narrations[0]
|
| 107 |
-
else:
|
| 108 |
-
teacher_narrations = row['Hadith Count']
|
| 109 |
-
student_narrations = student_info['Number of Narrations'].to_list()
|
| 110 |
if len(student_narrations):
|
| 111 |
student_narrations = student_narrations[0]
|
| 112 |
else:
|
| 113 |
-
student_narrations =
|
| 114 |
-
|
| 115 |
-
teacher_gen = teacher_info['Generation'].to_list()
|
| 116 |
-
if len(teacher_gen):
|
| 117 |
-
teacher_gen = teacher_gen[0]
|
| 118 |
-
else:
|
| 119 |
-
teacher_gen = -1
|
| 120 |
-
student_gen = student_info['Generation'].to_list()
|
| 121 |
if len(student_gen):
|
| 122 |
student_gen = student_gen[0]
|
| 123 |
else:
|
| 124 |
student_gen = -1
|
| 125 |
-
|
| 126 |
-
if len(teacher_rank):
|
| 127 |
-
teacher_rank = teacher_rank[0]
|
| 128 |
-
else:
|
| 129 |
-
teacher_rank = 'ููุงู'
|
| 130 |
-
|
| 131 |
-
student_rank = student_info["Narrator Rank"].to_list()
|
| 132 |
if len(student_rank):
|
| 133 |
student_rank = student_rank[0]
|
| 134 |
else:
|
| 135 |
student_rank = 'ููุงู'
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
end_matn_info = df[df["End Transmitter ID"] == source]
|
| 140 |
-
net.add_node(source, font = {'size':30, 'color': 'red'}, color = value_to_hex(teacher_narrations), label = f'{row["Teacher"]} \n {teacher_rank} \n ID: {row["Source"]} - Gen {teacher_gen} \n Hadith {" ".join(end_matn_info["Hadith Number"].tolist())}')
|
| 141 |
else:
|
| 142 |
-
|
| 143 |
-
if
|
| 144 |
-
|
| 145 |
-
|
|
|
|
|
|
|
| 146 |
else:
|
| 147 |
-
net.add_node(
|
|
|
|
|
|
|
|
|
|
| 148 |
net.add_edge(source, target, color = value_to_hex(int(row[f'{yaxis} Count'])), label = f"{row[f'{yaxis} Count']}")
|
| 149 |
-
net.
|
| 150 |
html = net.generate_html()
|
| 151 |
html = html.replace("'", "\"")
|
| 152 |
return f"""<iframe style="width: 100%; height: 600px;margin:0 auto" name="result" allow="midi; geolocation; microphone; camera;
|
|
@@ -154,6 +141,66 @@ def visualize_isnad(taraf_num, yaxis):
|
|
| 154 |
allow-scripts allow-same-origin allow-popups
|
| 155 |
allow-top-navigation-by-user-activation allow-downloads" allowfullscreen=""
|
| 156 |
allowpaymentrequest="" frameborder="0" srcdoc='{html}'></iframe>""" , df
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
|
| 158 |
def taraf_booknum(taraf_num):
|
| 159 |
taraf = matn_info[matn_info['taraf_ID'] == taraf_num]
|
|
|
|
| 94 |
isnad_hadith['Student'] = isnad_hadith['Student'].apply(lambda x: x[0] if len(x)==1 else 'ููุงู')
|
| 95 |
|
| 96 |
end_nodes = df['End Transmitter ID'].tolist()
|
| 97 |
+
G = nx.from_pandas_edgelist(isnad_hadith, source = 'Source', target = 'Destination', create_using = nx.DiGraph())
|
| 98 |
+
isnad_pos = nx.nx_agraph.graphviz_layout(G, prog='dot')
|
| 99 |
+
x_stretch = 4
|
| 100 |
+
y_stretch = 4
|
| 101 |
net = Network(directed =True)
|
| 102 |
+
|
| 103 |
+
for node, pos in isnad_pos.items():
|
| 104 |
+
node_info = narrator_bios[narrator_bios['Rawi ID'] == int(node)]
|
| 105 |
+
student_narrations = node_info['Number of Narrations'].to_list()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
if len(student_narrations):
|
| 107 |
student_narrations = student_narrations[0]
|
| 108 |
else:
|
| 109 |
+
student_narrations = 1
|
| 110 |
+
student_gen = node_info['Generation'].to_list()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
if len(student_gen):
|
| 112 |
student_gen = student_gen[0]
|
| 113 |
else:
|
| 114 |
student_gen = -1
|
| 115 |
+
student_rank = node_info["Narrator Rank"].to_list()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
if len(student_rank):
|
| 117 |
student_rank = student_rank[0]
|
| 118 |
else:
|
| 119 |
student_rank = 'ููุงู'
|
| 120 |
+
node_name = node_info['Famous Name'].to_list()
|
| 121 |
+
if len(node_name):
|
| 122 |
+
node_name = node_name[0]
|
|
|
|
|
|
|
| 123 |
else:
|
| 124 |
+
node_name = 'ููุงู'
|
| 125 |
+
if node == '99999':
|
| 126 |
+
net.add_node(node, font = {'size':50, 'color': 'black'}, color = '#000000', label = f'{node_name} \n ID: {node} - Gen {student_gen}', x= pos[0]*x_stretch, y= -1*pos[1]*y_stretch, size= 70)
|
| 127 |
+
elif node in end_nodes:
|
| 128 |
+
end_matn_info = df[df["End Transmitter ID"] == source]
|
| 129 |
+
net.add_node(node, font = {'size':30, 'color': 'red'}, color = value_to_hex(student_narrations), label = f'{node_name} \n {student_rank} \n ID: {node} - Gen {student_gen} \n Hadith {" ".join(end_matn_info["Hadith Number"].tolist())}', x= pos[0]*x_stretch, y= -1*pos[1]*y_stretch, size= 50)
|
| 130 |
else:
|
| 131 |
+
net.add_node(node, font = {'size':30, 'color': 'red'}, color = value_to_hex(student_narrations), label = f'{node_name} \n {student_rank} \n ID: {node} - Gen {student_gen}', x= pos[0]*x_stretch, y= -1*pos[1]*y_stretch, size= 50)
|
| 132 |
+
for _, row in isnad_hadith.iterrows():
|
| 133 |
+
source = row['Source']
|
| 134 |
+
target = row['Destination']
|
| 135 |
net.add_edge(source, target, color = value_to_hex(int(row[f'{yaxis} Count'])), label = f"{row[f'{yaxis} Count']}")
|
| 136 |
+
net.toggle_physics(False)
|
| 137 |
html = net.generate_html()
|
| 138 |
html = html.replace("'", "\"")
|
| 139 |
return f"""<iframe style="width: 100%; height: 600px;margin:0 auto" name="result" allow="midi; geolocation; microphone; camera;
|
|
|
|
| 141 |
allow-scripts allow-same-origin allow-popups
|
| 142 |
allow-top-navigation-by-user-activation allow-downloads" allowfullscreen=""
|
| 143 |
allowpaymentrequest="" frameborder="0" srcdoc='{html}'></iframe>""" , df
|
| 144 |
+
|
| 145 |
+
# for _, row in isnad_hadith.iterrows():
|
| 146 |
+
# source = row['Source']
|
| 147 |
+
# target = row['Destination']
|
| 148 |
+
# teacher_info = narrator_bios[narrator_bios['Rawi ID'] == int(row['Source'])]
|
| 149 |
+
# student_info = narrator_bios[narrator_bios['Rawi ID'] == int(row['Destination'])]
|
| 150 |
+
|
| 151 |
+
# teacher_narrations = teacher_info['Number of Narrations'].to_list()
|
| 152 |
+
# if len(teacher_narrations):
|
| 153 |
+
# teacher_narrations = teacher_narrations[0]
|
| 154 |
+
# else:
|
| 155 |
+
# teacher_narrations = row['Hadith Count']
|
| 156 |
+
# student_narrations = student_info['Number of Narrations'].to_list()
|
| 157 |
+
# if len(student_narrations):
|
| 158 |
+
# student_narrations = student_narrations[0]
|
| 159 |
+
# else:
|
| 160 |
+
# student_narrations = row['Hadith Count']
|
| 161 |
+
|
| 162 |
+
# teacher_gen = teacher_info['Generation'].to_list()
|
| 163 |
+
# if len(teacher_gen):
|
| 164 |
+
# teacher_gen = teacher_gen[0]
|
| 165 |
+
# else:
|
| 166 |
+
# teacher_gen = -1
|
| 167 |
+
# student_gen = student_info['Generation'].to_list()
|
| 168 |
+
# if len(student_gen):
|
| 169 |
+
# student_gen = student_gen[0]
|
| 170 |
+
# else:
|
| 171 |
+
# student_gen = -1
|
| 172 |
+
# teacher_rank = teacher_info["Narrator Rank"].to_list()
|
| 173 |
+
# if len(teacher_rank):
|
| 174 |
+
# teacher_rank = teacher_rank[0]
|
| 175 |
+
# else:
|
| 176 |
+
# teacher_rank = 'ููุงู'
|
| 177 |
+
|
| 178 |
+
# student_rank = student_info["Narrator Rank"].to_list()
|
| 179 |
+
# if len(student_rank):
|
| 180 |
+
# student_rank = student_rank[0]
|
| 181 |
+
# else:
|
| 182 |
+
# student_rank = 'ููุงู'
|
| 183 |
+
# if row['Source'] == '99999':
|
| 184 |
+
# net.add_node(source, font = {'size':50, 'color': 'Black'}, color = '#000000', label = f'{row["Teacher"]}')
|
| 185 |
+
# elif source in end_nodes:
|
| 186 |
+
# end_matn_info = df[df["End Transmitter ID"] == source]
|
| 187 |
+
# net.add_node(source, font = {'size':30, 'color': 'red'}, color = value_to_hex(teacher_narrations), label = f'{row["Teacher"]} \n {teacher_rank} \n ID: {row["Source"]} - Gen {teacher_gen} \n Hadith {" ".join(end_matn_info["Hadith Number"].tolist())}')
|
| 188 |
+
# else:
|
| 189 |
+
# net.add_node(source, font = {'size':30, 'color': 'red'}, color = value_to_hex(teacher_narrations), label = f'{row["Teacher"]} \n {teacher_rank} \n ID: {row["Source"]} - Gen {teacher_gen}')
|
| 190 |
+
# if target in end_nodes:
|
| 191 |
+
# end_matn_info = df[df["End Transmitter ID"] == target]
|
| 192 |
+
# net.add_node(target, font = {'size': 30, 'color': 'red'}, color = value_to_hex(student_narrations), label = f'{row["Student"]} \n{student_rank} \n ID: {row["Destination"]} - Gen {student_gen} \n Hadith {" ".join(end_matn_info["Hadith Number"].tolist())}')
|
| 193 |
+
# else:
|
| 194 |
+
# net.add_node(target, font = {'size': 30, 'color': 'red'}, color = value_to_hex(student_narrations), label = f'{row["Student"]} \n{student_rank} \n ID: {row["Destination"]} - Gen {student_gen}')
|
| 195 |
+
# net.add_edge(source, target, color = value_to_hex(int(row[f'{yaxis} Count'])), label = f"{row[f'{yaxis} Count']}")
|
| 196 |
+
# net.barnes_hut(gravity=-5000, central_gravity=0.3, spring_length=200)
|
| 197 |
+
# html = net.generate_html()
|
| 198 |
+
# html = html.replace("'", "\"")
|
| 199 |
+
# return f"""<iframe style="width: 100%; height: 600px;margin:0 auto" name="result" allow="midi; geolocation; microphone; camera;
|
| 200 |
+
# display-capture; encrypted-media;" sandbox="allow-modals allow-forms
|
| 201 |
+
# allow-scripts allow-same-origin allow-popups
|
| 202 |
+
# allow-top-navigation-by-user-activation allow-downloads" allowfullscreen=""
|
| 203 |
+
# allowpaymentrequest="" frameborder="0" srcdoc='{html}'></iframe>""" , df
|
| 204 |
|
| 205 |
def taraf_booknum(taraf_num):
|
| 206 |
taraf = matn_info[matn_info['taraf_ID'] == taraf_num]
|