From 9dc891b8098542bb089c8c47098b60a8beb76a53 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 2 Nov 2021 18:14:43 -0700 Subject: fmt (black): fatcat_web/ --- python/fatcat_web/graphics.py | 135 ++++++++++++++++++++++++++---------------- 1 file changed, 83 insertions(+), 52 deletions(-) (limited to 'python/fatcat_web/graphics.py') diff --git a/python/fatcat_web/graphics.py b/python/fatcat_web/graphics.py index b5a83f6c..c76408cd 100644 --- a/python/fatcat_web/graphics.py +++ b/python/fatcat_web/graphics.py @@ -1,4 +1,3 @@ - from typing import Dict, List, Tuple import pygal @@ -15,32 +14,40 @@ def ia_coverage_histogram(rows: List[Tuple]) -> pygal.Graph: raw_years = [int(r[0]) for r in rows] years = dict() if raw_years: - for y in range(min(raw_years), max(raw_years)+1): + for y in range(min(raw_years), max(raw_years) + 1): years[int(y)] = dict(year=int(y), available=0, missing=0) for r in rows: if r[1]: - years[int(r[0])]['available'] = r[2] + years[int(r[0])]["available"] = r[2] else: - years[int(r[0])]['missing'] = r[2] + years[int(r[0])]["missing"] = r[2] - years = sorted(years.values(), key=lambda x: x['year']) + years = sorted(years.values(), key=lambda x: x["year"]) CleanStyle.colors = ("green", "purple") label_count = len(years) if len(years) > 20: label_count = 10 - chart = pygal.StackedBar(dynamic_print_values=True, style=CleanStyle, - width=1000, height=500, x_labels_major_count=label_count, - show_minor_x_labels=False) - #chart.title = "Perpetual Access Coverage" + chart = pygal.StackedBar( + dynamic_print_values=True, + style=CleanStyle, + width=1000, + height=500, + x_labels_major_count=label_count, + show_minor_x_labels=False, + ) + # chart.title = "Perpetual Access Coverage" chart.x_title = "Year" - #chart.y_title = "Releases" - chart.x_labels = [str(y['year']) for y in years] - chart.add('via Fatcat', [y['available'] for y in years]) - chart.add('Missing', [y['missing'] for y in years]) + # chart.y_title = "Releases" + chart.x_labels = [str(y["year"]) for y in years] + chart.add("via Fatcat", [y["available"] for y in years]) + chart.add("Missing", [y["missing"] for y in years]) return chart -def preservation_by_year_histogram(rows: List[Dict], merge_shadows: bool = False) -> pygal.Graph: + +def preservation_by_year_histogram( + rows: List[Dict], merge_shadows: bool = False +) -> pygal.Graph: """ Note: this returns a raw pygal chart; it does not render it to SVG/PNG @@ -48,7 +55,7 @@ def preservation_by_year_histogram(rows: List[Dict], merge_shadows: bool = False There is also a 'year' key with float/int value. """ - years = sorted(rows, key=lambda x: x['year']) + years = sorted(rows, key=lambda x: x["year"]) if merge_shadows: CleanStyle.colors = ("red", "darkolivegreen", "limegreen") @@ -57,23 +64,32 @@ def preservation_by_year_histogram(rows: List[Dict], merge_shadows: bool = False label_count = len(years) if len(years) > 30: label_count = 10 - chart = pygal.StackedBar(dynamic_print_values=True, style=CleanStyle, - width=1000, height=500, x_labels_major_count=label_count, - show_minor_x_labels=False, x_label_rotation=20) - #chart.title = "Preservation by Year" + chart = pygal.StackedBar( + dynamic_print_values=True, + style=CleanStyle, + width=1000, + height=500, + x_labels_major_count=label_count, + show_minor_x_labels=False, + x_label_rotation=20, + ) + # chart.title = "Preservation by Year" chart.x_title = "Year" - #chart.y_title = "Count" - chart.x_labels = [str(y['year']) for y in years] + # chart.y_title = "Count" + chart.x_labels = [str(y["year"]) for y in years] if merge_shadows: - chart.add('None', [y['none'] + y['shadows_only'] for y in years]) + chart.add("None", [y["none"] + y["shadows_only"] for y in years]) else: - chart.add('None', [y['none'] for y in years]) - chart.add('Shadow', [y['shadows_only'] for y in years]) - chart.add('Dark', [y['dark'] for y in years]) - chart.add('Bright', [y['bright'] for y in years]) + chart.add("None", [y["none"] for y in years]) + chart.add("Shadow", [y["shadows_only"] for y in years]) + chart.add("Dark", [y["dark"] for y in years]) + chart.add("Bright", [y["bright"] for y in years]) return chart -def preservation_by_date_histogram(rows: List[Dict], merge_shadows: bool = False) -> pygal.Graph: + +def preservation_by_date_histogram( + rows: List[Dict], merge_shadows: bool = False +) -> pygal.Graph: """ Note: this returns a raw pygal chart; it does not render it to SVG/PNG @@ -81,7 +97,7 @@ def preservation_by_date_histogram(rows: List[Dict], merge_shadows: bool = False There is also a 'date' key with str value. """ - dates = sorted(rows, key=lambda x: x['date']) + dates = sorted(rows, key=lambda x: x["date"]) if merge_shadows: CleanStyle.colors = ("red", "darkolivegreen", "limegreen") @@ -90,23 +106,32 @@ def preservation_by_date_histogram(rows: List[Dict], merge_shadows: bool = False label_count = len(dates) if len(dates) > 30: label_count = 10 - chart = pygal.StackedBar(dynamic_print_values=True, style=CleanStyle, - width=1000, height=500, x_labels_major_count=label_count, - show_minor_x_labels=False, x_label_rotation=20) - #chart.title = "Preservation by Date" + chart = pygal.StackedBar( + dynamic_print_values=True, + style=CleanStyle, + width=1000, + height=500, + x_labels_major_count=label_count, + show_minor_x_labels=False, + x_label_rotation=20, + ) + # chart.title = "Preservation by Date" chart.x_title = "Date" - #chart.y_title = "Count" - chart.x_labels = [str(y['date']) for y in dates] + # chart.y_title = "Count" + chart.x_labels = [str(y["date"]) for y in dates] if merge_shadows: - chart.add('None', [y['none'] + y['shadows_only'] for y in dates]) + chart.add("None", [y["none"] + y["shadows_only"] for y in dates]) else: - chart.add('None', [y['none'] for y in dates]) - chart.add('Shadow', [y['shadows_only'] for y in dates]) - chart.add('Dark', [y['dark'] for y in dates]) - chart.add('Bright', [y['bright'] for y in dates]) + chart.add("None", [y["none"] for y in dates]) + chart.add("Shadow", [y["shadows_only"] for y in dates]) + chart.add("Dark", [y["dark"] for y in dates]) + chart.add("Bright", [y["bright"] for y in dates]) return chart -def preservation_by_volume_histogram(rows: List[Dict], merge_shadows: bool = False) -> pygal.Graph: + +def preservation_by_volume_histogram( + rows: List[Dict], merge_shadows: bool = False +) -> pygal.Graph: """ Note: this returns a raw pygal chart; it does not render it to SVG/PNG @@ -114,7 +139,7 @@ def preservation_by_volume_histogram(rows: List[Dict], merge_shadows: bool = Fal There is also a 'volume' key with str value. """ - volumes = sorted(rows, key=lambda x: x['volume']) + volumes = sorted(rows, key=lambda x: x["volume"]) if merge_shadows: CleanStyle.colors = ("red", "darkolivegreen", "limegreen") @@ -123,18 +148,24 @@ def preservation_by_volume_histogram(rows: List[Dict], merge_shadows: bool = Fal label_count = len(volumes) if len(volumes) >= 30: label_count = 10 - chart = pygal.StackedBar(dynamic_print_values=True, style=CleanStyle, - width=1000, height=500, x_labels_major_count=label_count, - show_minor_x_labels=False, x_label_rotation=20) - #chart.title = "Preservation by Volume" + chart = pygal.StackedBar( + dynamic_print_values=True, + style=CleanStyle, + width=1000, + height=500, + x_labels_major_count=label_count, + show_minor_x_labels=False, + x_label_rotation=20, + ) + # chart.title = "Preservation by Volume" chart.x_title = "Volume" - #chart.y_title = "Count" - chart.x_labels = [str(y['volume']) for y in volumes] + # chart.y_title = "Count" + chart.x_labels = [str(y["volume"]) for y in volumes] if merge_shadows: - chart.add('None', [y['none'] + y['shadows_only'] for y in volumes]) + chart.add("None", [y["none"] + y["shadows_only"] for y in volumes]) else: - chart.add('None', [y['none'] for y in volumes]) - chart.add('Shadow', [y['shadows_only'] for y in volumes]) - chart.add('Dark', [y['dark'] for y in volumes]) - chart.add('Bright', [y['bright'] for y in volumes]) + chart.add("None", [y["none"] for y in volumes]) + chart.add("Shadow", [y["shadows_only"] for y in volumes]) + chart.add("Dark", [y["dark"] for y in volumes]) + chart.add("Bright", [y["bright"] for y in volumes]) return chart -- cgit v1.2.3