Borjan Tchakaloff | d50f365 | 2018-08-03 17:00:23 +0200 | [diff] [blame] | 1 | """The stats models.""" |
Dirk Vogt | 62ff7f2 | 2017-05-04 16:07:21 +0200 | [diff] [blame] | 2 | from django.db import models |
| 3 | |
Dirk Vogt | 1accb67 | 2017-05-10 14:07:42 +0200 | [diff] [blame] | 4 | |
Borjan Tchakaloff | 01e102c | 2018-02-19 17:47:45 +0100 | [diff] [blame] | 5 | class _VersionStats(models.Model): |
Borjan Tchakaloff | d50f365 | 2018-08-03 17:00:23 +0200 | [diff] [blame] | 6 | """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 Vogt | 1accb67 | 2017-05-10 14:07:42 +0200 | [diff] [blame] | 32 | is_official_release = models.BooleanField(default=False) |
Borjan Tchakaloff | 01e102c | 2018-02-19 17:47:45 +0100 | [diff] [blame] | 33 | is_beta_release = models.BooleanField(default=False) |
Borjan Tchakaloff | b98dba7 | 2018-03-16 11:04:47 +0400 | [diff] [blame] | 34 | first_seen_on = models.DateField() |
| 35 | released_on = models.DateField() |
Borjan Tchakaloff | 01e102c | 2018-02-19 17:47:45 +0100 | [diff] [blame] | 36 | 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 Tchakaloff | d50f365 | 2018-08-03 17:00:23 +0200 | [diff] [blame] | 44 | |
Borjan Tchakaloff | 01e102c | 2018-02-19 17:47:45 +0100 | [diff] [blame] | 45 | class _DailyVersionStats(models.Model): |
Borjan Tchakaloff | d50f365 | 2018-08-03 17:00:23 +0200 | [diff] [blame] | 46 | """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 Tchakaloff | b98dba7 | 2018-03-16 11:04:47 +0400 | [diff] [blame] | 64 | date = models.DateField() |
Borjan Tchakaloff | 01e102c | 2018-02-19 17:47:45 +0100 | [diff] [blame] | 65 | 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 | |
| 74 | class Version(_VersionStats): |
Borjan Tchakaloff | d50f365 | 2018-08-03 17:00:23 +0200 | [diff] [blame] | 75 | """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 Tchakaloff | 01e102c | 2018-02-19 17:47:45 +0100 | [diff] [blame] | 83 | build_fingerprint = models.CharField(max_length=200, unique=True) |
| 84 | |
Borjan Tchakaloff | d50f365 | 2018-08-03 17:00:23 +0200 | [diff] [blame] | 85 | def __str__(self): # noqa: D105 |
Dirk Vogt | 1accb67 | 2017-05-10 14:07:42 +0200 | [diff] [blame] | 86 | return self.build_fingerprint |
Borjan Tchakaloff | 01e102c | 2018-02-19 17:47:45 +0100 | [diff] [blame] | 87 | |
Borjan Tchakaloff | d50f365 | 2018-08-03 17:00:23 +0200 | [diff] [blame] | 88 | |
Borjan Tchakaloff | 01e102c | 2018-02-19 17:47:45 +0100 | [diff] [blame] | 89 | class VersionDaily(_DailyVersionStats): |
Borjan Tchakaloff | d50f365 | 2018-08-03 17:00:23 +0200 | [diff] [blame] | 90 | """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 Nikolaus | cb50f2c | 2018-08-24 13:54:48 +0200 | [diff] [blame^] | 99 | Version, |
| 100 | db_index=True, |
| 101 | related_name="daily_stats", |
| 102 | on_delete=models.CASCADE, |
| 103 | ) |
Borjan Tchakaloff | 08974d6 | 2018-02-19 16:02:20 +0100 | [diff] [blame] | 104 | |
| 105 | |
| 106 | class RadioVersion(_VersionStats): |
Borjan Tchakaloff | d50f365 | 2018-08-03 17:00:23 +0200 | [diff] [blame] | 107 | """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 Tchakaloff | 08974d6 | 2018-02-19 16:02:20 +0100 | [diff] [blame] | 115 | radio_version = models.CharField(max_length=200, unique=True) |
| 116 | |
Borjan Tchakaloff | d50f365 | 2018-08-03 17:00:23 +0200 | [diff] [blame] | 117 | def __str__(self): # noqa: D105 |
Borjan Tchakaloff | 08974d6 | 2018-02-19 16:02:20 +0100 | [diff] [blame] | 118 | return self.radio_version |
| 119 | |
Borjan Tchakaloff | d50f365 | 2018-08-03 17:00:23 +0200 | [diff] [blame] | 120 | |
Borjan Tchakaloff | 08974d6 | 2018-02-19 16:02:20 +0100 | [diff] [blame] | 121 | class RadioVersionDaily(_DailyVersionStats): |
Borjan Tchakaloff | d50f365 | 2018-08-03 17:00:23 +0200 | [diff] [blame] | 122 | """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 Nikolaus | cb50f2c | 2018-08-24 13:54:48 +0200 | [diff] [blame^] | 131 | RadioVersion, |
| 132 | db_index=True, |
| 133 | related_name="daily_stats", |
| 134 | on_delete=models.CASCADE, |
| 135 | ) |
Borjan Tchakaloff | b98dba7 | 2018-03-16 11:04:47 +0400 | [diff] [blame] | 136 | |
| 137 | |
| 138 | class 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() |