diff --git a/grade_team_contribution.py b/grade_team_contribution.py index 95cbbdb6c652ad0ee1a5eea39387ef22be2a0cd5..3f59b8c3c26997a103154aa5306fab0f035f8ece 100644 --- a/grade_team_contribution.py +++ b/grade_team_contribution.py @@ -1,5 +1,6 @@ import textwrap -from typing import List +from math import ceil, log10 +from typing import Tuple from api.canvas_classes import * from api.gitlab_classes import * @@ -36,9 +37,26 @@ def get_project_prefix(canvas_groups): return prefix -def display_git_contributions(project): - print('Review git contributions offline') -# TODO: recognize that this only works for projects in namespace; will need to ask whether project should be retrieved. +def display_git_contributions(project: GitlabProject): + # TODO: recognize that this only works for projects in namespace; will need to ask whether to retrieve project. + commits: List[GitlabCommit] = project.get_commits() # TODO: narrow the selection + contributions: Dict[str, int] = {} + contributors: Set[Tuple[str, str]] = set() + # noinspection PyShadowingNames + for commit in commits: + if not commit.is_merge(): + author = commit.get_author() + contributors.add((author['name'], author['email'])) + email = author['email'] # TODO: manage aliases + size = commit.get_diff_size() # TODO: distinguish between file types + if email != 'bohn@unl.edu': # TODO: un-hard-code this + if email not in contributions: + contributions[email] = 0 + contributions[email] += size + print(f'Total line changes by each contributor to {project} :') + for contribution in contributions: + contributor = list(filter(lambda c: c[1] == contribution, contributors))[0] + print(f'\t{str(contributions[contribution]).rjust(5)}\t{contributor}') def grade(assignment1, assignment2, students): @@ -68,11 +86,13 @@ if __name__ == '__main__': if option is options[1]: print('Which group?') student_groups = [select_from_list(student_groups, 'student group')] + zero_padding: int = ceil(log10(len(projects))) for student_group in student_groups: # TODO: Skip past graded groups input(f'\n\nPress Enter to grade {student_group}') + project_name = f'{project_prefix}{student_group.get_name().split()[1]}'.zfill(zero_padding) + display_git_contributions(list(filter(lambda p: p.get_name() == project_name, projects))[0]) + print() display_peer_reviews(peer_review_assignment, student_group.get_students()) - project_name = f'{project_prefix}{student_group.get_name().split()[1]}' -# display_git_contributions(list(filter(lambda p: p.get_name() == project_name, projects))[0]) # TODO: Ask if you want to grade (keep track of groups that you don't grade) if True: grade(peer_review_assignment, None, student_group.get_students())