2323from ietf .submit .models import Submission
2424from ietf .group .models import Role , Group
2525from ietf .person .models import Person
26- from ietf .name .models import ReviewRequestStateName , ReviewResultName , CountryName
26+ from ietf .name .models import ReviewRequestStateName , ReviewResultName , CountryName , DocRelationshipName
27+ from ietf .person .name import plain_name
2728from ietf .doc .models import DocAlias , Document , State
28- from ietf .stats .utils import get_aliased_affiliations , get_aliased_countries
29+ from ietf .stats .utils import get_aliased_affiliations , get_aliased_countries , compute_hirsch_index
2930from ietf .ietfauth .utils import has_role
3031
3132def stats_index (request ):
@@ -103,7 +104,8 @@ def build_document_stats_url(stats_type_override=Ellipsis, get_overrides={}):
103104 ("author/affiliation" , "Affiliation" ),
104105 ("author/country" , "Country" ),
105106 ("author/continent" , "Continent" ),
106- ("author/citation" , "Citations" ),
107+ ("author/citations" , "Citations" ),
108+ ("author/hindex" , "Impact" ),
107109 ], lambda slug : build_document_stats_url (stats_type_override = slug ))
108110
109111
@@ -346,7 +348,7 @@ def generate_canonical_names(docalias_qs):
346348
347349 person_filters &= Q (documentauthor__document__in = docs_within_time_constraint )
348350
349- person_qs = Person .objects .filter (person_filters )
351+ person_qs = Person .objects .filter (person_filters , documentauthor__document = "draft-arkko-dual-stack-extra-lite" )
350352
351353 if document_type == "rfc" :
352354 doc_label = "RFC"
@@ -369,6 +371,8 @@ def count_bins(bins):
369371
370372 bins = defaultdict (list )
371373
374+ person_qs = Person .objects .filter (person_filters )
375+
372376 for name , document_count in person_qs .values_list ("name" ).annotate (Count ("documentauthor" )):
373377 bins [document_count ].append (name )
374378
@@ -378,7 +382,7 @@ def count_bins(bins):
378382 for document_count , names in sorted (bins .iteritems (), key = lambda t : t [0 ]):
379383 percentage = len (names ) * 100.0 / (total_persons or 1 )
380384 series_data .append ((document_count , percentage ))
381- table_data .append ((document_count , percentage , names ))
385+ table_data .append ((document_count , percentage , [ plain_name ( n ) for n in names ] ))
382386
383387 chart_data .append ({
384388 "data" : series_data ,
@@ -390,6 +394,8 @@ def count_bins(bins):
390394
391395 bins = defaultdict (list )
392396
397+ person_qs = Person .objects .filter (person_filters )
398+
393399 # Since people don't write the affiliation names in the
394400 # same way, and we don't want to go back and edit them
395401 # either, we transform them here.
@@ -410,7 +416,7 @@ def count_bins(bins):
410416 percentage = len (names ) * 100.0 / (total_persons or 1 )
411417 if affiliation :
412418 series_data .append ((affiliation , len (names )))
413- table_data .append ((affiliation , percentage , names ))
419+ table_data .append ((affiliation , percentage , [ plain_name ( n ) for n in names ] ))
414420
415421 series_data .sort (key = lambda t : t [1 ], reverse = True )
416422 series_data = series_data [:30 ]
@@ -428,6 +434,8 @@ def count_bins(bins):
428434
429435 bins = defaultdict (list )
430436
437+ person_qs = Person .objects .filter (person_filters )
438+
431439 # Since people don't write the country names in the
432440 # same way, and we don't want to go back and edit them
433441 # either, we transform them here.
@@ -457,7 +465,7 @@ def count_bins(bins):
457465 percentage = len (names ) * 100.0 / (total_persons or 1 )
458466 if country :
459467 series_data .append ((country , len (names )))
460- table_data .append ((country , percentage , names ))
468+ table_data .append ((country , percentage , [ plain_name ( n ) for n in names ] ))
461469
462470 series_data .sort (key = lambda t : t [1 ], reverse = True )
463471 series_data = series_data [:30 ]
@@ -477,6 +485,8 @@ def count_bins(bins):
477485
478486 bins = defaultdict (list )
479487
488+ person_qs = Person .objects .filter (person_filters )
489+
480490 name_country_set = set ((name , country )
481491 for name , country in person_qs .values_list ("name" , "documentauthor__country" ))
482492
@@ -497,7 +507,7 @@ def count_bins(bins):
497507 percentage = len (names ) * 100.0 / (total_persons or 1 )
498508 if continent :
499509 series_data .append ((continent , len (names )))
500- table_data .append ((continent , percentage , names ))
510+ table_data .append ((continent , percentage , [ plain_name ( n ) for n in names ] ))
501511
502512 series_data .sort (key = lambda t : t [1 ], reverse = True )
503513
@@ -506,6 +516,59 @@ def count_bins(bins):
506516 "animation" : False ,
507517 })
508518
519+ elif stats_type == "author/citations" :
520+ stats_title = "Number of citations of {}s written by author" .format (doc_label )
521+
522+ bins = defaultdict (list )
523+
524+ cite_relationships = list (DocRelationshipName .objects .filter (slug__in = ['refnorm' , 'refinfo' , 'refunk' , 'refold' ]))
525+ person_filters &= Q (documentauthor__document__docalias__relateddocument__relationship__in = cite_relationships )
526+
527+ person_qs = Person .objects .filter (person_filters )
528+
529+ for name , citations in person_qs .values_list ("name" ).annotate (Count ("documentauthor__document__docalias__relateddocument" )):
530+ bins [citations ].append (name )
531+
532+ total_persons = count_bins (bins )
533+
534+ series_data = []
535+ for citations , names in sorted (bins .iteritems (), key = lambda t : t [0 ], reverse = True ):
536+ percentage = len (names ) * 100.0 / (total_persons or 1 )
537+ series_data .append ((citations , percentage ))
538+ table_data .append ((citations , percentage , [plain_name (n ) for n in names ]))
539+
540+ chart_data .append ({
541+ "data" : sorted (series_data , key = lambda t : t [0 ]),
542+ "animation" : False ,
543+ })
544+
545+ elif stats_type == "author/hindex" :
546+ stats_title = "h-index for {}s written by author" .format (doc_label )
547+
548+ bins = defaultdict (list )
549+
550+ cite_relationships = list (DocRelationshipName .objects .filter (slug__in = ['refnorm' , 'refinfo' , 'refunk' , 'refold' ]))
551+ person_filters &= Q (documentauthor__document__docalias__relateddocument__relationship__in = cite_relationships )
552+
553+ person_qs = Person .objects .filter (person_filters )
554+
555+ values = person_qs .values_list ("name" , "documentauthor__document" ).annotate (Count ("documentauthor__document__docalias__relateddocument" ))
556+ for name , ts in itertools .groupby (values .order_by ("name" ), key = lambda t : t [0 ]):
557+ h_index = compute_hirsch_index ([citations for _ , document , citations in ts ])
558+ bins [h_index ].append (name )
559+
560+ total_persons = count_bins (bins )
561+
562+ series_data = []
563+ for citations , names in sorted (bins .iteritems (), key = lambda t : t [0 ], reverse = True ):
564+ percentage = len (names ) * 100.0 / (total_persons or 1 )
565+ series_data .append ((citations , percentage ))
566+ table_data .append ((citations , percentage , [plain_name (n ) for n in names ]))
567+
568+ chart_data .append ({
569+ "data" : sorted (series_data , key = lambda t : t [0 ]),
570+ "animation" : False ,
571+ })
509572
510573 return render (request , "stats/document_stats.html" , {
511574 "chart_data" : mark_safe (json .dumps (chart_data )),
0 commit comments