Skip to content

Commit 2d45167

Browse files
committed
fixed bug with streak not calculating correctly
1 parent a8f650e commit 2d45167

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/gitfetch/display.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ def _calculate_streaks(self, weeks_data: list) -> tuple:
960960
if not weeks_data:
961961
return 0, 0
962962

963-
# Flatten all contribution counts in reverse chronological order
963+
# Flatten contributions in reverse chronological order (newest first)
964964
all_contributions = []
965965
for week in weeks_data:
966966
for day in week.get('contributionDays', []):
@@ -972,18 +972,23 @@ def _calculate_streaks(self, weeks_data: list) -> tuple:
972972
max_streak = 0
973973
temp_streak = 0
974974

975+
# Calculate current streak (ending with most recent contribution)
975976
for contrib in all_contributions:
976977
if contrib > 0:
977-
temp_streak += 1
978-
current_streak = temp_streak
978+
current_streak += 1
979979
else:
980+
break
981+
982+
# Calculate max streak
983+
temp_streak = 0
984+
for contrib in all_contributions:
985+
if contrib > 0:
986+
temp_streak += 1
980987
if temp_streak > max_streak:
981988
max_streak = temp_streak
989+
else:
982990
temp_streak = 0
983991

984-
if temp_streak > max_streak:
985-
max_streak = temp_streak
986-
987992
return current_streak, max_streak
988993

989994
def _get_achievement_entries(self, current_streak: int, max_streak: int,

0 commit comments

Comments
 (0)