FDSRashid commited on
Commit
6a7641c
·
verified ·
1 Parent(s): 0323a61

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -1
app.py CHANGED
@@ -308,6 +308,8 @@ def visualize_hadith_isnad(df, yaxis):
308
 
309
  def visualize_narrator_taraf(taraf_num, narrator, yaxis):
310
  taraf = matn_info[matn_info['taraf_ID'] == taraf_num]
 
 
311
  hadith_cleaned = isnad_info['Tarafs Cleaned'].apply(lambda x: taraf_num in x)
312
  isnad_hadith = isnad_info[hadith_cleaned]
313
  isnad_hadith['Teacher'] = isnad_hadith['Source'].apply(lambda x: narrator_bios[narrator_bios['Rawi ID'].astype(int) == int(x)]['Famous Name'].to_list())
@@ -326,12 +328,21 @@ def visualize_narrator_taraf(taraf_num, narrator, yaxis):
326
  isnad_pos = nx.nx_agraph.graphviz_layout(G, prog='dot')
327
 
328
  matns_with_narrator = []
 
329
  for i in range(len(taraf_hadith_split)):
330
  isnad_in_hadith1 = isnad_hadith['Hadiths Cleaned'].apply(lambda x: taraf_hadith_split[i] in x )
331
  isnad_hadith1 = isnad_hadith[isnad_in_hadith1]
332
  G1 = nx.from_pandas_edgelist(isnad_hadith1, source = 'Source', target = 'Destination', create_using = nx.DiGraph())
 
333
  if narrator in list(G1.nodes):
334
  matns_with_narrator.append(taraf_hadith[i])
 
 
 
 
 
 
 
335
 
336
  narrator_matn_info = taraf[taraf['bookid_hadithid'].isin(matns_with_narrator)]
337
 
@@ -368,6 +379,8 @@ def visualize_narrator_taraf(taraf_num, narrator, yaxis):
368
 
369
  if node == '99999':
370
  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)
 
 
371
  else:
372
  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)
373
  for edge in G.edges:
@@ -382,7 +395,7 @@ def visualize_narrator_taraf(taraf_num, narrator, yaxis):
382
  display-capture; encrypted-media;" sandbox="allow-modals allow-forms
383
  allow-scripts allow-same-origin allow-popups
384
  allow-top-navigation-by-user-activation allow-downloads" allowfullscreen=""
385
- allowpaymentrequest="" frameborder="0" srcdoc='{html}'></iframe>""" , narrator_matn_info[['matn', 'Book_Name', 'Author', 'Book_ID', 'Hadith Number']]
386
 
387
 
388
 
 
308
 
309
  def visualize_narrator_taraf(taraf_num, narrator, yaxis):
310
  taraf = matn_info[matn_info['taraf_ID'] == taraf_num]
311
+ num_hadith = taraf.shape[0]
312
+ taraf['Index'] = np.arange(num_hadith)
313
  hadith_cleaned = isnad_info['Tarafs Cleaned'].apply(lambda x: taraf_num in x)
314
  isnad_hadith = isnad_info[hadith_cleaned]
315
  isnad_hadith['Teacher'] = isnad_hadith['Source'].apply(lambda x: narrator_bios[narrator_bios['Rawi ID'].astype(int) == int(x)]['Famous Name'].to_list())
 
328
  isnad_pos = nx.nx_agraph.graphviz_layout(G, prog='dot')
329
 
330
  matns_with_narrator = []
331
+ end_node = {}
332
  for i in range(len(taraf_hadith_split)):
333
  isnad_in_hadith1 = isnad_hadith['Hadiths Cleaned'].apply(lambda x: taraf_hadith_split[i] in x )
334
  isnad_hadith1 = isnad_hadith[isnad_in_hadith1]
335
  G1 = nx.from_pandas_edgelist(isnad_hadith1, source = 'Source', target = 'Destination', create_using = nx.DiGraph())
336
+ node = [int(n) for n, d in G.out_degree() if d == 0]
337
  if narrator in list(G1.nodes):
338
  matns_with_narrator.append(taraf_hadith[i])
339
+ for n in node:
340
+ if n not in list(end_node.keys()):
341
+ end_node[n] = []
342
+ end_node[n].append(i)
343
+
344
+
345
+
346
 
347
  narrator_matn_info = taraf[taraf['bookid_hadithid'].isin(matns_with_narrator)]
348
 
 
379
 
380
  if node == '99999':
381
  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)
382
+ elif node in list(end_node.keys()):
383
+ 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 Hadiths {", ".join(end_node[node])}', x= pos[0]*x_stretch, y= -1*pos[1]*y_stretch, size= 50)
384
  else:
385
  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)
386
  for edge in G.edges:
 
395
  display-capture; encrypted-media;" sandbox="allow-modals allow-forms
396
  allow-scripts allow-same-origin allow-popups
397
  allow-top-navigation-by-user-activation allow-downloads" allowfullscreen=""
398
+ allowpaymentrequest="" frameborder="0" srcdoc='{html}'></iframe>""" , narrator_matn_info[['matn', 'Book_Name', 'Author', 'Book_ID', 'Hadith Number', 'Index']]
399
 
400
 
401