From dccfad8354cd9562edbd3bf29ba232dc59df5e0c Mon Sep 17 00:00:00 2001 From: Narglc Yu Date: Thu, 19 Sep 2024 22:23:18 +0800 Subject: [PATCH] ignore the year which has no running data when drawing github.svg --- run_page/gen_svg.py | 2 +- run_page/gpxtrackposter/github_drawer.py | 3 +++ run_page/gpxtrackposter/year_range.py | 11 +++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/run_page/gen_svg.py b/run_page/gen_svg.py index bd2a891b68b..7ecd8342c69 100755 --- a/run_page/gen_svg.py +++ b/run_page/gen_svg.py @@ -243,7 +243,7 @@ def main(): # circular not add footer and header p.drawer_type = "plain" if is_circular else "title" if args.type == "github": - p.height = 55 + p.years.count() * 43 + p.height = 55 + p.years.real_year * 43 # for special circular if is_circular: years = p.years.all()[:] diff --git a/run_page/gpxtrackposter/github_drawer.py b/run_page/gpxtrackposter/github_drawer.py index 816b8914271..6d6b8771849 100644 --- a/run_page/gpxtrackposter/github_drawer.py +++ b/run_page/gpxtrackposter/github_drawer.py @@ -37,6 +37,9 @@ def draw(self, dr: svgwrite.Drawing, size: XY, offset: XY): ) year_length = total_length_year_dict.get(year, 0) year_length = format_float(self.poster.m2u(year_length)) + + if str(year_length) == "0.0": + continue try: month_names = [ locale.nl_langinfo(day)[:3] # Get only first three letters diff --git a/run_page/gpxtrackposter/year_range.py b/run_page/gpxtrackposter/year_range.py index dacb977b9d9..fb819bce603 100644 --- a/run_page/gpxtrackposter/year_range.py +++ b/run_page/gpxtrackposter/year_range.py @@ -28,6 +28,7 @@ def __init__(self): """Inits YearRange with empty bounds -- to be built after init""" self.from_year = None self.to_year = None + self.years_dict = dict() def parse(self, s: str) -> bool: """Parse a plaintext range of years into a pair of years @@ -69,6 +70,11 @@ def add(self, t: datetime.datetime): self.from_year = t.year elif t.year > self.to_year: self.to_year = t.year + """record the year which has running data""" + if t.year not in self.years_dict: + self.years_dict[t.year] = 1 + else: + self.years_dict[t.year] += 1 def contains(self, t: datetime.datetime) -> bool: """Return True if current year range contains t, False if not""" @@ -82,5 +88,10 @@ def count(self) -> Optional[int]: return None return 1 + self.to_year - self.from_year + @property + def real_year(self): + """Return number of years which has running data""" + return len(self.years_dict) + def all(self): return list(range(int(self.from_year), int(self.to_year) + 1))