-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontributor.py
42 lines (32 loc) · 1.49 KB
/
contributor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from __future__ import annotations
from pydriller.domain.developer import Developer
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from project import Project
import pydriller
class Contributor:
contributors = {}
@staticmethod
def measure_experience(project: Project, author) -> float:
author_contributions = 0
for c in pydriller.RepositoryMining(f"./projects/{project.name}", only_authors=[author]).traverse_commits():
author_contributions += sum([m.added + m.removed for m in c.modifications])
return author_contributions / project.total_contributions
@classmethod
def from_pydriller_method(cls, contributor: Developer, project: Project):
if contributor.email not in cls.contributors:
cls.contributors[contributor.email] = cls(contributor.name, contributor.email,
experience=cls.measure_experience(project, contributor.name))
return cls.contributors[contributor.email]
def __init__(self, name: str, email: str, experience: float):
self.name = name
self.email = email
self.experience = experience
def __str__(self):
return f"{self.name}<{self.email}>: XP={self.experience}"
def __repr__(self):
return f"{self.name}<{self.email}>: XP={self.experience}"
def __hash__(self):
return hash(self.name + self.email)
def __eq__(self, other):
return self.name == other.name and self.email == other.email