88from analytics import utils
99from analytics .custom_queries import custom_query
1010from scieloh5m5 import h5m5
11+ from articlemeta .client import ThriftClient as ArticleMetaThriftClient
12+ from citedby .client import ThriftClient as CitedbyThriftClient
1113
1214
1315PAGE_SIZE = 20
@@ -94,9 +96,7 @@ def __str__(self):
9496
9597def articlemeta (host ):
9698
97- address , port = host .split (':' )
98-
99- return ArticleMeta (address , port )
99+ return ArticleMeta (host )
100100
101101
102102def accessstats (host ):
@@ -115,9 +115,7 @@ def publicationstats(host):
115115
116116def bibliometrics (host ):
117117
118- address , port = host .split (':' )
119-
120- return BibliometricsStats (address , port )
118+ return BibliometricsStats (host )
121119
122120
123121class Stats (object ):
@@ -294,7 +292,7 @@ def citing_half_life(self, issn, collection, titles, citation_size=0):
294292 return self ._compute_citing_half_life (query_result )
295293
296294
297- class BibliometricsStats (clients . Citedby ):
295+ class BibliometricsStats (CitedbyThriftClient ):
298296
299297 def _compute_google_h5m5 (self , data ):
300298
@@ -342,7 +340,23 @@ def document_received_citations(self, document, py_range=None):
342340 except :
343341 return {}
344342
345- return {'total' : data .get ('article' , {}).get ('total_received' , 0 )}
343+ result = {
344+ 'total' : data .get ('article' , {}).get ('total_received' , 0 ),
345+ 'citedby' : data .get ('cited_by' , [])
346+ }
347+
348+ for item in result ['citedby' ]:
349+
350+ fa = item .get ('first_author' , {'given_names' : '' , 'surname' : '' })
351+
352+ item ['first_author_lt' ] = ''
353+ if not isinstance (fa , dict ):
354+ item ['first_author_lt' ] = fa
355+ else :
356+ item ['first_author_lt' ] = ', ' .join (
357+ [fa .get ('surname' , '' ), fa .get ('given_names' , '' )])
358+
359+ return result
346360
347361 @staticmethod
348362 def _compute_publication_and_citing_years (query_result ):
@@ -423,8 +437,8 @@ def publication_and_citing_years(self, issn, titles, py_range=None, size=0, cita
423437 body .update (aggs )
424438
425439 query_parameters = [
426- clients . citedby_thrift .kwargs ('size' , '0' ),
427- clients . citedby_thrift .kwargs ('search_type' , 'count' )
440+ self . CITEDBY_THRIFT .kwargs ('size' , '0' ),
441+ self . CITEDBY_THRIFT .kwargs ('search_type' , 'count' )
428442 ]
429443
430444 query_result = json .loads (self .client .search (json .dumps (body ), query_parameters ))
@@ -515,8 +529,8 @@ def self_citations(self, issn, titles, py_range=None, size=0, raw=False):
515529 body .update (aggs )
516530
517531 query_parameters = [
518- clients . citedby_thrift .kwargs ('size' , '0' ),
519- clients . citedby_thrift .kwargs ('search_type' , 'count' )
532+ self . CITEDBY_THRIFT .kwargs ('size' , '0' ),
533+ self . CITEDBY_THRIFT .kwargs ('search_type' , 'count' )
520534 ]
521535
522536 query_result = json .loads (self .client .search (json .dumps (body ), query_parameters ))
@@ -588,8 +602,8 @@ def granted_citations(self, issn, size=0, py_range=None, raw=False):
588602 body .update (aggs )
589603
590604 query_parameters = [
591- clients . citedby_thrift .kwargs ('size' , '0' ),
592- clients . citedby_thrift .kwargs ('search_type' , 'count' )
605+ self . CITEDBY_THRIFT .kwargs ('size' , '0' ),
606+ self . CITEDBY_THRIFT .kwargs ('search_type' , 'count' )
593607 ]
594608
595609 query_result = json .loads (self .client .search (json .dumps (body ), query_parameters ))
@@ -667,8 +681,8 @@ def received_citations_by_year(self, issn, titles, py_range=None, size=0, raw=Fa
667681 body .update (aggs )
668682
669683 query_parameters = [
670- clients . citedby_thrift .kwargs ('size' , '0' ),
671- clients . citedby_thrift .kwargs ('search_type' , 'count' )
684+ self . CITEDBY_THRIFT .kwargs ('size' , '0' ),
685+ self . CITEDBY_THRIFT .kwargs ('search_type' , 'count' )
672686 ]
673687
674688 query_result = json .loads (self .client .search (json .dumps (body ), query_parameters ))
@@ -745,8 +759,8 @@ def received_citations(self, issn, titles, py_range=None, size=0, raw=False):
745759 body .update (aggs )
746760
747761 query_parameters = [
748- clients . citedby_thrift .kwargs ('size' , '0' ),
749- clients . citedby_thrift .kwargs ('search_type' , 'count' )
762+ self . CITEDBY_THRIFT .kwargs ('size' , '0' ),
763+ self . CITEDBY_THRIFT .kwargs ('search_type' , 'count' )
750764 ]
751765
752766 query_result = json .loads (self .client .search (json .dumps (body ), query_parameters ))
@@ -824,8 +838,8 @@ def citing_forms(self, issn, titles, py_range=None, size=0, raw=False):
824838 body .update (aggs )
825839
826840 query_parameters = [
827- clients . citedby_thrift .kwargs ('size' , '0' ),
828- clients . citedby_thrift .kwargs ('search_type' , 'count' )
841+ self . CITEDBY_THRIFT .kwargs ('size' , '0' ),
842+ self . CITEDBY_THRIFT .kwargs ('search_type' , 'count' )
829843 ]
830844
831845 query_result = json .loads (self .client .search (json .dumps (body ), query_parameters ))
@@ -1562,7 +1576,7 @@ def by_publication_year(self, code, collection, field, py_range, sa_scope, la_sc
15621576 return query_result if raw else computed
15631577
15641578
1565- class ArticleMeta (clients . ArticleMeta ):
1579+ class ArticleMeta (ArticleMetaThriftClient ):
15661580
15671581 @cache_region .cache_on_arguments ()
15681582 def certified_collections (self ):
0 commit comments