Skip to content

Commit

Permalink
ignore the year which has no running data when drawing github.svg (#712)
Browse files Browse the repository at this point in the history
  • Loading branch information
Narglc authored Sep 22, 2024
1 parent fa3b736 commit 371ce67
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion run_page/gen_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()[:]
Expand Down
3 changes: 3 additions & 0 deletions run_page/gpxtrackposter/github_drawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions run_page/gpxtrackposter/year_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"""
Expand All @@ -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))

0 comments on commit 371ce67

Please sign in to comment.