-
Notifications
You must be signed in to change notification settings - Fork 1
/
InstitutionsApp.py
805 lines (720 loc) · 32 KB
/
InstitutionsApp.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
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
from sds.sdsBase import sdsPluginBase, endpoint
from bson import ObjectId
from pymongo import ASCENDING,DESCENDING
from pickle import load
from datetime import date
from math import log,exp
from flask import redirect
import json
from numpy import quantile
class InstitutionsApp(sdsPluginBase):
def __init__(self, sds):
super().__init__(sds)
def get_info(self,idx,start_year=None,end_year=None):
initial_year=9999
final_year = 0
if start_year:
try:
start_year=int(start_year)
except:
print("Could not convert start year to int")
return None
if end_year:
try:
end_year=int(end_year)
except:
print("Could not convert end year to int")
return None
institution = self.colav_db['affiliations'].find_one({"types.type":{"$ne":"group"},"_id":ObjectId(idx)})
if institution:
name=""
for n in institution["names"]:
if n["lang"]=="es":
name=n["name"]
break
elif n["lang"]=="en":
name=n["name"]
logo=""
for ext in institution["external_urls"]:
if ext["source"]=="logo":
logo=ext["url"]
entry={"id":institution["_id"],
"name":name,
"citations":institution["citations_count"],
"external_urls":[ext for ext in institution["external_urls"] if ext["source"]!="logo"],
"logo":logo,
"policies":{}
}
index_list=[]
if "policies" in institution.keys():
for policy in institution["policies"]:
policy_reg=self.colav_db["policies"].find_one({"_id":policy["id"]})
policy_entry={
"id":policy["id"],
"index":"",
"name":policy["name"]
}
if len(policy_reg["index"])>0:
indexes=[]
for index in policy_reg["index"]:
indexes.append(index["index"])
policy_entry["index"]+=str(int(index["index"]))+"."
index_list.append(indexes)
policy_entry["index"]=policy_entry["index"][:-1]
if policy_reg["abbreviations"][0] in entry["policies"].keys():
entry["policies"][policy_reg["abbreviations"][0]].append(policy_entry)
else:
entry["policies"][policy_reg["abbreviations"][0]]=[policy_entry]
if "ODS" in entry["policies"].keys():
sorted_ods=sorted(entry["policies"]["ODS"],key=lambda x:index_list[entry["policies"]["ODS"].index(x)])
entry["policies"]["ODS"]=sorted_ods
filters={"years":{}}
for reg in self.colav_db["works"].find({"authors.affiliations.id":ObjectId(idx),"year_published":{"$exists":1}}).sort([("year_published",ASCENDING)]).limit(1):
filters["years"]["start_year"]=reg["year_published"]
for reg in self.colav_db["works"].find({"authors.affiliations.id":ObjectId(idx),"year_published":{"$exists":1}}).sort([("year_published",DESCENDING)]).limit(1):
filters["years"]["end_year"]=reg["year_published"]
return {"data": entry, "filters": filters }
else:
return None
def get_coauthors(self,idx=None,start_year=None,end_year=None,page=1,max_results=100):
geojson=json.load(open("sds/etc/world_map.json","r"))
initial_year=0
final_year=0
if start_year:
try:
start_year=int(start_year)
except:
print("Could not convert start year to int")
return None
if end_year:
try:
end_year=int(end_year)
except:
print("Could not convert end year to int")
return None
if idx:
pipeline=[
{"$match":{"authors.affiliations.id":ObjectId(idx)}}
]
if start_year and not end_year:
pipeline=[
{"$match":{"year_published":{"$gte":start_year},"authors.affiliations.id":ObjectId(idx)}}
]
elif end_year and not start_year:
pipeline=[
{"$match":{"year_published":{"$lte":end_year},"authors.affiliations.id":ObjectId(idx)}}
]
elif start_year and end_year:
pipeline=[
{"$match":{"year_published":{"$gte":start_year,"$lte":end_year},"authors.affiliations.id":ObjectId(idx)}}
]
pipeline.extend([
{"$unwind":"$authors"},
{"$group":{"_id":"$authors.id","count":{"$sum":1}}},
{"$sort":{"count":-1}},
{"$lookup":{"from":"person","localField":"_id","foreignField":"_id","as":"author"}},
{"$project":{"count":1,"author.full_name":1,"author.affiliations":1}},
{"$unwind":"$author"}
])
entry={
"coauthors":[],
"geo":[]
}
affiliations_ids=[]
for reg in self.colav_db["works"].aggregate(pipeline):
inst_id = ""
inst_name = ""
group_id=""
group_name=""
if str(reg["_id"])==str(idx):
continue
if "affiliations" in reg["author"].keys():
for aff in reg["author"]["affiliations"]:
if "types" in aff.keys():
for typ in aff["types"]:
if typ["type"]!="group":
inst_name=aff["name"]
inst_id=aff["id"]
if inst_id:
if inst_id in affiliations_ids:
entry["coauthors"][affiliations_ids.index(inst_id)]["count"]+=reg["count"]
else:
entry["coauthors"].append(
{
"name":inst_name,
"id":inst_id,
"count":reg["count"]
}
)
affiliations_ids.append(inst_id)
entry["coauthors"]=sorted(entry["coauthors"],key=lambda x:x["count"],reverse=True)
countries={}
country_list=[]
pipeline=[pipeline[0]]
pipeline.extend([
{"$project":{"count":1,"affiliation.addresses.country_code":1,"affiliation.addresses.country":1,"authors.affiliations.id":1}},
{"$unwind":"$authors"},
{"$group":{"_id":"$authors.affiliations.id","count":{"$sum":1}}},
{"$unwind":"$_id"},
{"$lookup":{"from":"affiliations","localField":"_id","foreignField":"_id","as":"affiliation"}},
{"$unwind":"$affiliation"},
{"$unwind":"$affiliation.addresses"}
])
for reg in self.colav_db["works"].aggregate(pipeline,allowDiskUse=True):
if str(reg["_id"])==idx:
continue
if not "country_code" in reg["affiliation"]["addresses"].keys():
continue
if reg["affiliation"]["addresses"]["country_code"] and reg["affiliation"]["addresses"]["country"]:
alpha2=reg["affiliation"]["addresses"]["country_code"]
country_name=reg["affiliation"]["addresses"]["country"]
if alpha2 in countries.keys():
countries[alpha2]["count"]+=reg["count"]
else:
countries[alpha2]={
"count":reg["count"],
"name":country_name
}
for key,val in countries.items():
countries[key]["log_count"]=log(val["count"])
for i,feat in enumerate(geojson["features"]):
if feat["properties"]["country_code"] in countries.keys():
alpha2=feat["properties"]["country_code"]
geojson["features"][i]["properties"]["count"]=countries[alpha2]["count"]
geojson["features"][i]["properties"]["log_count"]=countries[alpha2]["log_count"]
entry["geo"]=geojson
db_reg=self.colav_db["affiliations"].find_one({"_id":ObjectId(idx)})
if db_reg:
if "coauthors_network" in db_reg.keys():
entry["coauthors_network"]=db_reg["coauthors_network"]
return {"data":entry}
def get_subjects(self,idx=None,start_year=None,end_year=None,limit=10):
initial_year=0
final_year=0
if not limit:
limit=10
else:
try:
limit=int(limit)
except:
print("Could not convert limit to int")
return None
if start_year:
try:
start_year=int(start_year)
except:
print("Could not convert start year to int")
return None
if end_year:
try:
end_year=int(end_year)
except:
print("Could not convert end year to int")
return None
if idx:
result=self.colav_db["affiliations"].find_one({"_id":ObjectId(idx)})
else:
return None
if not "subjects_by_year" in result.keys():
return {"data":{},"total":0}
if not result["subjects_by_year"]:
return {"data":{},"total":0}
data=[]
names=[]
for reg in result["subjects_by_year"]:
year=reg["year"]
if start_year:
if start_year>year:
continue
if end_year:
if end_year<year:
continue
for sub in reg["subjects"]:
if sub["name"] in names:
data[names.index(sub["name"])]["products"]+=sub["products"]
else:
data.append(sub)
names.append(sub["name"])
sorted_data=sorted(data,key=lambda x:x["products"],reverse=True)
return {"data":sorted_data[:limit],"total":len(data)}
def get_authors(self,idx=None,page=1,max_results=100,sort="citations",direction="descending"):
if idx:
total_results = self.colav_db["person"].count_documents({"affiliations.id":ObjectId(idx)})
if not page:
page=1
else:
try:
page=int(page)
except:
print("Could not convert end page to int")
return None
if not max_results:
max_results=100
else:
try:
max_results=int(max_results)
except:
print("Could not convert end max to int")
return None
skip = (max_results*(page-1))
cursor=self.colav_db["person"].find({"affiliations.id":ObjectId(idx)})
if sort=="citations" and direction=="ascending":
cursor.sort([("citations_count",ASCENDING)])
if sort=="citations" and direction=="descending":
cursor.sort([("citations_count",DESCENDING)])
if sort=="products" and direction=="ascending":
cursor.sort([("products_count",ASCENDING)])
if sort=="products" and direction=="descending":
cursor.sort([("products_count",DESCENDING)])
cursor=cursor.skip(skip).limit(max_results)
entry = []
for reg in cursor:
group_name=""
group_id=""
inst_name=""
inst_id=""
if len(reg["affiliations"])>0:
for aff in reg["affiliations"]:
if "types" in aff.keys():
for typ in aff["types"]:
if typ["type"]=="group":
group_name=aff["name"]
group_id=aff["id"]
else:
if str(aff["id"])==idx:
inst_name=aff["name"]
inst_id=aff["id"]
entry.append({
"id":reg["_id"],
"name":reg["full_name"],
"products_count":reg["products_count"],
"citations_count":reg["citations_count"],
"affiliation":{"institution":{"name":inst_name,
"id":inst_id},
"group":{"name":group_name, "id":group_id}}
})
return {"total":total_results,"page":page,"count":len(entry),"data":entry}
def get_groups(self,idx=None,page=1,max_results=100,sort="citations",direction="descending"):
if idx:
total_results = self.colav_db["affiliations"].count_documents({"types.type":"group","relations.id":ObjectId(idx)})
if not page:
page=1
else:
try:
page=int(page)
except:
print("Could not convert end page to int")
return None
if not max_results:
max_results=100
else:
try:
max_results=int(max_results)
except:
print("Could not convert end max to int")
return None
skip = (max_results*(page-1))
cursor=self.colav_db["affiliations"].find({"types.type":"group","relations.id":ObjectId(idx)})
if sort=="citations" and direction=="ascending":
cursor.sort([("citations_count",ASCENDING)])
if sort=="citations" and direction=="descending":
cursor.sort([("citations_count",DESCENDING)])
if sort=="products" and direction=="ascending":
cursor.sort([("products_count",ASCENDING)])
if sort=="products" and direction=="descending":
cursor.sort([("products_count",DESCENDING)])
cursor=cursor.skip(skip).limit(max_results)
entry = []
for reg in cursor:
name=""
for n in reg["names"]:
if n["lang"]=="es":
name=n["name"]
break
elif n["lang"]=="en":
name=n["name"]
entry.append({
"id":reg["_id"],
"name":name,
"products_count":reg["products_count"],
"citations_count":reg["citations_count"]
})
return {"total":total_results,"page":page,"count":len(entry),"data":entry}
def get_venn(self,venn_query):
venn_source={
"scholar":0,"lens":0,"wos":0,"scopus":0,
"scholar_lens":0,"scholar_wos":0,"scholar_scopus":0,"lens_wos":0,"lens_scopus":0,"wos_scopus":0,
"scholar_lens_wos":0,"scholar_wos_scopus":0,"scholar_lens_scopus":0,"lens_wos_scopus":0,
"scholar_lens_wos_scopus":0
}
venn_query["$and"]=[{"updated.source":"scholar"},
{"updated.source":{"$ne":"lens"}},
{"updated.source":{"$ne":"wos"}},
{"updated.source":{"$ne":"scopus"}}]
venn_source["scholar"]=self.colav_db['works'].count_documents(venn_query)
venn_query["$and"]=[{"updated.source":{"$ne":"scholar"}},
{"updated.source":"lens"},
{"updated.source":{"$ne":"wos"}},
{"updated.source":{"$ne":"scopus"}}]
venn_source["lens"]=self.colav_db['works'].count_documents(venn_query)
venn_query["$and"]=[{"updated.source":{"$ne":"scholar"}},
{"updated.source":{"$ne":"lens"}},
{"updated.source":"wos"},
{"updated.source":{"$ne":"scopus"}}]
venn_source["wos"]=self.colav_db['works'].count_documents(venn_query)
venn_query["$and"]=[{"updated.source":{"$ne":"scholar"}},
{"updated.source":{"$ne":"lens"}},
{"updated.source":{"$ne":"wos"}},
{"updated.source":"scopus"}]
venn_source["scopus"]=self.colav_db['works'].count_documents(venn_query)
venn_query["$and"]=[{"updated.source":"scholar"},
{"updated.source":"lens"},
{"updated.source":{"$ne":"wos"}},
{"updated.source":{"$ne":"scopus"}}]
venn_source["scholar_lens"]=self.colav_db['works'].count_documents(venn_query)
venn_query["$and"]=[{"updated.source":"scholar"},
{"updated.source":{"$ne":"lens"}},
{"updated.source":"wos"},
{"updated.source":{"$ne":"scopus"}}]
venn_source["scholar_wos"]=self.colav_db['works'].count_documents(venn_query)
venn_query["$and"]=[{"updated.source":"scholar"},
{"updated.source":{"$ne":"lens"}},
{"updated.source":{"$ne":"wos"}},
{"updated.source":"scopus"}]
venn_source["scholar_scopus"]=self.colav_db['works'].count_documents(venn_query)
venn_query["$and"]=[{"updated.source":{"$ne":"scholar"}},
{"updated.source":"lens"},
{"updated.source":"wos"},
{"updated.source":{"$ne":"scopus"}}]
venn_source["lens_wos"]=self.colav_db['works'].count_documents(venn_query)
venn_query["$and"]=[{"updated.source":{"$ne":"scholar"}},
{"updated.source":"lens"},
{"updated.source":{"$ne":"wos"}},
{"updated.source":"scopus"}]
venn_source["lens_scopus"]=self.colav_db['works'].count_documents(venn_query)
venn_query["$and"]=[{"updated.source":{"$ne":"scholar"}},
{"updated.source":{"$ne":"lens"}},
{"updated.source":"wos"},
{"updated.source":"scopus"}]
venn_source["wos_scopus"]=self.colav_db['works'].count_documents(venn_query)
venn_query["$and"]=[{"updated.source":"scholar"},
{"updated.source":"lens"},
{"updated.source":"wos"},
{"updated.source":{"$ne":"scopus"}}]
venn_source["scholar_lens_wos"]=self.colav_db['works'].count_documents(venn_query)
venn_query["$and"]=[{"updated.source":"scholar"},
{"updated.source":{"$ne":"lens"}},
{"updated.source":"wos"},
{"updated.source":"scopus"}]
venn_source["scholar_wos_scopus"]=self.colav_db['works'].count_documents(venn_query)
venn_query["$and"]=[{"updated.source":"scholar"},
{"updated.source":"lens"},
{"updated.source":{"$ne":"wos"}},
{"updated.source":"scopus"}]
venn_source["scholar_lens_scopus"]=self.colav_db['works'].count_documents(venn_query)
venn_query["$and"]=[{"updated.source":{"$ne":"scholar"}},
{"updated.source":"lens"},
{"updated.source":"wos"},
{"updated.source":"scopus"}]
venn_source["lens_wos_scopus"]=self.colav_db['works'].count_documents(venn_query)
venn_query["$and"]=[{"updated.source":"scholar"},
{"updated.source":"lens"},
{"updated.source":"wos"},
{"updated.source":"scopus"}]
venn_source["scholar_lens_wos_scopus"]=self.colav_db['works'].count_documents(venn_query)
return venn_source
def get_production(self,idx=None,start_year=None,end_year=None,sort=None):
papers=[]
total=0
open_access=[]
if start_year:
try:
start_year=int(start_year)
except:
print("Could not convert start year to int")
return None
if end_year:
try:
end_year=int(end_year)
except:
print("Could not convert end year to int")
return None
search_dict={}
venn_query={}
oa_query={}
if idx:
search_dict={"authors.affiliations.id":ObjectId(idx)}
venn_query={"authors.affiliations.id":ObjectId(idx)}
oa_query={"authors.affiliations.id":ObjectId(idx)}
if start_year or end_year:
search_dict["year_published"]={}
venn_query["year_published"]={}
oa_query["year_published"]={}
if start_year:
search_dict["year_published"]["$gte"]=start_year
venn_query["year_published"]["$gte"]=start_year
oa_query["year_published"]["$gte"]=start_year
if end_year:
search_dict["year_published"]["$lte"]=end_year
venn_query["year_published"]["$lte"]=end_year
oa_query["year_published"]["$lte"]=end_year
cursor=self.colav_db["works"].find(search_dict)
total=cursor.count()
for oa in ["green","gold","bronze","closed","hybrid"]:
oa_query["bibliographic_info.open_access_status"]=oa
val=self.colav_db["works"].count_documents(oa_query)
if val!=0:
open_access.append({"type":oa ,"value":val})
types = self.colav_db['works'].distinct("types",{"authors.affiliations.id":ObjectId(idx)})
tipos=[]
for tipo in types:
if tipo["source"]=="minciencias":
if not tipo["type"] in tipos:
tipos.append(tipo["type"])
return {
"open_access":open_access,
"venn_source":self.get_venn(venn_query),
"types":tipos
}
def get_production_by_type(self,idx=None,max_results=100,page=1,start_year=None,end_year=None,sort="year",direction="descending",tipo=None):
total = 0
if start_year:
try:
start_year=int(start_year)
except:
print("Could not convert start year to int")
return None
if end_year:
try:
end_year=int(end_year)
except:
print("Could not convert end year to int")
return None
search_dict={"types.type":tipo}
if idx:
search_dict["authors.affiliations.id"]=ObjectId(idx)
if start_year or end_year:
search_dict["year_published"]={}
if start_year:
search_dict["year_published"]["$gte"]=start_year
if end_year:
search_dict["year_published"]["$lte"]=end_year
cursor=self.colav_db["works"].find(search_dict)
total=cursor.count()
if not page:
page=1
else:
try:
page=int(page)
except:
print("Could not convert end page to int")
return None
if not max_results:
max_results=100
else:
try:
max_results=int(max_results)
except:
print("Could not convert end max to int")
return None
if sort=="citations" and direction=="ascending":
cursor.sort([("citations_count",ASCENDING)])
if sort=="citations" and direction=="descending":
cursor.sort([("citations_count",DESCENDING)])
if sort=="year" and direction=="ascending":
cursor.sort([("year_published",ASCENDING)])
if sort=="year" and direction=="descending":
cursor.sort([("year_published",DESCENDING)])
cursor=cursor.skip(max_results*(page-1)).limit(max_results)
if cursor:
paper_list=[]
for paper in cursor:
entry={
"id":paper["_id"],
"title":paper["titles"][0]["title"],
"authors":[],
"source":"",
"open_access_status":paper["bibliographic_info"]["open_access_status"] if "open_access_status" in paper["bibliographic_info"] else "",
"year_published":paper["year_published"],
"citations_count":paper["citations_count"] if "citations_count" in paper.keys() else 0,
"subjects":[]
}
for subs in paper["subjects"]:
if subs["source"]=="openalex":
for sub in subs["subjects"]:
name=sub["names"][0]["name"]
for n in sub["names"]:
if n["lang"]=="es":
name=n["name"]
break
if n["lang"]=="en":
name=n["name"]
entry["subjects"].append({"name":name,"id":sub["id"]})
break
if "source" in paper.keys():
entry["source"]={"name":paper["source"]["title"],"id":paper["source"]["id"]}
authors=[]
for author in paper["authors"]:
author_entry={
"id":author["id"],
"full_name":author["full_name"],
"affiliation": {
"institution":{"name":"","id":""}
}
}
if "affiliations" in author.keys():
if len(author["affiliations"])>0:
for aff in author["affiliations"]:
if "types" in aff.keys():
for typ in aff["types"]:
if typ["type"]=="group":
author_entry["affiliation"]["group"]={
"name":aff["name"],
"id":aff["id"]
}
else:
author_entry["affiliation"]["institution"]["name"]=aff["name"]
author_entry["affiliation"]["institution"]["id"] =aff["id"]
authors.append(author_entry)
entry["authors"]=authors
paper_list.append(entry)
return {"data":paper_list,
"count":len(paper_list),
"page":page,
"total_results":total
}
else:
return None
@endpoint('/app/institutions', methods=['GET'])
def app_institutions(self):
"""
"""
data = self.request.args.get('data')
tipo = self.request.args.get('type')
if data=="info":
idx = self.request.args.get('id')
info = self.get_info(idx)
if info:
response = self.app.response_class(
response=self.json.dumps(info),
status=200,
mimetype='application/json'
)
else:
response = self.app.response_class(
response=self.json.dumps({"status":"Request returned empty"}),
status=204,
mimetype='application/json'
)
elif data=="production":
idx = self.request.args.get('id')
max_results=self.request.args.get('max')
page=self.request.args.get('page')
start_year=self.request.args.get('start_year')
end_year=self.request.args.get('end_year')
sort=self.request.args.get('sort')
if tipo == None:
production=self.get_production(idx=idx,
start_year=start_year,
end_year=end_year,
sort=sort)
else:
production=self.get_production_by_type(idx=idx,
max_results=max_results,
page=page,
start_year=start_year,
end_year=end_year,
sort=sort,tipo=tipo)
if production:
response = self.app.response_class(
response=self.json.dumps(production),
status=200,
mimetype='application/json'
)
else:
response = self.app.response_class(
response=self.json.dumps({"status":"Request returned empty"}),
status=204,
mimetype='application/json'
)
elif data=="authors":
idx = self.request.args.get('id')
max_results=self.request.args.get('max')
page=self.request.args.get('page')
sort=self.request.args.get('sort')
authors=self.get_authors(idx=idx,page=page,max_results=max_results,sort=sort)
if authors:
response = self.app.response_class(
response=self.json.dumps(authors),
status=200,
mimetype='application/json'
)
else:
response = self.app.response_class(
response=self.json.dumps({"status":"Request returned empty"}),
status=204,
mimetype='application/json'
)
elif data=="coauthors":
idx = self.request.args.get('id')
start_year=self.request.args.get('start_year')
end_year=self.request.args.get('end_year')
max_results=self.request.args.get('max')
page=self.request.args.get('page')
coauthors=self.get_coauthors(idx,start_year,end_year,page,max_results)
if coauthors:
response = self.app.response_class(
response=self.json.dumps(coauthors),
status=200,
mimetype='application/json'
)
else:
response = self.app.response_class(
response=self.json.dumps({"status":"Request returned empty"}),
status=204,
mimetype='application/json'
)
elif data=="groups":
idx = self.request.args.get('id')
max_results=self.request.args.get('max')
page=self.request.args.get('page')
sort=self.request.args.get('sort')
groups=self.get_groups(idx=idx,page=page,max_results=max_results,sort=sort)
if groups:
response = self.app.response_class(
response=self.json.dumps(groups),
status=200,
mimetype='application/json'
)
else:
response = self.app.response_class(
response=self.json.dumps({"status":"Request returned empty"}),
status=204,
mimetype='application/json'
)
elif data=="subjects":
idx = self.request.args.get('id')
start_year=self.request.args.get('start_year')
end_year=self.request.args.get('end_year')
limit=self.request.args.get('limit')
subjects=self.get_subjects(idx,start_year,end_year,limit)
if subjects:
response = self.app.response_class(
response=self.json.dumps(subjects),
status=200,
mimetype='application/json'
)
else:
response = self.app.response_class(
response=self.json.dumps({"status":"Request returned empty"}),
status=204,
mimetype='application/json'
)
else:
response = self.app.response_class(
response=self.json.dumps({}),
status=400,
mimetype='application/json'
)
response.headers.add("Access-Control-Allow-Origin", "*")
return response