Skip to content

Commit

Permalink
feat: add ContributorStats model for tracking contributor activity (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
JisanAR03 authored Jan 6, 2025
1 parent 6c75fb5 commit 6c7c2ff
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 11 deletions.
60 changes: 60 additions & 0 deletions website/migrations/0179_contributorstats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Generated by Django 5.1.3 on 2025-01-06 13:17

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("website", "0178_alter_ip_agent"),
]

operations = [
migrations.CreateModel(
name="ContributorStats",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("date", models.DateField()),
("commits", models.PositiveIntegerField(default=0)),
("issues_opened", models.PositiveIntegerField(default=0)),
("issues_closed", models.PositiveIntegerField(default=0)),
("pull_requests", models.PositiveIntegerField(default=0)),
("comments", models.PositiveIntegerField(default=0)),
(
"granularity",
models.CharField(
choices=[("day", "Day"), ("month", "Month")],
default="day",
max_length=10,
),
),
(
"contributor",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="stats",
to="website.contributor",
),
),
(
"repo",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="stats",
to="website.repo",
),
),
],
options={
"unique_together": {("contributor", "repo", "date", "granularity")},
},
),
]
40 changes: 29 additions & 11 deletions website/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,17 +935,6 @@ def __str__(self):
return self.name


# class ContributorStats(models.Model):
# username = models.CharField(max_length=255, unique=True)
# commits = models.IntegerField(default=0)
# issues_opened = models.IntegerField(default=0)
# issues_closed = models.IntegerField(default=0)
# prs = models.IntegerField(default=0)
# comments = models.IntegerField(default=0)
# assigned_issues = models.IntegerField(default=0)
# created = models.DateTimeField(auto_now_add=True)


class Contribution(models.Model):
CONTRIBUTION_TYPES = [
("commit", "Commit"),
Expand Down Expand Up @@ -1316,3 +1305,32 @@ def save(self, *args, **kwargs):

def __str__(self):
return f"{self.project.name}/{self.name}"


class ContributorStats(models.Model):
contributor = models.ForeignKey(Contributor, on_delete=models.CASCADE, related_name="stats")
repo = models.ForeignKey(Repo, on_delete=models.CASCADE, related_name="stats")

# This will represent either a specific day or the first day of a month.
date = models.DateField()

# Store counts
commits = models.PositiveIntegerField(default=0)
issues_opened = models.PositiveIntegerField(default=0)
issues_closed = models.PositiveIntegerField(default=0)
pull_requests = models.PositiveIntegerField(default=0)
comments = models.PositiveIntegerField(default=0)

# "day" for daily entries, "month" for monthly entries
granularity = models.CharField(
max_length=10, choices=[("day", "Day"), ("month", "Month")], default="day"
)

class Meta:
# You can't have two different stats for the same date+granularity
unique_together = ("contributor", "repo", "date", "granularity")

def __str__(self):
return (
f"{self.contributor.name} in {self.repo.name} " f"on {self.date} [{self.granularity}]"
)

0 comments on commit 6c7c2ff

Please sign in to comment.