Skip to content

Commit

Permalink
Merge pull request #95 from lisc-tools/sum
Browse files Browse the repository at this point in the history
[BUG] - Fix ArticlesAll for empty collection
  • Loading branch information
TomDonoghue authored Aug 30, 2024
2 parents 8652f40 + c2248b4 commit 54179c3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
18 changes: 12 additions & 6 deletions lisc/data/articles_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,18 @@ def create_summary(self):

self.summary['label'] = self.label
self.summary['n_articles'] = str(self.n_articles)
self.summary['top_author_name'] = ' '.join(self.authors.most_common()[0][0])
self.summary['top_author_count'] = str(self.authors.most_common()[0][1])
self.summary['top_journal_name'] = self.journals.most_common()[0][0]
self.summary['top_journal_count'] = str(self.journals.most_common()[0][1])
self.summary['top_keywords'] = [freq[0] for freq in self.keywords.most_common()[0:5]]
self.summary['first_publication'] = str(min(self.years.keys()))
if self.has_data:
self.summary['top_author_name'] = ' '.join(self.authors.most_common()[0][0])
self.summary['top_author_count'] = str(self.authors.most_common()[0][1])
self.summary['top_journal_name'] = self.journals.most_common()[0][0]
self.summary['top_journal_count'] = str(self.journals.most_common()[0][1])
self.summary['top_keywords'] = [freq[0] for freq in self.keywords.most_common()[0:5]]
self.summary['first_publication'] = str(min(self.years.keys()))
else:
labels = ['top_author_name', 'top_author_count', 'top_journal_name',
'top_journal_count', 'top_keywords', 'first_publication']
for label in labels:
self.summary[label] = None


def print_summary(self):
Expand Down
28 changes: 22 additions & 6 deletions lisc/tests/data/test_articles_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ def test_articles_all(tarts_data):
data_all = ArticlesAll(tarts_data)
assert data_all

def test_articles_all_none(tarts_none):

data_all = ArticlesAll(tarts_none)
assert data_all

def test_check(tarts_all):

tarts_all.check_frequencies(data_type='words')
Expand All @@ -23,8 +18,29 @@ def test_check(tarts_all):
def test_summary(tdb, tarts_all):

tarts_all.create_summary()

assert tarts_all.summary

tarts_all.print_summary()
tarts_all.save_summary(directory=tdb)

def test_articles_all_none(tarts_none):

data_all = ArticlesAll(tarts_none)
assert data_all

data_all.check_frequencies(data_type='words')
data_all.check_frequencies(data_type='keywords')

data_all.create_summary()
assert data_all.summary

def test_articles_all_empty(tarts):

data_all = ArticlesAll(tarts)
assert not data_all.has_data

data_all.check_frequencies(data_type='words')
data_all.check_frequencies(data_type='keywords')

data_all.create_summary()
assert data_all.summary

0 comments on commit 54179c3

Please sign in to comment.