forked from SCOAP3/scoap3-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nations.py
360 lines (328 loc) · 16.6 KB
/
nations.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
from cgi import escape
from urllib import urlencode
from invenio.webinterface_handler_config import HTTP_BAD_REQUEST, SERVER_RETURN
from invenio.webpage import pagefooteronly, pageheaderonly, page
from invenio.search_engine import perform_request_search
from invenio.search_engine import get_coll_i18nname, get_record, get_collection_reclist
from invenio.bibrecord import record_get_field_value
from invenio.dbquery import run_sql
_CFG_NATION_MAP = [("Algeria", ),
("Argentina", ),
("Armenia", ),
("Australia", ),
("Austria", ),
("Azerbaijan", ),
("Belarus", ),
("Belgium", "Belgique"),
("Bangladesh", ),
("Brazil", ),
("Bulgaria", ),
("Canada", ),
("CERN", ),
("Chile", ),
("China (PRC)", "PR China", "China"),
("Colombia", ),
("Costa Rica", ),
("Croatia", ),
("Cuba", ),
("Cyprus", ),
("Czech Republic", ),
("Denmark", ),
("Egypt", ),
("Estonia", ),
("Finland", ),
("France", ),
("Georgia", ),
("Germany", "Deutschland"),
("Greece", ),
("Hong-Kong", "Hong Kong"),
("Hungary", ),
("Iceland", ),
("India", ),
("Indonesia", ),
("Iran", ),
("Ireland", ),
("Israel", ),
("Italy", "Italia"),
("Japan", ),
("Korea", "Republic of Korea", "South Korea"),
("Lebanon", ),
("Lithuania", ),
("México", "Mexico"),
("Montenegro", ),
("Morocco", ),
("Netherlands", "The Netherlands"),
("New Zealand", ),
("Norway", ),
("Pakistan", ),
("Poland", ),
("Portugal", ),
("Romania", ),
("Russia", "Russian Federation"),
("Saudi Arabia", ),
("Serbia", ),
("Singapore", ),
("Slovak Republic", "Slovakia"),
("Slovenia", ),
("South Africa", ),
("Spain", ),
("Sweden", ),
("Switzerland", ),
("Taiwan", ),
("Thailand", ),
("Tunisia", ),
("Turkey", ),
("Ukraine", ),
("United Kingdom", "UK", "U.K", "England"),
("United States of America", "United States", "USA", "U.S.A"),
("Uruguay", ),
("Uzbekistan", ),
("Venezuela", ),
("Vietnam", "Viet Nam"),
## ------ other -----
("Peru", ),
("Kuwait", ),
("Sri Lanka", ),
("Kazakhstan", ),
("Mongolia", ),
("United Arab Emirates", ),
("Malaysia", ),
("Qatar", ),
("Kyrgyz Republic", ),
("Jordan", )]
CFG_JOURNALS = ['Acta',
'Advances in High Energy Physics',
'Chinese Physics C',
'European Physical Journal C',
'Journal of Cosmology and Astroparticle Physics',
'Journal of High Energy Physics',
'New Journal of Physics',
'Nuclear Physics B',
'Physics Letters B',
'Progress of Theoretical and Experimental Physics']
CFG_SELECTED_AFF = {'Andrews University': ('Andrews University',),
'Arkansas State University': ('Arkansas State University',),
'Black Hills State University': ('Black Hills State University',),
'Boise State University': ('Boise State University',),
'Brookhaven National Laboratory': ('Brookhaven National Laboratory',),
'Brown University': ('Brown University',),
'Chicago State University': ('Chicago State University',),
'Columbia University': ('Columbia University',),
'Creighton University': ('Creighton University',),
'Fairfield University': ('Fairfield University',),
'George Washington University': ('George Washington University',),
'Hampton University': ('Hampton University',),
'Houston Advanced Research Center': ('Houston Advanced Research Center',),
'Janelia Farm Research Campus': ('Janelia Farm Research Campus',),
'Long Island University': ('Long Island University',),
'Louisiana Tech University': ('Louisiana Tech University',),
'Luther College': ('Luther College',),
'Manhattan College': ('Manhattan College',),
'Milwaukee School of Engineering': ('Milwaukee School of Engineering',),
'Mississippi State University': ('Mississippi State University',),
'Muhlenberg College': ('Muhlenberg College',),
'New York City College of Technology': ('New York City College of Technology',),
'North Carolina Central University': ('North Carolina Central University',),
'Northern Illinois University': ('Northern Illinois University',),
'Oklahoma State University': ('Oklahoma State University',),
'Pacific Lutheran University': ('Pacific Lutheran University',),
'Philander Smith College': ('Philander Smith College',),
'Rutgers University': ('Rutgers University',),
'South Dakota School of Mines and Technology': ('South Dakota School of Mines and Tec',),
'Stanford University': ('Stanford University',),
'State University of New York (or SUNY) Albany': ('SUNY Albany', 'University at Albany (SUNY)', 'Albany'),
'State University of New York (or SUNY) Buffalo': ('University at Buffalo', 'State University of New York at Buffalo'),
'Syracuse University': ('Syracuse University',),
'Tennessee Tech University': ('Tennessee Tech University',),
'Texas Tech University': ('Texas Tech University',),
'The George Washington University': ('The George Washington University',),
'The Graduate School and University Center, The City University of New York': ('The Graduate School and University Center, The City University o',),
'The Rockefeller University': ('The Rockefeller University',),
'The University of Alabama, Tuscaloosa': ('The University of Alabama, Tuscaloosa',),
'The University of Mississippi': ('The University of Mississippi',),
'Triangle Universities Nuclear Laboratory': ('Triangle Universities Nuclear Laboratory',),
'University of Connecticut': ('University of Connecticut',),
'University of Hawaii': ('University of Hawaii',),
'University of Houston': ('University of Houston',),
'University of Puerto Rico': ('University of Puerto Rico',),
'University of South Dakota': ('University of South Dakota',),
'Utah Valley University': ('Utah Valley University',),
'Virginia Military Institute': ('Virginia Military Institute',),
'Wayne State University': ('Wayne State University',),
'Wayne University': ('Wayne State university',),
'Western Michigan University': ('Western Michigan University',),
'Yale University': ('Yale University',)}
def _build_query(nation_tuple):
out = []
for value in nation_tuple:
out.append('affiliation:"*%s" OR affiliation:"*%s."' % (value, value))
return " OR ".join(out)
def index(req):
req.content_type = "text/html"
req.write(pageheaderonly("Nation numbers", req=req))
req.write("<h1>Nation numbers</h1>")
req.flush()
req.write("<table>\n")
for i, nation_tuple in enumerate(_CFG_NATION_MAP):
query = _build_query(nation_tuple)
results = perform_request_search(p=query, of='intbitset')
req.write("""<tr><td>%s</td><td><a href="/search?%s&sc=1">%s</a></td><td><a href="/nations.py/articles?i=%s" target="_blank">Articles</a> (<a href="/nations.py/articles?mode=text&i=%s">text</a>)</td><tr>\n""" % (
escape(nation_tuple[0]), escape(urlencode([("p", query)]), True), len(results), i, i
))
req.flush()
req.write("</table>\n")
req.write(pagefooteronly(req=req))
return ""
def late(req):
req.content_type = "text/html"
print >> req, pageheaderonly("Late journals", req=req)
for journal in CFG_JOURNALS:
print >> req, "<h2>%s</h2>" % escape(get_coll_i18nname(journal))
results = get_collection_reclist(journal)
print >> req, "<table>"
print >> req, "<tr><th>DOI</th><th>Title</th><th>DOI registration</th><th>Arrival in SCOAP3</th></tr>"
for recid in results:
creation_date = run_sql("SELECT creation_date FROM bibrec WHERE id=%s", (recid, ))[0][0]
record = get_record(recid)
doi = record_get_field_value(record, '024', '7', code='a')
title = record_get_field_value(record, '245', code='a')
doi_date = run_sql("SELECT creation_date FROM doi WHERE doi=%s", (doi, ))
background = "#eee"
if doi_date:
doi_date = doi_date[0][0]
if (creation_date - doi_date).days < 0:
background = "#66FF00"
elif (creation_date - doi_date).days < 1:
background = "#FF6600"
else:
background = "#FF0000"
else:
doi_date = ''
print >> req, '<tr style="background-color: %s;"><td><a href="http://dx.doi.org/%s" target="_blank">%s</td><td>%s</td><td>%s</td><td>%s</td></tr>' % (
background,
escape(doi, True),
escape(doi),
title,
doi_date,
creation_date)
print >> req, "</table>"
def articles(req, i, mode='html'):
try:
i = int(i)
assert 0 <= i < len(_CFG_NATION_MAP)
except:
raise SERVER_RETURN(HTTP_BAD_REQUEST)
nation_tuple = _CFG_NATION_MAP[i]
ret = []
page_title = "SCOAP3 Articles by authors from %s" % nation_tuple[0]
if mode == 'text':
req.content_type = "text/plain; charset=utf8"
req.headers_out['content-disposition'] = 'attachment; filename=%s.txt' % nation_tuple[0]
else:
req.content_type = "text/html"
if mode == 'text':
print >> req, page_title
print >> req, "-" * len(page_title)
query = _build_query(nation_tuple)
for journal in CFG_JOURNALS:
results = perform_request_search(p=query, cc=journal, of='intbitset')
if not results:
#ret.append("<p>No articles yet</p>")
continue
ret.append("<h2>%s (%s)</h2" % (escape(get_coll_i18nname(journal)), len(results)))
ret.append("<p><ul>")
if mode == 'text':
print >> req, ""
print >> req, get_coll_i18nname(journal)
for recid in results:
record = get_record(recid)
title = record_get_field_value(record, '245', code='a')
doi = record_get_field_value(record, '024', '7', code='a')
if mode == 'text':
print >> req, "http://dx.doi.org/%s" % doi
ret.append('<li><a href="http://dx.doi.org/%s" target="_blank">%s</a>: %s</li>' % (escape(doi, True), escape(doi), title))
ret.append("</ul></p>")
body = '\n'.join(ret)
if mode == 'text':
return ""
return page(req=req, title=page_title, body=body)
def csv(req):
req.content_type = 'text/csv; charset=utf-8'
req.headers_out['content-disposition'] = 'attachment; filename=scoap3.csv'
header = ','.join(['Nation'] + [get_coll_i18nname(journal) for journal in CFG_JOURNALS])
print >> req, header
for nation_tuple in _CFG_NATION_MAP:
query = _build_query(nation_tuple)
line = ','.join([nation_tuple[0]] + [str(len(perform_request_search(p=query, cc=journal, of='intbitset'))) for journal in CFG_JOURNALS])
print >> req, line
def create_search_from_affiliation(aff):
return '|'.join(t for t in CFG_SELECTED_AFF[aff])
def us_affiliations(req):
from invenio.search_engine_utils import get_fieldvalues
req.content_type = "text/html"
print >> req, pageheaderonly("USA affiliations", req=req)
affiliations = []
tmp = []
tmp.extend(get_fieldvalues(perform_request_search(p="*"), '100__u', False))
tmp.extend(get_fieldvalues(perform_request_search(p="*"), '100__v', False))
tmp.extend(get_fieldvalues(perform_request_search(p="*"), '700__u', False))
tmp.extend(get_fieldvalues(perform_request_search(p="*"), '700__v', False))
affiliations.extend(filter(lambda x: "United States of America" in x or "United States" in x or "USA" in x or "U.S.A" in x, tmp))
affiliations = set(affiliations)
affs = map(lambda x: x.replace('United States of America', '').replace("United States", '').replace("USA", '').replace("U.S.A", '').replace("University", '').replace("State", '').replace('Department of Physics and Astronomy', "").replace('Department of Physics', "").replace('Department', '').replace(",", '').strip(), affiliations)
affiliations2 = zip(affiliations, affs)
for a in sorted(affiliations2, key=lambda aff: aff[1]):
req.write(a[0]+'<br />')
req.write(pagefooteronly(req=req))
return ""
def us_affiliations_csv(req):
req.content_type = 'text/csv; charset=utf-8'
req.headers_out['content-disposition'] = 'attachment; filename=us_aff.csv'
header = ';'.join(['University'] + [get_coll_i18nname(journal) for journal in CFG_JOURNALS] + ['sum'])
print >> req, header
for university in sorted(CFG_SELECTED_AFF):
line = university
count = 0
search = create_search_from_affiliation(university)
for collection in CFG_JOURNALS:
res = perform_request_search(p='/%s/' % (search,), c=collection)
line = line + ";" + str(len(res))
count = count + len(res)
print >> req, line+";"+str(count)
def usa_papers(req):
req.content_type = "text/html"
print >> req, pageheaderonly("USA papers for selected affiliations", req=req)
## print the list of linkt to the articles
for university in CFG_SELECTED_AFF:
print >> req, "<h2>%s</h2>" % (str(university),)
search = create_search_from_affiliation(university)
for collection in CFG_JOURNALS:
res = perform_request_search(p='/%s/' % (search,), c=collection)
if len(res):
print >> req, "<h3>%s (%i)</h3>" % (str(collection), len(res))
print >> req, "<ul>"
for rec_id in res:
rec = get_record(rec_id)
line = "<li><a href='https://repo.scoap3.org/record/%s'>%s</a></li>" % (str(rec_id), str(rec['245'][0][0][0][1]))
print >> req, line
print >> req, "</ul>"
req.write(pagefooteronly(req=req))
return ""
def usa_papers_csv(req):
req.content_type = 'text/csv; charset=utf-8'
req.headers_out['content-disposition'] = 'attachment; filename=usa_papers.csv'
## print the list of linkt to the articles
for university in CFG_SELECTED_AFF:
print >> req, university
search = create_search_from_affiliation(university)
for collection in CFG_JOURNALS:
res = perform_request_search(p='(%s)' % (search,), c=collection)
if len(res):
print >> req, collection
for rec_id in res:
rec = get_record(rec_id)
line = "%s; https://repo.scoap3.org/record/%s" % (str(rec['245'][0][0][0][1]), str(rec_id))
print >> req, line
print >> req, ""
print >> req, ""
print >> req, ""