Skip to content

Commit f413727

Browse files
authored
Merges #15 Closes #15
2 parents 2a48474 + 0f13b76 commit f413727

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

tests/unit/test_metrics.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,70 @@ def test_get_developer_categories(self):
216216
categories = self.analyzer.get_developer_categories()
217217
self.assertDictEqual(categories, {"core": 2, "regular": 1, "casual": 1})
218218

219+
def test_get_categories_one_developer(self):
220+
"""Test if the categories are calculated correctly when there is only one developer"""
221+
222+
categories = self.analyzer.get_developer_categories()
223+
self.assertDictEqual(categories, {"core": 0, "regular": 0, "casual": 0})
224+
225+
# Add a core developer with 100% of the contributions
226+
extra_events = [
227+
{
228+
"type": "org.grimoirelab.events.git.commit",
229+
"data": {"Author": "Author 1 <author1@example_new.com>", "message": "Another commit"},
230+
},
231+
{
232+
"type": "org.grimoirelab.events.git.commit",
233+
"data": {"Author": "Author 1 <author1@example_new.com>", "message": "Another commit"},
234+
},
235+
{
236+
"type": "org.grimoirelab.events.git.commit",
237+
"data": {"Author": "Author 1 <author1@example_new.com>", "message": "Another commit"},
238+
},
239+
{
240+
"type": "org.grimoirelab.events.git.commit",
241+
"data": {"Author": "Author 1 <author1@example_new.com>", "message": "Another commit"},
242+
},
243+
]
244+
245+
self.analyzer.process_events(extra_events)
246+
categories = self.analyzer.get_developer_categories()
247+
self.assertDictEqual(categories, {"core": 1, "regular": 0, "casual": 0})
248+
249+
def test_get_developer_categories_tied(self):
250+
"""Test if the categories are calculated correctly when the core developers have the same contributions"""
251+
252+
categories = self.analyzer.get_developer_categories()
253+
self.assertDictEqual(categories, {"core": 0, "regular": 0, "casual": 0})
254+
255+
# Add core developers with the same number of contributions
256+
extra_events = [
257+
{
258+
"type": "org.grimoirelab.events.git.commit",
259+
"data": {"Author": "Author 1 <author1@example_new.com>", "message": "Another commit"},
260+
},
261+
{
262+
"type": "org.grimoirelab.events.git.commit",
263+
"data": {"Author": "Author 2 <author2@example_new.com>", "message": "Another commit"},
264+
},
265+
{
266+
"type": "org.grimoirelab.events.git.commit",
267+
"data": {"Author": "Author 3 <author3@example_new.com>", "message": "Another commit"},
268+
},
269+
{
270+
"type": "org.grimoirelab.events.git.commit",
271+
"data": {"Author": "Author 4 <author4@example_new.com>", "message": "Another commit"},
272+
},
273+
{
274+
"type": "org.grimoirelab.events.git.commit",
275+
"data": {"Author": "Author 5 <author5@example_new.com>", "message": "Another commit"},
276+
},
277+
]
278+
279+
self.analyzer.process_events(extra_events)
280+
categories = self.analyzer.get_developer_categories()
281+
self.assertDictEqual(categories, {"core": 4, "regular": 1, "casual": 0})
282+
219283

220284
if __name__ == "__main__":
221285
unittest.main()

trustable_cli/metrics.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,15 @@ def get_developer_categories(self):
176176
regular_threshold = int(0.8 * self.total_commits)
177177
casual_threshold = int(0.95 * self.total_commits)
178178
acc_commits = 0
179+
last_core_contribution = 0
179180

180181
for _, contributions in self.contributors.most_common():
181182
acc_commits += contributions
182183

183-
if acc_commits <= regular_threshold:
184+
if acc_commits <= regular_threshold or contributions > last_core_contribution:
185+
last_core_contribution = contributions
184186
core += 1
185-
elif acc_commits <= casual_threshold:
187+
elif acc_commits <= casual_threshold or contributions == last_core_contribution:
186188
regular += 1
187189
else:
188190
casual += 1

0 commit comments

Comments
 (0)