Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignore the year which has no running data when drawing github.svg #712

Merged
merged 1 commit into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))