Skip to content

Commit c72c273

Browse files
committed
Refactor scoring into modular components
1 parent e9c3f6f commit c72c273

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

backend/apps/github/models/user.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,24 @@
2727

2828
class User(NodeModel, GenericUserModel, TimestampedModel, UserIndexMixin):
2929
"""User model."""
30+
calculated_score = models.FloatField( default=0 )
31+
def calculate_score(self):
32+
return (
33+
self._contribution_score()
34+
+ self._consistency_score()
35+
+ self._recency_score()
36+
)
37+
def _contribution_score(self):
38+
return (self.contributions_count or 0) * 1.0
39+
def _consistency_score(self):
40+
base = self.contributions_count or 0
41+
if base > 50:
42+
return 25
43+
elif base > 10:
44+
return 10
45+
return 0
46+
def _recency_score(self):
47+
return 5 if (self.contributions_count or 0) > 0 else 0
3048

3149
class Meta:
3250
"""Model options."""
@@ -184,6 +202,7 @@ def from_github(self, gh_user) -> None:
184202
self.is_bot = gh_user.type == "Bot"
185203
self.calculated_score = self.calculate_score()
186204

205+
187206
def get_absolute_url(self):
188207
"""Get absolute URL for the user."""
189208
return f"/members/{self.nest_key}"

0 commit comments

Comments
 (0)