Skip to content

Commit d8efd4e

Browse files
Merge branch 'main' into comments
2 parents 225f24d + 6c7c2ff commit d8efd4e

File tree

2 files changed

+89
-11
lines changed

2 files changed

+89
-11
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Generated by Django 5.1.3 on 2025-01-06 13:17
2+
3+
import django.db.models.deletion
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
dependencies = [
9+
("website", "0178_alter_ip_agent"),
10+
]
11+
12+
operations = [
13+
migrations.CreateModel(
14+
name="ContributorStats",
15+
fields=[
16+
(
17+
"id",
18+
models.AutoField(
19+
auto_created=True,
20+
primary_key=True,
21+
serialize=False,
22+
verbose_name="ID",
23+
),
24+
),
25+
("date", models.DateField()),
26+
("commits", models.PositiveIntegerField(default=0)),
27+
("issues_opened", models.PositiveIntegerField(default=0)),
28+
("issues_closed", models.PositiveIntegerField(default=0)),
29+
("pull_requests", models.PositiveIntegerField(default=0)),
30+
("comments", models.PositiveIntegerField(default=0)),
31+
(
32+
"granularity",
33+
models.CharField(
34+
choices=[("day", "Day"), ("month", "Month")],
35+
default="day",
36+
max_length=10,
37+
),
38+
),
39+
(
40+
"contributor",
41+
models.ForeignKey(
42+
on_delete=django.db.models.deletion.CASCADE,
43+
related_name="stats",
44+
to="website.contributor",
45+
),
46+
),
47+
(
48+
"repo",
49+
models.ForeignKey(
50+
on_delete=django.db.models.deletion.CASCADE,
51+
related_name="stats",
52+
to="website.repo",
53+
),
54+
),
55+
],
56+
options={
57+
"unique_together": {("contributor", "repo", "date", "granularity")},
58+
},
59+
),
60+
]

website/models.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -936,17 +936,6 @@ def __str__(self):
936936
return self.name
937937

938938

939-
# class ContributorStats(models.Model):
940-
# username = models.CharField(max_length=255, unique=True)
941-
# commits = models.IntegerField(default=0)
942-
# issues_opened = models.IntegerField(default=0)
943-
# issues_closed = models.IntegerField(default=0)
944-
# prs = models.IntegerField(default=0)
945-
# comments = models.IntegerField(default=0)
946-
# assigned_issues = models.IntegerField(default=0)
947-
# created = models.DateTimeField(auto_now_add=True)
948-
949-
950939
class Contribution(models.Model):
951940
CONTRIBUTION_TYPES = [
952941
("commit", "Commit"),
@@ -1318,3 +1307,32 @@ def save(self, *args, **kwargs):
13181307

13191308
def __str__(self):
13201309
return f"{self.project.name}/{self.name}"
1310+
1311+
1312+
class ContributorStats(models.Model):
1313+
contributor = models.ForeignKey(Contributor, on_delete=models.CASCADE, related_name="stats")
1314+
repo = models.ForeignKey(Repo, on_delete=models.CASCADE, related_name="stats")
1315+
1316+
# This will represent either a specific day or the first day of a month.
1317+
date = models.DateField()
1318+
1319+
# Store counts
1320+
commits = models.PositiveIntegerField(default=0)
1321+
issues_opened = models.PositiveIntegerField(default=0)
1322+
issues_closed = models.PositiveIntegerField(default=0)
1323+
pull_requests = models.PositiveIntegerField(default=0)
1324+
comments = models.PositiveIntegerField(default=0)
1325+
1326+
# "day" for daily entries, "month" for monthly entries
1327+
granularity = models.CharField(
1328+
max_length=10, choices=[("day", "Day"), ("month", "Month")], default="day"
1329+
)
1330+
1331+
class Meta:
1332+
# You can't have two different stats for the same date+granularity
1333+
unique_together = ("contributor", "repo", "date", "granularity")
1334+
1335+
def __str__(self):
1336+
return (
1337+
f"{self.contributor.name} in {self.repo.name} " f"on {self.date} [{self.granularity}]"
1338+
)

0 commit comments

Comments
 (0)