From 897fb1921dc0fe9a7506cb7d0e648a17d26f3ee4 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Thu, 17 Sep 2020 21:14:38 -0700 Subject: coverage: handle the case of hits, but none with years --- python/fatcat_web/search.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/python/fatcat_web/search.py b/python/fatcat_web/search.py index 7d9ce69f..755b303a 100644 --- a/python/fatcat_web/search.py +++ b/python/fatcat_web/search.py @@ -604,10 +604,11 @@ def get_elastic_preservation_by_year(query) -> List[dict]: buckets = resp.aggregations.year_preservation.buckets year_nums = set([int(h['key']['year']) for h in buckets]) year_dicts = dict() - for num in range(min(year_nums), max(year_nums)+1): - year_dicts[num] = dict(year=num, bright=0, dark=0, shadows_only=0, none=0) - for row in buckets: - year_dicts[int(row['key']['year'])][row['key']['preservation']] = int(row['doc_count']) + if year_nums: + for num in range(min(year_nums), max(year_nums)+1): + year_dicts[num] = dict(year=num, bright=0, dark=0, shadows_only=0, none=0) + for row in buckets: + year_dicts[int(row['key']['year'])][row['key']['preservation']] = int(row['doc_count']) if app.config['FATCAT_MERGE_SHADOW_PRESERVATION']: for k in year_dicts.keys(): year_dicts[k]['none'] += year_dicts[k]['shadows_only'] -- cgit v1.2.3