51
51
52
52
53
53
class GitEventsAnalyzer :
54
- def __init__ (self , code_file_pattern : str | None = None , binary_file_pattern : str | None = None ):
54
+ def __init__ (
55
+ self ,
56
+ code_file_pattern : str | None = None ,
57
+ binary_file_pattern : str | None = None ,
58
+ pony_threshold : float = 0.5 ,
59
+ elephant_threshold : float = 0.5 ,
60
+ dev_categories_thresholds : tuple [float , float ] = (0.8 , 0.95 ),
61
+ ):
55
62
self .total_commits : int = 0
56
63
self .contributors : Counter = Counter ()
57
64
self .companies : Counter = Counter ()
@@ -61,6 +68,9 @@ def __init__(self, code_file_pattern: str | None = None, binary_file_pattern: st
61
68
self .messages_sizes : list = []
62
69
self .re_code_pattern = re .compile (code_file_pattern or FILE_TYPE_CODE )
63
70
self .re_binary_pattern = re .compile (binary_file_pattern or FILE_TYPE_BINARY )
71
+ self .pony_threshold = pony_threshold
72
+ self .elephant_threshold = elephant_threshold
73
+ self .dev_categories_thresholds = dev_categories_thresholds
64
74
65
75
def process_events (self , events : iter (dict [str , Any ])):
66
76
for event in events :
@@ -93,7 +103,7 @@ def get_pony_factor(self):
93
103
for _ , contributions in self .contributors .most_common ():
94
104
partial_contributions += contributions
95
105
pony_factor += 1
96
- if partial_contributions / self .total_commits > 0.5 :
106
+ if partial_contributions / self .total_commits > self . pony_threshold :
97
107
break
98
108
99
109
return pony_factor
@@ -110,7 +120,7 @@ def get_elephant_factor(self):
110
120
for _ , contributions in self .companies .most_common ():
111
121
partial_contributions += contributions
112
122
elephant_factor += 1
113
- if partial_contributions / self .total_commits > 0.5 :
123
+ if partial_contributions / self .total_commits > self . elephant_threshold :
114
124
break
115
125
116
126
return elephant_factor
@@ -173,8 +183,8 @@ def get_developer_categories(self):
173
183
core = 0
174
184
regular = 0
175
185
casual = 0
176
- regular_threshold = int (0.8 * self .total_commits )
177
- casual_threshold = int (0.95 * self .total_commits )
186
+ regular_threshold = int (self . dev_categories_thresholds [ 0 ] * self .total_commits )
187
+ casual_threshold = int (self . dev_categories_thresholds [ 1 ] * self .total_commits )
178
188
acc_commits = 0
179
189
last_core_contribution = 0
180
190
@@ -244,6 +254,9 @@ def get_repository_metrics(
244
254
verify_certs : bool = True ,
245
255
code_file_pattern : str | None = None ,
246
256
binary_file_pattern : str | None = None ,
257
+ pony_threshold : float | None = None ,
258
+ elephant_threshold : float | None = None ,
259
+ dev_categories_thresholds : tuple [float , float ] = (0.8 , 0.95 ),
247
260
):
248
261
"""
249
262
Get the metrics from a repository.
@@ -256,14 +269,23 @@ def get_repository_metrics(
256
269
:param to_date: End date, by default None
257
270
:param code_file_pattern: Regular expression to match code file types.
258
271
:param binary_file_pattern: Regular expression to match binary file types.
272
+ :param pony_threshold: Threshold for the pony factor
273
+ :param elephant_threshold: Threshold for the elephant factor
274
+ :param dev_categories_thresholds: Threshold for the developer categories
259
275
"""
260
276
os_conn = connect_to_opensearch (opensearch_url , verify_certs = verify_certs )
261
277
262
278
metrics = {"metrics" : {}}
263
279
264
280
events = get_repository_events (os_conn , opensearch_index , repository , from_date , to_date )
265
281
266
- analyzer = GitEventsAnalyzer (code_file_pattern = code_file_pattern , binary_file_pattern = binary_file_pattern )
282
+ analyzer = GitEventsAnalyzer (
283
+ code_file_pattern = code_file_pattern ,
284
+ binary_file_pattern = binary_file_pattern ,
285
+ pony_threshold = pony_threshold ,
286
+ elephant_threshold = elephant_threshold ,
287
+ dev_categories_thresholds = dev_categories_thresholds ,
288
+ )
267
289
analyzer .process_events (events )
268
290
269
291
metrics ["metrics" ]["total_commits" ] = analyzer .get_commit_count ()
0 commit comments