@@ -936,17 +936,6 @@ def __str__(self):
936
936
return self .name
937
937
938
938
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
-
950
939
class Contribution (models .Model ):
951
940
CONTRIBUTION_TYPES = [
952
941
("commit" , "Commit" ),
@@ -1318,3 +1307,32 @@ def save(self, *args, **kwargs):
1318
1307
1319
1308
def __str__ (self ):
1320
1309
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