Skip to content

Commit b548d47

Browse files
committed
Add a convenience method to bin cites per year
1 parent 7f075cf commit b548d47

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

scholarly/_scholarly.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from dotenv import find_dotenv, load_dotenv
1515
from .author_parser import AuthorParser
1616
from .publication_parser import PublicationParser, _SearchScholarIterator
17-
from .data_types import Author, AuthorSource, Journal, Publication, PublicationSource
17+
from .data_types import Author, AuthorSource, CitesPerYear, Journal, Publication, PublicationSource
1818

1919
_AUTHSEARCH = '/citations?hl=en&view_op=search_authors&mauthors={0}'
2020
_KEYWORDSEARCH = '/citations?hl=en&view_op=search_authors&mauthors=label:{0}'
@@ -253,6 +253,25 @@ def bibtex(self, object: Publication)->str:
253253
self.logger.warning("Object not supported for bibtex exportation")
254254
return
255255

256+
@staticmethod
257+
def _bin_citations_by_year(cites_per_year: CitesPerYear, year_end):
258+
years = []
259+
y_hi, y_lo = year_end, year_end
260+
running_count = 0
261+
for y in sorted(cites_per_year, reverse=True):
262+
if running_count + cites_per_year[y] <= 1000:
263+
running_count += cites_per_year[y]
264+
y_lo = y
265+
else:
266+
running_count = cites_per_year[y]
267+
years.append((y_hi, y_lo))
268+
y_hi = y
269+
270+
if running_count > 0:
271+
years.append((y_hi, y_lo))
272+
273+
return years
274+
256275
def citedby(self, object: Publication)->_SearchScholarIterator:
257276
"""Searches Google Scholar for other articles that cite this Publication
258277
and returns a Publication generator.

0 commit comments

Comments
 (0)