forked from emeryberger/CSrankings
-
Notifications
You must be signed in to change notification settings - Fork 0
/
csrankings.js
615 lines (612 loc) · 23.2 KB
/
csrankings.js
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
/*
CSrankings.ts
@author Emery Berger <[email protected]> http://www.emeryberger.com
*/
/// <reference path="./typescript/jquery.d.ts" />
/// <reference path="./typescript/papaparse.d.ts" />
/// <reference path="./typescript/set.d.ts" />
/// <reference path="./typescript/pako.d.ts" />
var coauthorFile = "faculty-coauthors.csv";
var authorinfoFile = "generated-author-info.csv";
var countryinfoFile = "country-info.csv";
var allowRankingChange = false; /* Can we change the kind of rankings being used? */
var showCoauthors = false;
var maxCoauthors = 30; /* Max co-authors to display. */
var useArithmeticMean = false;
var useGeometricMean = true; /* This is the default and arguably only principled choice. */
var useHarmonicMean = false;
var useDenseRankings = false; /* Set to true for "dense rankings" vs. "competition rankings". */
/* All the areas, in order by their 'field_' number (the checkboxes) in index.html. */
var areas = ["proglang", "softeng", "opsys", "networks", "security", "database", "metrics", "mlmining", "ai", "nlp", "web", "vision", "theory", "logic", "arch", "graphics", "hci", "mobile", "robotics", "highperf", "nada", "crypto"];
;
;
;
var authors = []; /* The data which will hold the parsed CSV of author info. */
var coauthors = []; /* The data which will hold the parsed CSV of co-author info. */
var countryInfo = {};
/* The prologue that we preface each generated HTML page with (the results). */
function makePrologue() {
var s = "<html>"
+ "<head>"
+ '<style type="text/css">'
+ ' body { font-family: "Helvetica", "Arial"; }'
+ " table td { vertical-align: top; }"
+ "</style>"
+ "</head>"
+ "<body>"
+ '<div class="row">'
+ '<div class="table" style="overflow:auto; height: 650px;">'
+ '<table class="table-sm table-striped"'
+ 'id="ranking" valign="top">';
return s;
}
/* from http://hubrik.com/2015/11/16/sort-by-last-name-with-javascript/ */
function compareNames(a, b) {
//split the names as strings into arrays
var aName = a.split(" ");
var bName = b.split(" ");
// get the last names by selecting
// the last element in the name arrays
// using array.length - 1 since full names
// may also have a middle name or initial
var aLastName = aName[aName.length - 1];
var bLastName = bName[bName.length - 1];
// compare the names and return either
// a negative number, positive number
// or zero.
if (aLastName < bLastName)
return -1;
if (aLastName > bLastName)
return 1;
return 0;
}
/* from http://www.html5gamedevs.com/topic/20052-tutorial-efficiently-load-large-amounts-of-game-data-into-memory/ */
function zlibDecompress(url, callback) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'blob';
xhr.onload = function (oEvent) {
// Base64 encode
var reader = new FileReader();
reader.readAsDataURL(xhr.response);
reader.onloadend = function () {
var base64data = reader.result;
//console.log(base64data);
var base64 = base64data.split(',')[1];
// Decode base64 (convert ascii to binary)
var strData = atob(base64);
// Convert binary string to character-number array
var charData = strData.split('').map(function (x) { return x.charCodeAt(0); });
// Turn number array into byte-array
var binData = new Uint8Array(charData);
// Pako inflate
var data = pako.inflate(binData, { to: 'string' });
callback(data);
};
};
xhr.send();
}
function redisplay(str) {
jQuery("#success").html(str);
}
function toggle(dept) {
var e = document.getElementById(dept);
var widget = document.getElementById(dept + "-widget");
if (e.style.display == 'block') {
e.style.display = 'none';
widget.innerHTML = '<font color="blue">►</font> ' + dept;
}
else {
e.style.display = 'block';
widget.innerHTML = '<font color="blue">▼</font> ' + dept;
}
}
function setAllCheckboxes() {
/* Set the _default_ (not "other") checkboxes to true. */
for (var i = 1; i <= areas.length; i++) {
var str = 'input[name=field_' + i + ']';
jQuery(str).prop('checked', true);
}
}
/* A convenience function for ending a pipeline of function calls executed in continuation-passing style. */
function nop() { }
function loadCoauthors(cont) {
Papa.parse(coauthorFile, {
download: true,
header: true,
complete: function (results) {
var data = results.data;
coauthors = data;
cont();
}
});
}
function loadCountryInfo(cont) {
Papa.parse(countryinfoFile, {
header: true,
download: true,
complete: function (results) {
var data = results.data;
var ci = data;
for (var i = 0; i < ci.length; i++) {
countryInfo[ci[i].institution] = ci[i].region;
}
cont();
}
});
}
function loadAuthorInfo(cont) {
Papa.parse(authorinfoFile, {
download: true,
header: true,
complete: function (results) {
var data = results.data;
authors = data;
for (var i = 1; i <= areas.length; i++) {
var str = 'input[name=field_' + i + ']';
(function (s) {
jQuery(s).click(function () {
rank();
});
})(str);
}
cont();
/* rank(); */
}
});
}
function init() {
jQuery(document).ready(function () {
setAllCheckboxes();
loadAuthorInfo(function () {
loadCountryInfo(rank);
});
});
}
/*
function init() : void {
jQuery(document).ready(
function() {
setAllCheckboxes();
loadAuthorInfo(function() {
loadCountryInfo(function() {
loadCoauthors(rank);
});
});
});
}
*/
function activateAll(value) {
if (value === undefined) {
value = true;
}
for (var i = 1; i <= areas.length; i++) {
var str = "input[name=field_" + i + "]";
jQuery(str).prop('checked', value);
}
rank();
return false;
}
function activateNone() {
return activateAll(false);
}
function activateFields(value, fields) {
if (value === undefined) {
value = true;
}
for (var i = 0; i <= fields.length; i++) {
var str = "input[name=field_" + fields[i] + "]";
jQuery(str).prop('checked', value);
}
rank();
return false;
}
function activatePL(value) {
var plFields = [1, 2, 21];
return activateFields(value, plFields);
}
function activateSystems(value) {
activatePL(value);
var systemsFields = [3, 4, 5, 6, 7, 15, 18, 20];
return activateFields(value, systemsFields);
}
function activateAI(value) {
var aiFields = [8, 9, 10, 11, 12];
return activateFields(value, aiFields);
}
function activateTheory(value) {
var theoryFields = [13, 14, 22];
return activateFields(value, theoryFields);
}
function activateOthers(value) {
var otherFields = [16, 17, 19];
return activateFields(value, otherFields);
}
function deactivatePL() {
return activatePL(false);
}
function deactivateSystems() {
return activateSystems(false);
}
function deactivateAI() {
return activateAI(false);
}
function deactivateTheory() {
return activateTheory(false);
}
function deactivateOthers() {
return activateOthers(false);
}
function toggleAI(cb) {
if (cb.checked) {
console.log("checked");
activateAI(false);
}
else {
console.log("not checked");
activateAI(true);
}
return false;
}
function sortIndex(univagg) {
var keys = Object.keys(univagg);
keys.sort(function (a, b) {
if (univagg[a] > univagg[b]) {
return -1;
}
if (univagg[b] > univagg[a]) {
return 1;
}
if (a < b) {
return -1;
}
if (b < a) {
return 1;
}
return 0;
});
return keys;
}
function computeCoauthors(coauthors, startyear, endyear, weights) {
var coauthorList = {};
for (var c in coauthors) {
var author = coauthors[c].author;
var coauthor = coauthors[c].coauthor;
var year = coauthors[c].year;
var area = coauthors[c].area;
if (!(author in coauthorList)) {
coauthorList[author] = new Set([]);
}
if ((weights[area] == 0) || (year < startyear) || (year > endyear)) {
continue;
}
coauthorList[author].add(coauthor);
}
return coauthorList;
}
function countPapers(areacount, areaAdjustedCount, areaDeptAdjustedCount, authors, startyear, endyear, weights) {
/* Count the total number of papers (raw and adjusted) in each area. */
for (var r in authors) {
var area = authors[r].area;
var dept = authors[r].dept;
var year = authors[r].year;
var areaDept = area + dept;
areaDeptAdjustedCount[areaDept] = 0;
if ((weights[area] == 0) || (year < startyear) || (year > endyear)) {
continue;
}
var count = parseFloat(authors[r].count);
var adjustedCount = parseFloat(authors[r].adjustedcount);
areacount[area] += count;
areaAdjustedCount[area] += adjustedCount;
}
}
function buildDepartments(areaDeptAdjustedCount, deptCounts, deptNames, facultycount, facultyAdjustedCount, authors, startyear, endyear, weights, regions) {
/* Build the dictionary of departments (and count) to be ranked. */
var visited = {}; /* contains an author name if that author has been processed. */
for (var r in authors) {
var area = authors[r].area;
var dept = authors[r].dept;
switch (regions) {
case "USA":
if (dept in countryInfo) {
continue;
}
break;
case "europe":
if (!(dept in countryInfo)) {
continue;
}
if (countryInfo[dept] != "europe") {
continue;
}
break;
case "canada":
if (!(dept in countryInfo)) {
continue;
}
if (countryInfo[dept] != "canada") {
continue;
}
break;
case "world":
break;
}
var areaDept = area + dept;
if (!(areaDept in areaDeptAdjustedCount)) {
areaDeptAdjustedCount[areaDept] = 0;
}
if (weights[area] == 0) {
continue;
}
var name_1 = authors[r].name;
var count = parseInt(authors[r].count);
var adjustedCount = parseFloat(authors[r].adjustedcount);
var year = authors[r].year;
if ((year >= startyear) && (year <= endyear)) {
areaDeptAdjustedCount[areaDept] += adjustedCount;
/* Is this the first time we have seen this person? */
if (!(name_1 in visited)) {
visited[name_1] = true;
facultycount[name_1 + dept] = 0;
facultyAdjustedCount[name_1 + dept] = 0;
if (!(dept in deptCounts)) {
deptCounts[dept] = 0;
deptNames[dept] = [];
}
deptNames[dept].push(name_1);
deptCounts[dept] += 1;
}
facultycount[name_1 + dept] += count;
facultyAdjustedCount[name_1 + dept] += adjustedCount;
}
}
}
/* Compute aggregate statistics. */
function computeStats(deptNames, areaAdjustedCount, areaDeptAdjustedCount, areas, numAreas, displayPercentages, weights) {
var univagg = {};
for (var dept in deptNames) {
if (displayPercentages) {
if (useArithmeticMean) {
univagg[dept] = 0;
}
if (useGeometricMean) {
univagg[dept] = 1;
}
if (useHarmonicMean) {
univagg[dept] = 0;
}
}
else {
univagg[dept] = 0;
}
for (var ind = 0; ind < areas.length; ind++) {
var area = areas[ind];
var areaDept = area + dept;
if (!(areaDept in areaDeptAdjustedCount)) {
areaDeptAdjustedCount[areaDept] = 0;
}
if (weights[area] != 0) {
if (displayPercentages) {
if (areaDeptAdjustedCount[areaDept] != 0) {
if (useArithmeticMean) {
univagg[dept] += areaDeptAdjustedCount[areaDept] / areaAdjustedCount[area];
}
if (useGeometricMean) {
univagg[dept] *= areaDeptAdjustedCount[areaDept];
}
if (useHarmonicMean) {
univagg[dept] += areaAdjustedCount[area] / areaDeptAdjustedCount[areaDept];
}
}
else {
}
}
else {
univagg[dept] += areaDeptAdjustedCount[areaDept];
}
}
}
if (displayPercentages) {
if (useArithmeticMean) {
univagg[dept] = univagg[dept] / numAreas;
}
if (useGeometricMean) {
univagg[dept] = Math.pow(univagg[dept], 1 / numAreas);
}
if (useHarmonicMean) {
univagg[dept] = numAreas / univagg[dept];
}
}
}
return univagg;
}
function rank() {
var form = document.getElementById("rankform");
var s = "";
var deptNames = {}; /* names of departments. */
var deptCounts = {}; /* number of faculty in each department. */
var facultycount = {}; /* name + dept -> raw count of pubs per name / department */
var facultyAdjustedCount = {}; /* name + dept -> adjusted count of pubs per name / department */
var weights = {}; /* array to hold 1 or 0, depending on if the area is checked or not. */
var areacount = {}; /* raw number of papers in each area */
var areaAdjustedCount = {}; /* adjusted number of papers in each area (split among faculty authors). */
var areaDeptAdjustedCount = {}; /* as above, but for area+dept. */
var startyear = parseInt(jQuery("#startyear").find(":selected").text());
var endyear = parseInt(jQuery("#endyear").find(":selected").text());
var displayPercentages = Boolean(parseInt(jQuery("#displayPercent").find(":selected").val()));
/* Show the top N (with more if tied at the end) */
var minToRank = parseInt(jQuery("#minToRank").find(":selected").val());
var whichRegions = jQuery("#regions").find(":selected").val();
var numAreas = 0; /* Total number of areas checked */
/* Update the 'weights' of each area from the checkboxes. */
for (var ind = 0; ind < areas.length; ind++) {
weights[areas[ind]] = jQuery('input[name=field_' + (ind + 1) + ']').prop('checked') ? 1 : 0;
if (weights[areas[ind]] == 1) {
/* One more area checked. */
numAreas++;
}
areacount[areas[ind]] = 0;
areaAdjustedCount[areas[ind]] = 0;
}
var coauthorList = {};
if (showCoauthors) {
coauthorList = computeCoauthors(coauthors, startyear, endyear, weights);
}
countPapers(areacount, areaAdjustedCount, areaDeptAdjustedCount, authors, startyear, endyear, weights);
buildDepartments(areaDeptAdjustedCount, deptCounts, deptNames, facultycount, facultyAdjustedCount, authors, startyear, endyear, weights, whichRegions);
/* (university, total or average number of papers) */
var univagg = computeStats(deptNames, areaAdjustedCount, areaDeptAdjustedCount, areas, numAreas, displayPercentages, weights);
var s = makePrologue();
var univtext = {};
/* Build drop down for faculty names and paper counts. */
for (dept in deptNames) {
var p = '<div class="row"><div class="table"><table class="table-striped" width="400px"><thead><th></th><td><small><em><abbr title="Click on an author\'s name to go to their home page.">Faculty</abbr></em></small></td><td align="right"><small><em> <abbr title="Total number of publications (click for DBLP entry).">Raw \# Pubs</abbr></em></small></td><td align="right"><small><em> <abbr title="Count divided by number of co-authors">Adjusted \#</abbr></em></small></td></thead><tbody>';
/* Build a dict of just faculty from this department for sorting purposes. */
var fc = {};
for (var ind = 0; ind < deptNames[dept].length; ind++) {
name = deptNames[dept][ind];
fc[name] = facultycount[name + dept];
}
var keys = Object.keys(fc);
keys.sort(function (a, b) { return fc[b] - fc[a]; });
for (var ind = 0; ind < keys.length; ind++) {
name = keys[ind];
if (showCoauthors) {
/* Build up text for co-authors. */
var coauthorStr = "";
if ((!(name in coauthorList)) || (coauthorList[name].size == 0)) {
coauthorList[name] = new Set([]);
coauthorStr = "(no senior co-authors on these papers)";
}
else {
coauthorStr = "Senior co-authors on these papers:\n";
}
/* Sort it by last name. */
var l = [];
coauthorList[name].forEach(function (item, coauthors) {
l.push(item);
});
if (l.length > maxCoauthors) {
coauthorStr = "(more than " + maxCoauthors + " senior co-authors)";
}
else {
l.sort(compareNames);
l.forEach(function (item, coauthors) {
coauthorStr += item + "\n";
});
/* Trim off the trailing newline. */
coauthorStr = coauthorStr.slice(0, coauthorStr.length - 1);
}
}
p += "<tr><td> </td><td><small>"
+ '<a title="Click for author\'s home page." target="_blank" href="https://www.google.com/search?q='
+ encodeURI(name + " " + dept)
+ '&gws_rd=ssl">'
+ name
+ '</a></small></td><td align="right"><small>'
+ '<a title="Click for author\'s DBLP entry." target="_blank" href="http://dblp.uni-trier.de/search?q=' + encodeURI(name) + '">'
+ facultycount[name + dept]
+ '</a>'
+ "</small></td>"
+ '</a></small></td><td align="right"><small>'
+ facultyAdjustedCount[name + dept].toPrecision(2)
+ "</small></td></tr>";
}
p += "</tbody></table></div></div>";
univtext[dept] = p;
}
if (displayPercentages) {
s = s + '<thead><tr><th align="left">Rank </th><th align="right">Institution </th><th align="right"><abbr title="Geometric mean number of papers published across all areas.">Average Count</abbr></th><th align="right"> <abbr title="Number of faculty who have published in these areas.">Faculty</abbr></th></th></tr></thead>';
}
else {
s = s + '<thead><tr><th align="left">Rank </th><th align="right">Institution </th><th align="right">Adjusted Pub Count</th><th align="right"> Faculty</th></tr></thead>';
}
s = s + "<tbody>";
/* As long as there is at least one thing selected, compute and display a ranking. */
if (numAreas > 0) {
var ties = 1; /* number of tied entries so far (1 = no tie yet); used to implement "competition rankings" */
var rank = 0; /* index */
var oldv = null; /* old number - to track ties */
/* Sort the university aggregate count from largest to smallest. */
var keys2 = sortIndex(univagg);
/* Display rankings until we have shown `minToRank` items or
while there is a tie (those all get the same rank). */
for (var ind = 0; ind < keys2.length; ind++) {
var dept = keys2[ind];
var v = univagg[dept];
if (useArithmeticMean || useHarmonicMean) {
v = (Math.floor(10000.0 * v) / (100.0));
}
if (useGeometricMean) {
v = (Math.floor(10.0 * v) / 10.0);
}
if ((ind >= minToRank) && (v != oldv)) {
break;
}
if (v === 0.0) {
break;
}
if (oldv != v) {
if (useDenseRankings) {
rank = rank + 1;
}
else {
rank = rank + ties;
ties = 0;
}
}
s += "\n<tr><td>" + rank + "</td>";
s += "<td><div onclick=\"toggle('" + dept + "')\" class=\"hovertip\" id=\"" + dept + "-widget\"><font color=\"blue\">►</font> " + dept + "</div>";
s += '<div style="display:none;" id="' + dept + '">' + univtext[dept] + '</div>';
s += "</td>";
if (displayPercentages) {
/* Show average */
if (useArithmeticMean || useHarmonicMean) {
s += '<td align="right">' + (Math.floor(10000.0 * v) / (100.0)).toPrecision(2) + "%</td>";
}
if (useGeometricMean) {
s += '<td align="right">' + (Math.floor(10.0 * v) / 10.0).toFixed(1) + "</td>";
}
}
else {
/* Show count */
s += '<td align="right">' + (Math.floor(100.0 * v) / 100.0) + "</td>";
}
s += '<td align="right">' + deptCounts[dept] + "<br />"; /* number of faculty */
s += "</td>";
s += "</tr>\n";
ties++;
oldv = v;
}
s += "</tbody>" + "</table>" + "<br />";
if (allowRankingChange) {
/* Disable option to change ranking approach for now. */
if (useDenseRankings) {
s += '<em><a class="only_these_areas" onClick="deactivateDenseRankings(); return false;"><font color="blue"><b>Using dense rankings. Click to use competition rankings.</b></font></a><em>';
}
else {
s += '<em><a class="only_these_areas" onClick="activateDenseRankings(); return false;"><font color="blue"><b>Using competition rankings. Click to use dense rankings.</b></font></a></em>';
}
}
s += "</div>" + "</div>" + "\n";
s += "<br>" + "</body>" + "</html>";
}
else {
/* Nothing selected. */
s = "<h4>Please select at least one area.</h4>";
}
setTimeout((function (str) { redisplay(str); })(s), 0);
return false;
}
function activateDenseRankings() {
useDenseRankings = true;
rank();
return false;
}
function deactivateDenseRankings() {
useDenseRankings = false;
rank();
return false;
}
window.onload = init;