Skip to content

Commit f9f2d5b

Browse files
committed
Fix corner cases in developer categories
- If there is only one developer, it is classified as 'core'. - If there is a list of people with the exact same number of contributions and not all of them can enter the 'core' group, the first one is selected and the next ones are assigned to 'regular'. Signed-off-by: Eva Millán <[email protected]>
1 parent 5028f42 commit f9f2d5b

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
@@ -168,6 +168,70 @@ def test_get_developer_categories(self):
168168
categories = self.analyzer.get_developer_categories()
169169
self.assertDictEqual(categories, {"core": 2, "regular": 1, "casual": 1})
170170

171+
def test_get_categories_one_developer(self):
172+
"""Test if the categories are calculated correctly when there is only one developer"""
173+
174+
categories = self.analyzer.get_developer_categories()
175+
self.assertDictEqual(categories, {"core": 0, "regular": 0, "casual": 0})
176+
177+
# Add a core developer with 100% of the contributions
178+
extra_events = [
179+
{
180+
"type": "org.grimoirelab.events.git.commit",
181+
"data": {"Author": "Author 1 <author1@example_new.com>", "message": "Another commit"},
182+
},
183+
{
184+
"type": "org.grimoirelab.events.git.commit",
185+
"data": {"Author": "Author 1 <author1@example_new.com>", "message": "Another commit"},
186+
},
187+
{
188+
"type": "org.grimoirelab.events.git.commit",
189+
"data": {"Author": "Author 1 <author1@example_new.com>", "message": "Another commit"},
190+
},
191+
{
192+
"type": "org.grimoirelab.events.git.commit",
193+
"data": {"Author": "Author 1 <author1@example_new.com>", "message": "Another commit"},
194+
},
195+
]
196+
197+
self.analyzer.process_events(extra_events)
198+
categories = self.analyzer.get_developer_categories()
199+
self.assertDictEqual(categories, {"core": 1, "regular": 0, "casual": 0})
200+
201+
def test_get_developer_categories_tied(self):
202+
"""Test if the categories are calculated correctly when the core developers have the same contributions"""
203+
204+
categories = self.analyzer.get_developer_categories()
205+
self.assertDictEqual(categories, {"core": 0, "regular": 0, "casual": 0})
206+
207+
# Add core developers with the same number of contributions
208+
extra_events = [
209+
{
210+
"type": "org.grimoirelab.events.git.commit",
211+
"data": {"Author": "Author 1 <author1@example_new.com>", "message": "Another commit"},
212+
},
213+
{
214+
"type": "org.grimoirelab.events.git.commit",
215+
"data": {"Author": "Author 2 <author2@example_new.com>", "message": "Another commit"},
216+
},
217+
{
218+
"type": "org.grimoirelab.events.git.commit",
219+
"data": {"Author": "Author 3 <author3@example_new.com>", "message": "Another commit"},
220+
},
221+
{
222+
"type": "org.grimoirelab.events.git.commit",
223+
"data": {"Author": "Author 4 <author4@example_new.com>", "message": "Another commit"},
224+
},
225+
{
226+
"type": "org.grimoirelab.events.git.commit",
227+
"data": {"Author": "Author 5 <author5@example_new.com>", "message": "Another commit"},
228+
},
229+
]
230+
231+
self.analyzer.process_events(extra_events)
232+
categories = self.analyzer.get_developer_categories()
233+
self.assertDictEqual(categories, {"core": 4, "regular": 1, "casual": 0})
234+
171235

172236
if __name__ == "__main__":
173237
unittest.main()

trustable_cli/metrics.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,15 @@ def get_developer_categories(self):
158158
regular_threshold = int(0.8 * self.total_commits)
159159
casual_threshold = int(0.95 * self.total_commits)
160160
acc_commits = 0
161+
last_core_contribution = 0
161162

162163
for _, contributions in self.contributors.most_common():
163164
acc_commits += contributions
164165

165-
if acc_commits <= regular_threshold:
166+
if acc_commits <= regular_threshold or contributions > last_core_contribution:
167+
last_core_contribution = contributions
166168
core += 1
167-
elif acc_commits <= casual_threshold:
169+
elif acc_commits <= casual_threshold or contributions == last_core_contribution:
168170
regular += 1
169171
else:
170172
casual += 1

0 commit comments

Comments
 (0)