forked from emeryberger/CSrankings
-
Notifications
You must be signed in to change notification settings - Fork 0
/
csrankings.ts
1216 lines (1115 loc) · 38.6 KB
/
csrankings.ts
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
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
CSrankings.ts
@author Emery Berger <emery@cs.umass.edu> 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/d3.d.ts" />
/// <reference path="./typescript/d3pie.d.ts" />
declare function escape(s:string): string;
declare function unescape(s:string): string;
interface Article {
readonly name : string;
readonly conf : string;
readonly area : string;
readonly subarea : string;
readonly year : number;
readonly title : string;
readonly institution : string;
};
interface Author {
readonly name : string;
readonly dept : string;
readonly area : string;
readonly subarea : string;
readonly count : string;
readonly adjustedcount : string;
readonly year : number;
};
interface Coauthor {
readonly author : string;
readonly coauthor : string;
readonly year : number;
readonly area : string;
};
interface CountryInfo {
readonly institution : string;
readonly region : "USA" | "europe" | "canada" | "northamerica" | "australasia" | "asia" | "world";
};
interface Alias {
readonly alias : string;
readonly name : string;
};
interface HomePage {
readonly name : string;
readonly homepage : string;
};
interface AreaMap {
readonly area : string;
readonly title : string;
};
interface ChartData {
readonly label : string;
readonly value : number;
readonly color : string;
};
class CSRankings {
constructor() {
/* Build the areaDict dictionary: areas -> names used in pie charts
and areaPosition dictionary: areas -> position in area array
*/
for (let position = 0; position < CSRankings.areaMap.length; position++) {
const { area, title } = CSRankings.areaMap[position];
CSRankings.areas[position] = area;
CSRankings.areaNames[position] = title;
CSRankings.fields[position] = area;
CSRankings.areaDict[area] = CSRankings.areaNames[position];
CSRankings.areaPosition[area] = position;
}
for (let area of CSRankings.aiAreas) {
CSRankings.aiFields.push (CSRankings.areaPosition[area]);
}
for (let area of CSRankings.systemsAreas) {
CSRankings.systemsFields.push (CSRankings.areaPosition[area]);
}
for (let area of CSRankings.theoryAreas) {
CSRankings.theoryFields.push (CSRankings.areaPosition[area]);
}
for (let area of CSRankings.interdisciplinaryAreas) {
CSRankings.otherFields.push (CSRankings.areaPosition[area]);
}
// CSRankings.setAllCheckboxes();
let next = ()=> {
CSRankings.loadAliases(CSRankings.aliases, function() {
CSRankings.loadHomepages(CSRankings.homepages,
function() {
CSRankings.loadAuthorInfo(function() {
CSRankings.loadCountryInfo(CSRankings.countryInfo,
CSRankings.rank);
});
});
});
};
CSRankings.activateAll();
if (CSRankings.showCoauthors) {
CSRankings.loadCoauthors(next);
} else {
next();
}
}
private static readonly coauthorFile = "faculty-coauthors.csv";
private static readonly authorinfoFile = "generated-author-info.csv";
private static readonly countryinfoFile = "country-info.csv";
private static readonly aliasFile = "dblp-aliases.csv";
private static readonly homepagesFile = "homepages.csv";
private static readonly allowRankingChange = false; /* Can we change the kind of rankings being used? */
private static readonly showCoauthors = false;
private static readonly maxCoauthors = 30; /* Max co-authors to display. */
private static readonly parentMap : {[key : string] : string }
= { 'aaai' : 'ai',
'ijcai' : 'ai',
'cvpr' : 'vision',
'eccv' : 'vision',
'iccv' : 'vision'
};
private static readonly childMap : {[key : string] : [string] }
= { 'ai' : ['aaai', 'ijcai'],
'vision' : ['cvpr', 'eccv', 'iccv'] };
private static readonly areaMap : Array<AreaMap>
= [ { area : "ai", title : "AI" },
// { area : "aaai", title : "AI" },
// { area : "ijcai", title : "AI" },
{ area : "vision", title : "Vision" },
// { area : "cvpr", title : "Vision" },
// { area : "eccv", title : "Vision" },
// { area : "iccv", title : "Vision" },
{ area : "mlmining", title : "ML" },
{ area : "nlp", title : "NLP" },
{ area : "ir", title : "Web & IR" },
{ area : "arch", title : "Arch" },
{ area : "comm", title : "Networks"},
{ area : "sec", title : "Security"},
{ area : "mod", title : "DB"},
{ area : "hpc", title : "HPC"},
{ area : "mobile", title : "Mobile"},
{ area : "metrics", title : "Metrics"},
{ area : "ops", title : "OS" },
{ area : "plan", title : "PL" },
{ area : "soft", title : "SE" },
{ area : "act", title : "Theory" },
{ area : "crypt", title: "Crypto" },
{ area : "log", title : "Logic" },
{ area : "graph", title : "Graphics" },
{ area : "chi", title : "HCI" },
{ area : "robotics", title : "Robotics" },
{ area : "bio", title : "Comp. Biology" },
{ area : "da", title : "EDA" },
{ area : "bed", title : "Embedded" },
{ area : "vis", title : "Visualization" }
//,{ area : "ecom", title : "ECom" }
//,{ area : "cse", title : "CSEd" }
];
private static readonly aiAreas = [ "ai", "vision", "mlmining", "nlp", "ir" ];
private static readonly systemsAreas = [ "arch", "comm", "sec", "mod", "hpc", "mobile", "metrics", "ops", "plan", "soft", "da", "bed" ];
private static readonly theoryAreas = [ "act", "crypt", "log" ];
private static readonly interdisciplinaryAreas = [ "graph", "chi", "robotics", "bio", "vis", "ecom" ];
private static readonly areas : Array<string> = [];
private static readonly areaNames : Array<string> = [];
private static readonly fields : Array<string> = [];
private static readonly aiFields : Array<number> = [];
private static readonly systemsFields : Array<number> = [];
private static readonly theoryFields : Array<number> = [];
private static readonly otherFields : Array<number> = [];
/* Map area to its name (from areaNames). */
private static readonly areaDict : {[key : string] : string } = {};
/* Map area to its position in the list. */
private static readonly areaPosition : {[key : string] : number } = {};
/* Map aliases to canonical author name. */
private static readonly aliases : {[key : string] : string } = {};
/* Map institution to (non-US) region. */
private static readonly countryInfo : {[key : string] : string } = {};
private static articles : Array<Article>;
/* Map name to home page. */
private static readonly homepages : {[key : string] : string } = {};
/* Set to true for "dense rankings" vs. "competition rankings". */
private static readonly useDenseRankings : boolean = false;
/* The data which will hold the parsed CSV of author info. */
private static authors : Array<Author> = [];
/* The data which will hold the parsed CSV of co-author info. */
private static coauthors : Array<Coauthor> = [];
/* Map authors to the areas they have published in (for pie chart display). */
private static authorAreas : {[name : string] : {[area : string] : number } } = {};
/* Computed stats (univagg). */
private static stats : {[key: string] : number} = {};
private static areaDeptAdjustedCount : {[key: string] : number} = {}; /* area+dept */
/* Colors for all areas. */
private static readonly color : Array<string> =
["#f30000", "#0600f3", "#00b109", "#14e4b4", "#0fe7fb", "#67f200", "#ff7e00", "#8fe4fa", "#ff5300", "#640000", "#3854d1", "#d00ed8", "#7890ff", "#01664d", "#04231b", "#e9f117", "#f3228e", "#7ce8ca", "#ff5300", "#ff5300", "#7eff30", "#9a8cf6", "#79aff9", "#bfbfbf", "#56b510", "#00e2f6", "#ff4141", "#61ff41" ];
private static readonly RightTriangle = "►"; // right-facing triangle symbol (collapsed view)
private static readonly DownTriangle = "▼"; // downward-facing triangle symbol (expanded view)
private static readonly PieChart = "◕"; // symbol that looks close enough to a pie chart
private static translateNameToDBLP(name : string) : string {
// Ex: "Emery D. Berger" -> "http://dblp.uni-trier.de/pers/hd/b/Berger:Emery_D="
// First, replace spaces and non-ASCII characters (not complete).
// Known issue: does not properly handle suffixes like Jr., III, etc.
name = name.replace(/'|\-|\./g, "=");
// name = name.replace(/\-/g, "=");
// name = name.replace(/\./g, "=");
name = name.replace(/Á/g, "=Aacute=");
name = name.replace(/á/g, "=aacute=");
name = name.replace(/è/g, "=egrave=");
name = name.replace(/é/g, "=eacute=");
name = name.replace(/ï/g, "=iuml=");
name = name.replace(/ó/g, "=oacute=");
name = name.replace(/ç/g, "=ccedil=");
name = name.replace(/ä/g, "=auml=");
name = name.replace(/ö/g, "=ouml=");
name = name.replace(/ø/g, "=oslash=");
name = name.replace(/Ö/g, "=Ouml=");
name = name.replace(/ü/g, "=uuml=");
let splitName = name.split(" ");
let lastName = splitName[splitName.length - 1];
let disambiguation = ""
if (parseInt(lastName) > 0) {
// this was a disambiguation entry; go back.
disambiguation = lastName;
splitName.pop();
lastName = splitName[splitName.length - 1] + "_" + disambiguation;
}
splitName.pop();
let newName = splitName.join(" ");
newName = newName.replace(/\s/g, "_");
newName = newName.replace(/\-/g, "=");
let str = "http://dblp.uni-trier.de/pers/hd";
const lastInitial = lastName[0].toLowerCase();
str += "/" + lastInitial + "/" + lastName + ":" + newName;
return str;
}
/* Create the prologue that we preface each generated HTML page with (the results). */
private static makePrologue() : string {
const 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/ */
private static compareNames (a : string, b : string) : number {
//split the names as strings into arrays
const aName = a.split(" ");
const 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
const aLastName = aName[aName.length - 1];
const 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;
}
/* Create a pie chart */
private static makeChart(name : string) : void
{
console.assert (CSRankings.color.length >= CSRankings.areas.length, "Houston, we have a problem.");
let data : Array<ChartData> = [];
let datadict : {[key : string] : number } = {};
const keys = CSRankings.areas;
const uname = unescape(name);
for (let i = 0; i < keys.length; i++) {
let key = keys[i];
let value = CSRankings.authorAreas[uname][key];
// Use adjusted count if this is for a department.
if (uname in CSRankings.stats) {
value = CSRankings.areaDeptAdjustedCount[key+uname] + 1;
if (value == 1) {
value = 0;
}
}
// Round it to the nearest 0.1.
value = Math.round(value * 10) / 10;
if (value > 0) {
if (key in CSRankings.parentMap) {
// key = CSRankings.parentMap[key];
}
if (!(key in datadict)) {
datadict[key] = 0;
}
datadict[key] += value;
}
}
for (let key in datadict) {
data.push({ "label" : CSRankings.areaDict[key],
"value" : datadict[key],
"color" : CSRankings.color[CSRankings.areaPosition[key]] });
}
new d3pie(name + "-chart", {
"header": {
"title": {
"text": uname,
"fontSize": 24,
"font": "open sans"
},
"subtitle": {
"text": "Publication Profile",
"color": "#999999",
"fontSize": 14,
"font": "open sans"
},
"titleSubtitlePadding": 9
},
"size": {
"canvasHeight": 500,
"canvasWidth": 500,
"pieInnerRadius": "38%",
"pieOuterRadius": "83%"
},
"data": {
"content": data,
"smallSegmentGrouping": {
"enabled": true,
"value": 1
},
},
"labels": {
"outer": {
"pieDistance": 32
},
"inner": {
//"format": "percentage", // "value",
//"hideWhenLessThanPercentage": 0 // 2 // 100 // 2
"format": "value",
"hideWhenLessThanPercentage": 2 // 100 // 2
},
"mainLabel": {
"fontSize": 12
},
"percentage": {
"color": "#ffffff",
"decimalPlaces": 0
},
"value": {
"color": "#ffffff", // "#adadad",
"fontSize": 10
},
"lines": {
"enabled": true
},
"truncation": {
"enabled": true
}
},
"effects": {
"load": {
"effect": "none"
},
"pullOutSegmentOnClick": {
"effect": "linear",
"speed": 400,
"size": 8
}
},
"misc": {
"gradient": {
"enabled": true,
"percentage": 100
}
}
});
}
private static loadCoauthors(cont : () => void ) : void {
Papa.parse(CSRankings.coauthorFile, {
download : true,
header: true,
complete : (results)=> {
const data : any = results.data;
CSRankings.coauthors = data as Array<Coauthor>;
setTimeout(cont, 0);
}
});
}
private static loadAliases(aliases: {[key : string] : string },
cont : ()=> void ) : void {
Papa.parse(CSRankings.aliasFile, {
header: true,
download : true,
complete : (results)=> {
const data : any = results.data;
const d = data as Array<Alias>;
for (let aliasPair of d) {
aliases[aliasPair.alias] = aliasPair.name;
}
setTimeout(cont, 0);
}
});
}
private static loadArticles(cont : () => void) : void {
jQuery.getJSON("articles.json", (_ : Array<Article>) => {
/* disabled for now
CSRankings.articles = data; */
setTimeout(cont, 0);
});
}
private static loadCountryInfo(countryInfo : {[key : string] : string },
cont : () => void ) : void {
Papa.parse(CSRankings.countryinfoFile, {
header: true,
download : true,
complete : (results)=> {
const data : any = results.data;
const ci = data as Array<CountryInfo>;
for (let info of ci) {
countryInfo[info.institution] = info.region;
}
setTimeout(cont, 0);
}
});
}
private static loadAuthorInfo(cont : () => void) : void {
Papa.parse(CSRankings.authorinfoFile, {
download : true,
header : true,
complete: (results)=> {
const data : any = results.data;
this.authors = data as Array<Author>;
for (let i = 0; i < CSRankings.fields.length; i++) {
const str = 'input[name='+CSRankings.fields[i]+']';
jQuery(str).click(()=>{
/* if (jQuery(str).hasClass("parent")) {
// Parent (un)checked => all children (un)checked
let isChecked = jQuery(str).prop('checked');
let parent = CSRankings.fields[i];
for (let kid of CSRankings.childMap[parent]) {
jQuery("input[name="+kid+"]").prop('checked', isChecked);
}
}
if (jQuery(str).hasClass("child")) {
let s = jQuery(str).attr("id");
let parent = CSRankings.parentMap[s];
// Uncheck a child => uncheck the parent.
if (!jQuery("input[name="+CSRankings.fields[i]+"]").prop('checked')) {
jQuery("input[name="+parent+"]").prop('checked', false);
} else {
// All children checked => check the parent.
let v = true;
for (let kid of CSRankings.childMap[parent]) {
let checked = jQuery("input[name="+kid+"]").prop('checked');
if (!checked) {
v = false;
break;
}
}
if (v) {
jQuery("input[name="+parent+"]").prop('checked', true);
}
}
} */
this.rank();
});
}
setTimeout(cont, 0);
}
});
}
private static loadHomepages(homepages : {[key : string] : string },
cont : ()=> void ) : void {
Papa.parse(CSRankings.homepagesFile, {
header: true,
download : true,
complete : (results)=> {
const data : any = results.data;
const d = data as Array<HomePage>;
for (let namePage of d) {
if (typeof namePage.homepage === 'undefined') {
continue
}
homepages[namePage.name.trim()] = namePage.homepage.trim();
}
setTimeout(cont, 0);
}
});
}
private static inRegion(dept : string,
regions : string): boolean
{
switch (regions) {
case "world":
break;
case "USA":
if (dept in CSRankings.countryInfo) {
return false;
}
break;
case "europe":
if (!(dept in CSRankings.countryInfo)) { // USA
return false;
}
if (CSRankings.countryInfo[dept] != "europe") {
return false;
}
break;
case "canada":
if (!(dept in CSRankings.countryInfo)) { // USA
return false;
}
if (CSRankings.countryInfo[dept] != "canada") {
return false;
}
break;
case "northamerica":
if ((dept in CSRankings.countryInfo) && (CSRankings.countryInfo[dept] != "canada")) {
return false;
}
break;
case "australasia":
if (!(dept in CSRankings.countryInfo)) { // USA
return false;
}
if (CSRankings.countryInfo[dept] != "australasia") {
return false;
}
break;
case "southamerica":
if (!(dept in CSRankings.countryInfo)) { // USA
return false;
}
if (CSRankings.countryInfo[dept] != "southamerica") {
return false;
}
break;
case "asia":
if (!(dept in CSRankings.countryInfo)) { // USA
return false;
}
if (CSRankings.countryInfo[dept] != "asia") {
return false;
}
break;
}
return true;
}
private static activateFields(value : boolean,
fields : Array<number>) : boolean
{
for (let i = 0; i < fields.length; i++) {
const str = "input[name=" + CSRankings.fields[fields[i]] + "]";
jQuery(str).prop('checked', value);
}
CSRankings.rank();
return false;
}
private static sortIndex(univagg : {[key: string] : number}) : string[]
{
let 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;
}
private static computeCoauthors(coauthors : Array<Coauthor>,
startyear : number,
endyear : number,
weights : {[key:string] : number})
: {[key : string] : Set<string> }
{
let coauthorList : {[key : string] : Set<string> } = {};
for (let c in coauthors) {
if (!coauthors.hasOwnProperty(c)) {
continue;
}
const { author, coauthor, year, area } = coauthors[c];
if ((weights[area] === 0) || (year < startyear) || (year > endyear)) {
continue;
}
if (!(author in coauthorList)) {
coauthorList[author] = new Set([]);
}
coauthorList[author].add(coauthor);
}
return coauthorList;
}
private static countAuthorAreas(authors : Array<Author>,
startyear : number,
endyear : number,
weights : {[key:string] : number},
authorAreas : {[name : string] : {[area : string] : number }}) : void
{
for (let r in authors) {
if (!authors.hasOwnProperty(r)) {
continue;
}
const auth = authors[r];
const year = auth.year;
if ((year < startyear) || (year > endyear)) {
continue;
}
const theArea = auth.area;
if (weights[theArea] === 0) {
continue;
}
const theDept = auth.dept;
const theCount = parseFloat(auth.count);
// const theCount = parseFloat(auth.adjustedcount);
let name : string = auth.name;
if (name in CSRankings.aliases) {
name = CSRankings.aliases[name];
}
if (!(name in authorAreas)) {
authorAreas[name] = {};
for (let area in CSRankings.areaDict) {
if (CSRankings.areaDict.hasOwnProperty(area)) {
authorAreas[name][area] = 0;
}
}
}
if (!(theDept in authorAreas)) {
authorAreas[theDept] = {};
for (let area in CSRankings.areaDict) {
if (CSRankings.areaDict.hasOwnProperty(area)) {
authorAreas[theDept][area] = 0;
}
}
}
authorAreas[name][theArea] += theCount;
authorAreas[theDept][theArea] += theCount;
}
}
/* Build the dictionary of departments (and count) to be ranked. */
private static buildDepartments(authors : Array<Author>,
startyear : number,
endyear : number,
weights : {[key:string] : number},
regions : string,
areaDeptAdjustedCount : {[key:string] : number},
deptCounts : {[key:string] : number},
deptNames : {[key:string] : Array<string>},
facultycount : {[key:string] : number},
facultyAdjustedCount : {[key:string] : number}) : void
{
/* contains an author name if that author has been processed. */
let visited : {[key:string] : boolean} = {};
for (let r in authors) {
if (!authors.hasOwnProperty(r)) {
continue;
}
let { name, year, area, dept } = authors[r];
if (name in CSRankings.aliases) {
name = CSRankings.aliases[name];
}
if (typeof dept === 'undefined') {
continue;
}
if ((weights[area] === 0) || (year < startyear) || (year > endyear)) {
continue;
}
if (!CSRankings.inRegion(dept, regions)) {
continue;
}
// If this area is a child area, accumulate totals for parent.
if (area in CSRankings.parentMap) {
area = CSRankings.parentMap[area];
}
const areaDept : string = area+dept;
const nameDept : string = name+dept;
if (!(areaDept in areaDeptAdjustedCount)) {
areaDeptAdjustedCount[areaDept] = 0;
}
const count : number = parseInt(authors[r].count);
const adjustedCount : number = parseFloat(authors[r].adjustedcount);
areaDeptAdjustedCount[areaDept] += adjustedCount;
/* Is this the first time we have seen this person? */
if (!(name in visited)) {
visited[name] = true;
facultycount[nameDept] = 0;
facultyAdjustedCount[nameDept] = 0;
if (!(dept in deptCounts)) {
deptCounts[dept] = 0;
deptNames[dept] = <Array<string>>[];
}
deptNames[dept].push(name);
deptCounts[dept] += 1;
}
facultycount[nameDept] += count;
facultyAdjustedCount[nameDept] += adjustedCount;
}
}
/* Compute aggregate statistics. */
private static computeStats(deptNames : {[key:string] : Array<string> },
areaDeptAdjustedCount : {[key:string] : number},
areas : Array<string>,
numAreas : number,
displayPercentages : boolean,
weights : {[key:string] : number})
: {[key: string] : number}
{
CSRankings.stats = {};
let univagg : {[key: string] : number} = {};
for (let dept in deptNames) {
if (!deptNames.hasOwnProperty(dept)) {
continue;
}
if (displayPercentages) {
univagg[dept] = 1;
} else {
univagg[dept] = 0;
}
for (let area of areas) {
// If the area is a child, ignore it.
if (area in CSRankings.parentMap) {
continue;
}
let areaDept = area+dept;
if (!(areaDept in areaDeptAdjustedCount)) {
areaDeptAdjustedCount[areaDept] = 0;
}
if (weights[area] != 0) {
if (displayPercentages) {
// Adjusted (smoothed) geometric mean.
univagg[dept] *= (areaDeptAdjustedCount[areaDept] + 1.0);
} else {
univagg[dept] += areaDeptAdjustedCount[areaDept];
}
}
}
if (displayPercentages) {
// finally compute geometric mean.
univagg[dept] = Math.pow(univagg[dept], 1/numAreas);
}
}
return univagg;
}
/* Updates the 'weights' of each area from the checkboxes. */
/* Returns the number of areas selected (checked). */
private static updateWeights(weights : {[key: string] : number}) : number
{
let numAreas = 0;
for (let ind = 0; ind < CSRankings.areas.length; ind++) {
let area = CSRankings.areas[ind];
weights[area] = jQuery('input[name=' + CSRankings.fields[ind] + ']').prop('checked') ? 1 : 0;
if (weights[area] === 1) {
/* One more area checked. */
numAreas++;
}
}
return numAreas;
}
private static canonicalizeNames(deptNames : {[key: string] : Array<string> },
facultycount : {[key: string] : number},
facultyAdjustedCount: {[key: string] : number}) : void
{
for (let dept in deptNames) {
if (!deptNames.hasOwnProperty(dept)) {
continue;
}
for (let ind = 0; ind < deptNames[dept].length; ind++) {
let name = deptNames[dept][ind];
if (name in CSRankings.aliases) {
deptNames[dept][ind] = CSRankings.aliases[name];
if (!(CSRankings.aliases[name]+dept in facultycount)) {
facultycount[CSRankings.aliases[name]+dept] = facultycount[name+dept];
facultyAdjustedCount[CSRankings.aliases[name]+dept] = facultyAdjustedCount[name+dept];
} else {
facultycount[CSRankings.aliases[name]+dept] += facultycount[name+dept];
facultyAdjustedCount[CSRankings.aliases[name]+dept] += facultyAdjustedCount[name+dept];
}
}
}
}
}
/* Build drop down for faculty names and paper counts. */
private static buildDropDown(deptNames : {[key: string] : Array<string> },
facultycount : {[key: string] : number},
facultyAdjustedCount: {[key: string] : number},
coauthorList : {[key : string] : Set<string> })
: {[key: string] : string}
{
let univtext : {[key:string] : string} = {};
for (let dept in deptNames) {
if (!deptNames.hasOwnProperty(dept)) {
continue;
}
let p = '<div class="row"><div class="table"><table class="table-striped" width="100%"><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. */
let fc : {[key:string] : number} = {};
for (let name of deptNames[dept]) {
fc[name] = facultycount[name+dept];
}
let keys = Object.keys(fc);
keys.sort(function(a : string, b : string){
if (fc[b] === fc[a]) {
let fb = Math.round(10.0 * facultyAdjustedCount[b+dept]) / 10.0;
let fa = Math.round(10.0 * facultyAdjustedCount[a+dept]) / 10.0;
if (fb === fa) {
return CSRankings.compareNames(a, b);
}
return fb - fa;
} else {
return fc[b] - fc[a];
}
});
for (let name of keys) {
if (CSRankings.showCoauthors) {
/* Build up text for co-authors. */
let 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. */
let l : Array<string> = [];
coauthorList[name].forEach((item, _)=>{
l.push(item);
});
if (l.length > CSRankings.maxCoauthors) {
coauthorStr = "(more than "+CSRankings.maxCoauthors+" senior co-authors)";
} else {
l.sort(CSRankings.compareNames);
l.forEach((item, _)=>{
coauthorStr += item + "\n";
});
/* Trim off the trailing newline. */
coauthorStr = coauthorStr.slice(0,coauthorStr.length-1);
}
}
let homePage = encodeURI(CSRankings.homepages[name]);
let dblpName = CSRankings.translateNameToDBLP(name);
p += "<tr><td> </td><td><small>"
+ '<a title="Click for author\'s home page." target="_blank" href="'
+ homePage
+ '" '
+ 'onclick="trackOutboundLink(\''
+ homePage
+ '\', true); return false;"'
+ '>'
+ name
+ '</a> '
+ "<span onclick=\"CSRankings.toggleChart('"
+ escape(name)
+ "')\" class=\"hovertip\" ><font color=\"blue\">" + CSRankings.PieChart + "</font></span>"
+ '</small>'
+ '</td><td align="right"><small>'
+ '<a title="Click for author\'s DBLP entry." target="_blank" href="'
+ dblpName
+ '" '
+ 'onclick="trackOutboundLink(\''
+ dblpName
+ '\', true); return false;"'
+ '>'
+ fc[name]
+ '</a>'
+ "</small></td>"
+ '<td align="right"><small>'
// + '<abbr title="' + coauthorStr + '">'
+ (Math.round(10.0 * facultyAdjustedCount[name+dept]) / 10.0).toFixed(1)
// + '</abbr>'
+ "</small></td></tr>"
+ "<tr><td colspan=\"4\">"
+ '<div style="display:none;" id="' + escape(name) + "-chart" + '">'
+ '</div>'
+ "</td></tr>"
;
}
p += "</tbody></table></div></div>";
univtext[dept] = p;
}
return univtext;
}
private static buildOutputString(displayPercentages : boolean,
numAreas : number,
univagg : {[key: string] : number},
deptCounts: {[key: string] : number},
univtext: {[key:string] : string}) : string
{
let s = CSRankings.makePrologue();
/* Show the top N (with more if tied at the end) */
let minToRank = parseInt(jQuery("#minToRank").find(":selected").val());
if (displayPercentages) {
s = s + '<thead><tr><th align="left">Rank </th><th align="right">Institution </th><th align="right"><abbr title="Geometric mean count 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) {
let ties = 1; /* number of tied entries so far (1 = no tie yet); used to implement "competition rankings" */
let rank = 0; /* index */
let oldv = 9999999.999; /* old number - to track ties */
/* Sort the university aggregate count from largest to smallest. */
let keys2 = CSRankings.sortIndex(univagg);
/* Display rankings until we have shown `minToRank` items or
while there is a tie (those all get the same rank). */
for (let ind = 0; ind < keys2.length; ind++) {
const dept = keys2[ind];
const v = Math.round(10.0 * univagg[dept]) / 10.0;
if ((ind >= minToRank) && (v != oldv)) {
break;
}
if (v === 0.0) {
break;
}
if (oldv != v) {
if (CSRankings.useDenseRankings) {
rank = rank + 1;
} else {
rank = rank + ties;
ties = 0;
}
}
const esc = escape(dept);
s += "\n<tr><td>" + rank + "</td>";
s += "<td>"
+ "<span onclick=\"CSRankings.toggleFaculty('" + dept + "')\" class=\"hovertip\" id=\"" + dept + "-widget\">" + "<font color=\"blue\">" + CSRankings.RightTriangle + "</font></span> "
+ "<span onclick=\"CSRankings.toggleFaculty('" + dept + "')\" class=\"hovertip\">" + dept + "</span>";
s += " <font color=\"blue\">" + "<span onclick=\"CSRankings.toggleChart('"
+ esc
+ "')\" class=\"hovertip\" id=\""
+ esc