blob: e4bb6834c75c5ae89a979685dbd637b0415c7b7c [file] [log] [blame]
Borjan Tchakaloffd50f3652018-08-03 17:00:23 +02001"""The stats models."""
Dirk Vogt62ff7f22017-05-04 16:07:21 +02002from django.db import models
3
Dirk Vogt1accb672017-05-10 14:07:42 +02004
Borjan Tchakaloff01e102c2018-02-19 17:47:45 +01005class _VersionStats(models.Model):
Borjan Tchakaloffd50f3652018-08-03 17:00:23 +02006 """The base class for all-time stats of a version.
7
8 Sub-classes should be created to gather stats about a versioned
9 end-product such as a software build.
10
11 Attributes:
12 is_official_release (models.BooleanField): If this version is an
13 official release. Defaults to False.
14 is_beta_release (models.BooleanField): If this version is a beta
15 release. Defaults to False.
16 first_seen_on (models.DateField): Day this version has been seen for
17 the first time as reported by devices (not by the server). Defaults
18 to the current date.
19 released_on (models.DateField): Day this version has been released on.
20 Defaults to the current date.
21 heartbeats (models.IntegerField): The total heartbeats counted for this
22 version.
23 prob_crashes (models.IntegerField): The total probable crash reports
24 counted for this version.
25 smpl (models.IntegerField): The total SMPL reports counted for this
26 version.
27 other (models.IntegerField): The total of other reports counted for
28 this version.
29
30 """
31
Dirk Vogt1accb672017-05-10 14:07:42 +020032 is_official_release = models.BooleanField(default=False)
Borjan Tchakaloff01e102c2018-02-19 17:47:45 +010033 is_beta_release = models.BooleanField(default=False)
Borjan Tchakaloffb98dba72018-03-16 11:04:47 +040034 first_seen_on = models.DateField()
35 released_on = models.DateField()
Borjan Tchakaloff01e102c2018-02-19 17:47:45 +010036 heartbeats = models.IntegerField(default=0)
37 prob_crashes = models.IntegerField(default=0)
38 smpl = models.IntegerField(default=0)
39 other = models.IntegerField(default=0)
40
41 class Meta:
42 abstract = True
43
Borjan Tchakaloffd50f3652018-08-03 17:00:23 +020044
Borjan Tchakaloff01e102c2018-02-19 17:47:45 +010045class _DailyVersionStats(models.Model):
Borjan Tchakaloffd50f3652018-08-03 17:00:23 +020046 """The base class for daily stats of a version.
47
48 Sub-classes MUST define the foreign key `version` pointing back to the
49 `_VersionStats` implementation they are gathering stats for.
50
51 Attributes:
52 date (models.DateField): Day considered for the stats.
53 heartbeats (models.IntegerField): The total heartbeats counted for this
54 version on the day `date`.
55 prob_crashes (models.IntegerField): The total probable crash reports
56 counted for this version on the day `date`.
57 smpl (models.IntegerField): The total SMPL reports counted for this
58 version on the day `date`.
59 other (models.IntegerField): The total of other reports counted for
60 this version on the day `date`.
61
62 """
63
Borjan Tchakaloffb98dba72018-03-16 11:04:47 +040064 date = models.DateField()
Borjan Tchakaloff01e102c2018-02-19 17:47:45 +010065 heartbeats = models.IntegerField(default=0)
66 prob_crashes = models.IntegerField(default=0)
67 smpl = models.IntegerField(default=0)
68 other = models.IntegerField(default=0)
69
70 class Meta:
71 abstract = True
72
73
74class Version(_VersionStats):
Borjan Tchakaloffd50f3652018-08-03 17:00:23 +020075 """The all-time stats of a software version.
76
77 Attributes:
78 build_fingerprint (models.CharField): The software build fingerprint
79 uniquely identifying this version.
80
81 """
82
Borjan Tchakaloff01e102c2018-02-19 17:47:45 +010083 build_fingerprint = models.CharField(max_length=200, unique=True)
84
Borjan Tchakaloffd50f3652018-08-03 17:00:23 +020085 def __str__(self): # noqa: D105
Dirk Vogt1accb672017-05-10 14:07:42 +020086 return self.build_fingerprint
Borjan Tchakaloff01e102c2018-02-19 17:47:45 +010087
Borjan Tchakaloffd50f3652018-08-03 17:00:23 +020088
Borjan Tchakaloff01e102c2018-02-19 17:47:45 +010089class VersionDaily(_DailyVersionStats):
Borjan Tchakaloffd50f3652018-08-03 17:00:23 +020090 """The daily stats of a software version.
91
92 Attributes:
93 version (models.ForeignKey): The software version object (`Version`)
94 these daily stats are about.
95
96 """
97
98 version = models.ForeignKey(
Mitja Nikolauscb50f2c2018-08-24 13:54:48 +020099 Version,
100 db_index=True,
101 related_name="daily_stats",
102 on_delete=models.CASCADE,
103 )
Borjan Tchakaloff08974d62018-02-19 16:02:20 +0100104
105
106class RadioVersion(_VersionStats):
Borjan Tchakaloffd50f3652018-08-03 17:00:23 +0200107 """The all-time stats of a radio version.
108
109 Attributes:
110 radio_version (models.CharField): The radio version number uniquely
111 identifying this version.
112
113 """
114
Borjan Tchakaloff08974d62018-02-19 16:02:20 +0100115 radio_version = models.CharField(max_length=200, unique=True)
116
Borjan Tchakaloffd50f3652018-08-03 17:00:23 +0200117 def __str__(self): # noqa: D105
Borjan Tchakaloff08974d62018-02-19 16:02:20 +0100118 return self.radio_version
119
Borjan Tchakaloffd50f3652018-08-03 17:00:23 +0200120
Borjan Tchakaloff08974d62018-02-19 16:02:20 +0100121class RadioVersionDaily(_DailyVersionStats):
Borjan Tchakaloffd50f3652018-08-03 17:00:23 +0200122 """The daily stats of a radio version.
123
124 Attributes:
125 version (models.ForeignKey): The radio version object (`RadioVersion`)
126 these daily stats are about.
127
128 """
129
130 version = models.ForeignKey(
Mitja Nikolauscb50f2c2018-08-24 13:54:48 +0200131 RadioVersion,
132 db_index=True,
133 related_name="daily_stats",
134 on_delete=models.CASCADE,
135 )
Borjan Tchakaloffb98dba72018-03-16 11:04:47 +0400136
137
138class StatsMetadata(models.Model):
139 """The stats metadata.
140
141 Attributes:
142 updated_at (models.DateTimeField): The last time the stats were
143 updated.
144
145 """
146
147 updated_at = models.DateTimeField()