FDSRashid commited on
Commit
248b1ce
ยท
verified ยท
1 Parent(s): cdbb8ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -19
app.py CHANGED
@@ -153,31 +153,56 @@ def visualize_subTaraf(df, yaxis):
153
  hadith = matn_info[matn_info['bookid_hadithid'].isin(df['bookid_hadithid'])]
154
  taraf_hadith_split = [i.split('_') for i in hadith['bookid_hadithid'].to_list()]
155
  hadith_cleaned = isnad_info['Hadiths Cleaned'].apply(lambda x: any(i in x for i in taraf_hadith_split))
156
- isnad_hadith = isnad_info[hadith_cleaned][['Source', 'Destination']]
157
- narrators = isnad_hadith.applymap(lambda x: narrator_bios[narrator_bios['Rawi ID'] == int(x)]['Famous Name'].to_list()).rename(columns={"Source": "Teacher", "Destination": "Student"})
158
- isnad_hadith["Student"] = narrators['Student']
159
- isnad_hadith["Teacher"] = narrators['Teacher']
160
- filtered = isnad_hadith[(isnad_hadith['Teacher'].apply(lambda x: len(x)) == 1) & (isnad_hadith['Student'].apply(lambda x: len(x)) == 1)]
161
- filtered['Student'] = filtered['Student'].apply(lambda x: x[0])
162
- filtered['Teacher'] = filtered['Teacher'].apply(lambda x: x[0])
163
  net = Network(directed =True)
164
- for _, row in filtered.iterrows():
165
- source = row['Teacher']
166
- target = row['Student']
167
  teacher_info = narrator_bios[narrator_bios['Rawi ID'] == int(row['Source'])]
168
  student_info = narrator_bios[narrator_bios['Rawi ID'] == int(row['Destination'])]
169
- isnad = isnad_info[(isnad_info['Source'] == row['Source']) & (isnad_info['Destination'] == row['Destination'])]
170
- teacher_narrations = teacher_info['Number of Narrations'].to_list()[0]
171
- student_narrations = student_info['Number of Narrations'].to_list()[0]
172
- teacher_gen = teacher_info['Generation'].to_list()[0]
173
- student_gen = student_info['Generation'].to_list()[0]
174
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  if row['Source'] == '99999':
176
- net.add_node(source, font = {'size':50, 'color': 'Black'}, color = '#000000')
177
  else:
178
- net.add_node(source, font = {'size':30, 'color': 'red'}, color = value_to_hex(teacher_narrations), label = f'{source} \n {teacher_info["Narrator Rank"].to_list()[0]} \n ID: {row["Source"]} - Gen {teacher_gen}')
179
- net.add_node(target, font = {'size': 30, 'color': 'red'}, color = value_to_hex(student_narrations), label = f'{target} \n{student_info["Narrator Rank"].to_list()[0]} \n ID: {row["Destination"]} - Gen {student_gen}')
180
- net.add_edge(source, target, color = value_to_hex(int(isnad[f'{yaxis} Count'].to_list()[0])), label = f"{isnad[f'{yaxis} Count'].to_list()[0]}")
181
  net.barnes_hut(gravity=-5000, central_gravity=0.3, spring_length=200)
182
  html = net.generate_html()
183
  html = html.replace("'", "\"")
 
153
  hadith = matn_info[matn_info['bookid_hadithid'].isin(df['bookid_hadithid'])]
154
  taraf_hadith_split = [i.split('_') for i in hadith['bookid_hadithid'].to_list()]
155
  hadith_cleaned = isnad_info['Hadiths Cleaned'].apply(lambda x: any(i in x for i in taraf_hadith_split))
156
+ isnad_hadith = isnad_info[hadith_cleaned]
157
+ isnad_hadith['Teacher'] = isnad_hadith['Source'].apply(lambda x: narrator_bios[narrator_bios['Rawi ID'].astype(int) == int(x)]['Famous Name'].to_list())
158
+ isnad_hadith['Student'] = isnad_hadith['Destination'].apply(lambda x: narrator_bios[narrator_bios['Rawi ID'].astype(int) == int(x)]['Famous Name'].to_list())
159
+ isnad_hadith['Teacher'] = isnad_hadith['Teacher'].apply(lambda x: x[0] if len(x)==1 else 'ูู„ุงู†')
160
+ isnad_hadith['Student'] = isnad_hadith['Student'].apply(lambda x: x[0] if len(x)==1 else 'ูู„ุงู†')
 
 
161
  net = Network(directed =True)
162
+ for _, row in isnad_hadith.iterrows():
163
+ source = row['Source']
164
+ target = row['Destination']
165
  teacher_info = narrator_bios[narrator_bios['Rawi ID'] == int(row['Source'])]
166
  student_info = narrator_bios[narrator_bios['Rawi ID'] == int(row['Destination'])]
 
 
 
 
 
167
 
168
+ teacher_narrations = teacher_info['Number of Narrations'].to_list()
169
+ if len(teacher_narrations):
170
+ teacher_narrations = teacher_narrations[0]
171
+ else:
172
+ teacher_narrations = row['Hadith Count']
173
+ student_narrations = student_info['Number of Narrations'].to_list()
174
+ if len(student_narrations):
175
+ student_narrations = student_narrations[0]
176
+ else:
177
+ student_narrations = row['Hadith Count']
178
+
179
+ teacher_gen = teacher_info['Generation'].to_list()
180
+ if len(teacher_gen):
181
+ teacher_gen = teacher_gen[0]
182
+ else:
183
+ teacher_gen = -1
184
+ student_gen = student_info['Generation'].to_list()
185
+ if len(student_gen):
186
+ student_gen = student_gen[0]
187
+ else:
188
+ student_gen = -1
189
+ teacher_rank = teacher_info["Narrator Rank"].to_list()
190
+ if len(teacher_rank):
191
+ teacher_rank = teacher_rank[0]
192
+ else:
193
+ teacher_rank = 'ูู„ุงู†'
194
+
195
+ student_rank = student_info["Narrator Rank"].to_list()
196
+ if len(student_rank):
197
+ student_rank = student_rank[0]
198
+ else:
199
+ student_rank = 'ูู„ุงู†'
200
  if row['Source'] == '99999':
201
+ net.add_node(source, font = {'size':50, 'color': 'Black'}, color = '#000000', label = f'{row["Teacher"]}')
202
  else:
203
+ 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}')
204
+ 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}')
205
+ net.add_edge(source, target, color = value_to_hex(int(row[f'{yaxis} Count'])), label = f"{row[f'{yaxis} Count']}")
206
  net.barnes_hut(gravity=-5000, central_gravity=0.3, spring_length=200)
207
  html = net.generate_html()
208
  html = html.replace("'", "\"")