-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimpact_data_retriver.py
66 lines (59 loc) · 2.69 KB
/
impact_data_retriver.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
from __future__ import division
import MySQLdb
from collections import Counter
impact_db=MySQLdb.connect(host="localhost",
user="user",
passwd="password",
db="impact")
impact_db_c=impact_db.cursor()
journals={'NPB':'Nuclear Physics B',
'JCAP':'JCAP',
'JHEP':'JHEP',
'PLB':'Physics letters B',
'PTEP':'PTEP',
'AHEP':'Advances in High Energy Physics',
'APPB':'Acta Physica Polonica B',
'CPC':'Chinese Phys. C',
'EPJC':'EPJC',
'NJP':'New J. Phys.',
'Phys.Rev.D':'APS Phys.Rev.D',
'Phys.Rev.C':'APS Phys.Rev.C',
'Phys.Rev.Lett':'APS Phys.Rev.Lett.'}
for name, search_term in journals.items():
for rank in range(1,5):
impact_db_c.execute("select idrecord from record where journal_name = '%s'" % search_term)
records = impact_db_c.fetchall()
impact_file = open("impact_factor_"+name+"_rank"+str(rank)+".csv","w")
for recid in records:
impact_db_c.execute("select idauthor from rec_author where idrecord = %s", (recid[0],))
authors_id = impact_db_c.fetchall()
countries = []
for author in authors_id:
impact_db_c.execute("""select country.rank%s
from auth_affiliation
join affiliation
on auth_affiliation.idaffiliation=affiliation.idaffiliation
join country
on affiliation.idcountry=country.idcountry
where auth_affiliation.idauthor = %s
order by country.rank%s""", (rank, author[0],rank))
ranks = impact_db_c.fetchall()
if ranks:
countries.append(ranks[0][0])
counter = Counter(countries)
print "%s: %s" % (recid, counter)
final = {}
for key, value in counter.iteritems():
final[key] = value/len(countries)
for i in range(-5, 198):
if i not in final and i != 0:
final[i] = 0
print "%s: %s" % (recid, final)
result=[]
impact_file.write("recid,%s\n" % (",".join(final.keys()),))
for k, v in sorted(final.items(), key=lambda x: x[0]):
result.append(v)
result = ','.join(result)
#print "%s: %s" % (recid, result)
impact_file.write("%s,%s\n" % (recid[0], result))
impact_file.close()