-
-
Notifications
You must be signed in to change notification settings - Fork 629
Add calculated_score field and basic scoring logic #4330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
e9c3f6f
c72c273
ccb63a6
5351332
a4975fe
d9724fc
833c73d
af8e724
25b2694
4b2759c
96b476c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| from django.db import migrations, models | ||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("github", "0044_user_indexes"), | ||
| ] | ||
| operations = [ | ||
| migrations.AddField( | ||
| model_name="user", | ||
| name="calculated_score", | ||
| field=models.FloatField( | ||
| default=0, | ||
| help_text="Computed score based on contribution signals", | ||
| ), | ||
| ), | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,33 @@ | |
|
|
||
| class User(NodeModel, GenericUserModel, TimestampedModel, UserIndexMixin): | ||
| """User model.""" | ||
| calculated_score = models.FloatField( default=0 ) | ||
|
|
||
| def calculate_score(self): | ||
| return ( | ||
| self._contribution_score() | ||
| + self._consistency_score() | ||
| + self._recency_score() | ||
| ) | ||
|
|
||
| def _contribution_score(self): | ||
| return (self.contributions_count or 0) * 1.0 | ||
| def _consistency_score(self): | ||
| base = self.contributions_count or 0 | ||
| if base > 50: | ||
| return 25 | ||
| elif base > 10: | ||
| return 10 | ||
| return 0 | ||
| def _recency_score(self): | ||
| return 5 if (self.contributions_count or 0) > 0 else 0 | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| def _leadership_score(self): | ||
| score = 0 | ||
| # Simple leadership signal | ||
| if self.is_owasp_staff: | ||
| score += 30 | ||
| return score | ||
|
|
||
| class Meta: | ||
| """Model options.""" | ||
|
|
@@ -55,7 +82,13 @@ class Meta: | |
| ) | ||
|
|
||
| contributions_count = models.PositiveIntegerField( | ||
| verbose_name="Contributions count", default=0 | ||
| verbose_name="Contributions count", | ||
| default=0 | ||
| ) | ||
|
|
||
| calculated_score = models.FloatField( | ||
| default=0, | ||
| help_text="Computed score based on contribution signals" | ||
| ) | ||
|
Comment on lines
+89
to
92
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Search the GitHub app for model and migration references to `calculated_score`.
rg -n -C2 "calculated_score|AddField\(|AlterField\(" backend/apps/githubRepository: OWASP/Nest Length of output: 39202 Create a migration for the The 🧰 Tools🪛 Ruff (0.15.6)[warning] 82-85: Class field Remove duplicate field definition for (PIE794) 🤖 Prompt for AI Agents |
||
|
|
||
| contribution_data = models.JSONField( | ||
|
|
@@ -170,6 +203,8 @@ def from_github(self, gh_user) -> None: | |
| setattr(self, model_field, value) | ||
|
|
||
| self.is_bot = gh_user.type == "Bot" | ||
| self.calculated_score = self.calculate_score() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Score becomes stale when The Since the management command appears to be the primary mechanism for aggregating contribution counts from Consider one of these approaches:
# In github_update_users.py, after setting contributions_count:
user.contributions_count = user_contributions.get(user.id, 0)
user.calculated_score = user.calculate_score()
users.append(user)
# And update bulk_save to include the new field:
User.bulk_save(users, fields=("contributions_count", "calculated_score"))
🤖 Prompt for AI Agents |
||
|
|
||
|
|
||
| def get_absolute_url(self): | ||
| """Get absolute URL for the user.""" | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.