-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
534 lines (440 loc) · 17.2 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
import data
import matplotlib
import matplotlib.pyplot as plt
import pandas as pd
from flask import Flask, redirect, render_template, request, send_file, url_for
from PIL import Image
app = Flask(__name__)
matplotlib.use("Agg")
@app.route("/")
def main_page():
main_logo = url_for("static", filename="images/dark_logo.png")
main_title = url_for("static", filename="images/innopolis_title.png")
arrow = url_for("static", filename="images/arrow_up.jpg")
number1 = url_for("static", filename="images/1.jpg")
number2 = url_for("static", filename="images/2.jpg")
number3 = url_for("static", filename="images/3.jpg")
number4 = url_for("static", filename="images/4.jpg")
return render_template(
"base.html",
title="Bibliogram",
main_logo=main_logo,
main_title=main_title,
arrowUp=arrow,
number1=number1,
number2=number2,
number3=number3,
number4=number4,
amount_of_publications=data.uni.num_publications,
number_of_researches=data.uni.num_researchers,
publications_per_person=data.uni.public_per_person,
citations_per_person=data.uni.cit_per_person,
)
@app.route("/search", methods=["POST", "GET"])
def search_author():
authors = data.authors.rename(columns=lambda x: x[0].upper() + x[1:])
filt = authors["Institution"].str.contains("Innopolis University")
authors = authors.loc[filt].sort_values(by="Overall_citations", ascending=False)
main_logo = url_for("static", filename="images/dark_logo.png")
main_title = url_for("static", filename="images/innopolis_title.png")
arrow = url_for("static", filename="images/arrow_up.jpg")
def to_list(arg):
return list(arg)
if request.method == "POST":
author_name = request.form["author"]
filt = (
authors["Name"].apply(lambda x: x.lower()).str.contains(author_name.lower())
)
authors = authors.loc[filt]
return render_template(
"search_page.html",
title="Search for authors",
authors=authors.set_index("Id"),
list=list(authors["Id"].values),
add_data=data.authors_add,
photos=data.authors_photos,
main_logo=main_logo,
main_title=main_title,
to_list=to_list,
arrowUp=arrow,
)
@app.route("/author_id=<int:id>")
def author(id):
mains_logo = url_for("static", filename="images/dark_logo.png")
mains_title = url_for("static", filename="images/innopolis_title.png")
authors_data = data.authors.set_index("id")
authors_data = authors_data.loc[id]
citations = authors_data["citations"]
citations_max = int(citations[max(citations, key=citations.get)])
papers_published = authors_data["papers_published"]
papers_published_max = int(
papers_published[max(papers_published, key=papers_published.get)]
)
myList2 = citations.items()
myList2 = sorted(myList2)
x2, y2 = zip(*myList2)
x2 = list(x2)
y2 = list(y2)
y_plot = pd.Series(y2)
fig = plt.figure(figsize=(16, 12))
ax = y_plot.plot(kind="bar", color="#036e8e", width=0.08)
ax.set_xticklabels(x2)
for label in ax.get_xticklabels() + ax.get_yticklabels():
label.set_fontsize(20)
rects = ax.patches
for rect2, label in zip(rects, y2):
height = rect2.get_height()
ax.text(
rect2.get_x() + rect2.get_width() / 2,
height + citations_max / 80,
label,
ha="center",
va="baseline",
family="Arial",
size=23.5,
)
ax.plot(x2, y2, "#004", lw=2)
fig.savefig("static/images/graphic_author_citations.png")
plt.close(fig)
im = Image.open("static/images/graphic_author_citations.png")
width, height = im.size
im1 = im.crop((110, 130, width - 150, height - 30))
im1.save("static/images/graphic_author_citations.png")
myList = papers_published.items()
myList = sorted(myList)
x, y = zip(*myList)
x = list(x)
y = list(y)
y_plot = pd.Series(y)
fig = plt.figure(figsize=(16, 12))
ax = y_plot.plot(kind="bar", color="#036e8e", width=0.08)
ax.set_xticklabels(x)
for label in ax.get_xticklabels() + ax.get_yticklabels():
label.set_fontsize(20)
rects = ax.patches
for rect, label in zip(rects, y):
height = rect.get_height()
ax.text(
rect.get_x() + rect.get_width() / 2,
height + papers_published_max / 200,
label,
ha="center",
va="bottom",
family="Arial",
size=23.5,
)
ax.plot(x, y, "#004", lw=2)
fig.savefig("static/images/graphic_author_papers.png")
plt.close(fig)
im = Image.open("static/images/graphic_author_papers.png")
width, height = im.size
im1 = im.crop((110, 130, width - 150, height - 30))
im1.save("static/images/graphic_author_papers.png")
if authors_data["name"] in list(data.authors_add["name"].values):
authors_add = data.authors_add.set_index("name")
if_photo = True
photo_link = authors_add.loc[authors_data["name"]]["photo_link"]
if authors_add.loc[authors_data["name"]]["department"] != "No department":
department = authors_add.loc[authors_data["name"]]["department"]
else:
department = ""
disciplines = authors_add.loc[authors_data["name"]]["disciplines"]
else:
if_photo = False
photo_link = ""
department = ""
disciplines = []
return render_template(
"author_page.html",
author=authors_data,
id=id,
if_photo=if_photo,
photo_link=photo_link,
department=department,
disciplines=disciplines,
photos=data.authors_photos,
main_logo=mains_logo,
main_title=mains_title,
)
@app.route("/publications/page=<int:num>", methods=["POST", "GET"])
def publications(num): # pragma: no cover
main_logo = url_for("static", filename="images/dark_logo.png")
main_title = url_for("static", filename="images/innopolis_title.png")
arrow_left = url_for("static", filename="images/arrow_left.jpg")
arrow_right = url_for("static", filename="images/arrow_right.jpg")
arrow = arrow = url_for("static", filename="images/arrow_up.jpg")
# dataframe modification for further displaying
data.page_check("general_publications")
all_papers = data.data_modification(data.publications)
if request.method == "POST":
if "filtration" in request.form:
data.date_filter = data.date_check_with(request.form.getlist("date_filter"))
data.source_filter = data.source_check_with(
request.form.getlist("source_filter")
)
data.quart_filter = data.quart_check_with(
list(map(int, request.form.getlist("quartile_filter")))
)
if request.form["citations_from"]:
cit_from = int(request.form["citations_from"])
else:
cit_from = 0
if request.form["citations_to"]:
cit_to = int(request.form["citations_to"])
else:
cit_to = 100000
data.citations_from, data.citations_to = data.cit_check_with(
cit_from, cit_to
)
all_papers = data.data_modification(data.publications)
elif "parameters" in request.form:
data.parameters = sum(
[["Authors Names"], ["Title"], request.form.getlist("show")], list()
)
all_papers = data.data_modification(data.publications)
elif "sorting" in request.form:
data.sorting = data.sorting_check_with(request.form["sort"])
if request.form.get("order"):
data.order = False
else:
data.order = True
all_papers = data.data_modification(data.publications)
elif "downloading" in request.form:
file_type = request.form["download"]
data.download_file(all_papers, file_type)
return send_file(app.root_path + "\\downloads\\download." + file_type)
elif "page" in request.form:
new_num = int(request.form["page"])
print(new_num)
if new_num > 0 and new_num * 20 - all_papers.shape[0] <= 20:
return redirect("/publications/page=" + str(new_num))
else:
return redirect("/publications/page=" + str(num))
return render_template(
"publications_page.html",
papers=all_papers,
main_logo=main_logo,
main_title=main_title,
arrow_left=arrow_left,
arrow_right=arrow_right,
page_num=num,
arrowUp=arrow,
)
@app.route("/co-author=<int:id>", methods=["POST", "GET"])
def co_authors(id):
main_logo = url_for("static", filename="images/dark_logo.png")
main_title = url_for("static", filename="images/innopolis_title.png")
authors_data = data.authors
author_data = authors_data.set_index("id").loc[id]
filt = data.publications["Authors Names"].str.contains(author_data["name"])
author_papers = data.publications.loc[filt]
list_ind = list(author_papers.index)
co_authors_list = []
for ind in list_ind:
co_authors_list.append(author_papers.loc[ind]["Authors ID"])
co_authors_list = list(set(sum(co_authors_list, list())))
co_authors_list.remove(id)
co_au_names = "Co-Authors Names"
authors_id = "ID"
joint_pub = "Quantity of joint publications"
affil = "Affiliation"
co_authors_data = {authors_id: [], co_au_names: [], joint_pub: [], affil: []}
for au_id in co_authors_list:
com_papers = 0
affiliation = []
for ind in list_ind:
if au_id in author_papers.loc[ind]["Authors ID"]:
com_papers += 1
affiliation.append(
eval(author_papers.loc[ind]["Authors Affiliation"])[str(au_id)]
)
affiliation = ", ".join(set(sum(affiliation, list())))
if au_id in list(authors_data["id"].values):
temp_list = co_authors_data.get(authors_id)
temp_list.append(au_id)
co_authors_data[authors_id] = temp_list
temp_list = co_authors_data.get(co_au_names)
temp_list.append(authors_data.set_index("id").loc[au_id]["name"])
co_authors_data[co_au_names] = temp_list
temp_list = co_authors_data.get(joint_pub)
temp_list.append(com_papers)
co_authors_data[joint_pub] = temp_list
temp_list = co_authors_data.get(affil)
temp_list.append(affiliation)
co_authors_data[affil] = temp_list
co_authors_data = (
pd.DataFrame(co_authors_data)
.set_index("ID")
.sort_values(by=joint_pub, ascending=False)
)
if request.method == "POST":
file_type = request.form["download"]
data.download_file(co_authors_data, file_type)
return send_file(app.root_path + "\\downloads\\download." + file_type)
return render_template(
"co-author.html",
author_name=author_data["name"],
co_authors_id=list(co_authors_data.index),
co_authors=co_authors_data,
id=id,
main_logo=main_logo,
main_title=main_title,
)
@app.route("/author_publications=<int:id>", methods=["POST", "GET"])
def author_publications(id): # pragma: no cover
main_logo = url_for("static", filename="images/dark_logo.png")
main_title = url_for("static", filename="images/innopolis_title.png")
author_data = data.authors.set_index("id")
author_data = author_data.loc[id]
# dataframe modification for further displaying
data.page_check(author_data["name"])
filt = data.publications["Authors Names"].str.contains(author_data["name"])
papers = data.data_modification(data.publications.loc[filt])
if request.method == "POST":
if "filtration" in request.form:
data.source_filter = data.source_check_with(
request.form.getlist("source_filter")
)
data.date_filter = data.date_check_with(request.form.getlist("date_filter"))
data.quart_filter = data.quart_check_with(
list(map(int, request.form.getlist("quartile_filter")))
)
if request.form["citations_to"]:
cit_to = int(request.form["citations_to"])
else:
cit_to = 100000
if request.form["citations_from"]:
cit_from = int(request.form["citations_from"])
else:
cit_from = 0
data.citations_from, data.citations_to = data.cit_check_with(
cit_from, cit_to
)
papers = data.data_modification(data.publications.loc[filt])
elif "parameters" in request.form:
data.parameters = sum(
[["Authors Names"], ["Title"], request.form.getlist("show")], list()
)
papers = data.data_modification(data.publications.loc[filt])
elif "sorting" in request.form:
data.sorting = data.sorting_check_with(request.form["sort"])
if request.form.get("order"):
data.order = False
else:
data.order = True
papers = data.data_modification(data.publications.loc[filt])
elif "downloading" in request.form:
file_type = request.form["download"]
data.download_file(papers, file_type)
return send_file(app.root_path + "\\downloads\\download." + file_type)
return render_template(
"author_publications.html",
author=author_data,
id=id,
papers=papers,
main_logo=main_logo,
main_title=main_title,
arrowUp=url_for("static", filename="images/arrow_up.jpg"),
)
@app.route("/refresh")
def refresh():
main_logo = url_for("static", filename="images/dark_logo.png")
main_title = url_for("static", filename="images/innopolis_title.png")
date = data.cur_date
return render_template(
"refresh_page.html",
main_logo=main_logo,
main_title=main_title,
date=date,
)
@app.route("/general", methods=["POST", "GET"])
def general():
main_logo = url_for("static", filename="images/dark_logo.png")
main_title = url_for("static", filename="images/innopolis_title.png")
filt = data.publications["Affiliation"].str.contains("Innopolis University")
papers = data.publications.loc[filt]
indicators_names = [
"Number of all publications",
"Articles",
"Books",
"Book Chapters",
"Conference Papers",
"Reviews",
"Short Surveys",
"Others",
"Scopus",
"Q1 & Q2",
"Number of citations",
">10",
"5-9",
"1-4",
"0",
]
info = pd.DataFrame(indicators_names, columns=["Indicators"])
for year in range(2016, 2023):
year_filt = papers["Publication Date"].apply(lambda x: x[:4]) == str(year)
temp_papers = papers.loc[year_filt]
info_param = [temp_papers.shape[0]]
number = 0
for type in indicators_names[1:7]:
type = type[:-1]
add_filt = temp_papers["Work Type"] == type
info_param.append(temp_papers.loc[add_filt].shape[0])
number += info_param[-1]
info_param.append(temp_papers.shape[0] - number)
info_param.append(temp_papers.shape[0])
add_filt = (temp_papers["Quartile"] == 1) | (temp_papers["Quartile"] == 2)
info_param.append(temp_papers.loc[add_filt].shape[0])
info_param.append(sum(list(temp_papers["Citations"].values)))
add_filt = temp_papers["Citations"] > 10
info_param.append(temp_papers.loc[add_filt].shape[0])
add_filt = (temp_papers["Citations"] > 4) & (temp_papers["Quartile"] < 10)
info_param.append(temp_papers.loc[add_filt].shape[0])
add_filt = (temp_papers["Citations"] > 0) & (temp_papers["Quartile"] < 5)
info_param.append(temp_papers.loc[add_filt].shape[0])
add_filt = temp_papers["Citations"] == 0
info_param.append(temp_papers.loc[add_filt].shape[0])
info[year] = info_param
if request.method == "POST":
file_type = request.form["download"]
data.download_file(info, file_type)
return send_file(app.root_path + "\\downloads\\download." + file_type)
add_filt_1 = info["Indicators"] == "Number of all publications"
info_1 = info.loc[add_filt_1]
types = [
"Articles",
"Books",
"Book Chapters",
"Conference Papers",
"Reviews",
"Short Surveys",
"Others",
]
add_filt_2 = info["Indicators"].isin(types)
info_2 = info.loc[add_filt_2]
scopus = [
"Scopus",
"Q1 & Q2",
"Number of citations",
]
add_filt_3 = info["Indicators"].isin(scopus)
info_3 = info.loc[add_filt_3]
citations = [
">10",
"5-9",
"1-4",
"0",
]
add_filt_4 = info["Indicators"].isin(citations)
info_4 = info.loc[add_filt_4]
return render_template(
"general.html",
main_logo=main_logo,
main_title=main_title,
info_1=info_1,
info_2=info_2,
info_3=info_3,
info_4=info_4,
)
if __name__ == "__main__":
app.run(port=8080, host="0.0.0.0")