Extracted function to parse daily counts from a contributions SVG and added a test for it.

This commit is contained in:
Jochen Kupperschmidt
2016-06-10 00:24:06 +02:00
parent 2c9c4cba83
commit d23a2d0746
2 changed files with 22 additions and 6 deletions

View File

@ -222,17 +222,19 @@ def retrieve_contributions_calendar(username, base_url):
return page.read().decode('utf-8')
def find_max_daily_commits(contributions_calendar):
"""finds the highest number of commits in one day"""
output = set()
def parse_contributions_calendar(contributions_calendar):
"""Yield daily counts extracted from the contributions SVG."""
for line in contributions_calendar.splitlines():
for day in line.split():
if 'data-count=' in day:
commit = day.split('=')[1]
commit = commit.strip('"')
output.add(int(commit))
yield int(commit)
def find_max_daily_commits(contributions_calendar):
"""finds the highest number of commits in one day"""
output = parse_contributions_calendar(contributions_calendar)
output = list(output)
output.sort()
output.reverse()

View File

@ -1,4 +1,4 @@
from gitfiti import find_max_daily_commits
from gitfiti import find_max_daily_commits, parse_contributions_calendar
CONTRIBUTIONS_CALENDAR_SVG = '''\
@ -71,5 +71,19 @@ CONTRIBUTIONS_CALENDAR_SVG = '''\
'''
def test_parse_contributions_calendar():
expected = [
0, 0, 0, 0, 6, 0, 0,
0, 0, 0, 0, 0, 0, 6,
84, 16, 4, 8, 0, 0, 0,
0, 25, 66, 20, 10, 0, 0,
33, 9, 0, 0, 7,
]
actual = parse_contributions_calendar(CONTRIBUTIONS_CALENDAR_SVG)
assert list(actual) == expected
def test_find_max_daily_commits():
assert find_max_daily_commits(CONTRIBUTIONS_CALENDAR_SVG) == 84