Borjan Tchakaloff | d50f365 | 2018-08-03 17:00:23 +0200 | [diff] [blame] | 1 | """The stats models.""" |
Mitja Nikolaus | 9c3b29e | 2018-08-22 11:17:50 +0200 | [diff] [blame] | 2 | from django.db.models import ( |
| 3 | BooleanField, |
| 4 | CASCADE, |
| 5 | CharField, |
| 6 | DateField, |
| 7 | DateTimeField, |
| 8 | ForeignKey, |
| 9 | IntegerField, |
| 10 | Model, |
| 11 | ) |
Dirk Vogt | 62ff7f2 | 2017-05-04 16:07:21 +0200 | [diff] [blame] | 12 | |
Dirk Vogt | 1accb67 | 2017-05-10 14:07:42 +0200 | [diff] [blame] | 13 | |
Mitja Nikolaus | 9c3b29e | 2018-08-22 11:17:50 +0200 | [diff] [blame] | 14 | class _VersionStats(Model): |
Borjan Tchakaloff | d50f365 | 2018-08-03 17:00:23 +0200 | [diff] [blame] | 15 | """The base class for all-time stats of a version. |
| 16 | |
| 17 | Sub-classes should be created to gather stats about a versioned |
| 18 | end-product such as a software build. |
| 19 | |
| 20 | Attributes: |
Mitja Nikolaus | 9c3b29e | 2018-08-22 11:17:50 +0200 | [diff] [blame] | 21 | is_official_release: |
| 22 | If this version is an official release. Defaults to False. |
| 23 | is_beta_release: If this version is a beta release. Defaults to False. |
| 24 | first_seen_on: |
| 25 | Day this version has been seen for the first time as reported by |
| 26 | devices (not by the server). Defaults to the current date. |
| 27 | released_on: |
| 28 | Day this version has been released on. Defaults to the current date. |
| 29 | heartbeats: The total heartbeats counted for this version. |
| 30 | prob_crashes: The total probable crash reports counted for this version. |
| 31 | smpl: The total SMPL reports counted for this version. |
| 32 | other: The total of other reports counted for this version. |
Borjan Tchakaloff | d50f365 | 2018-08-03 17:00:23 +0200 | [diff] [blame] | 33 | |
| 34 | """ |
| 35 | |
Mitja Nikolaus | 9c3b29e | 2018-08-22 11:17:50 +0200 | [diff] [blame] | 36 | is_official_release = BooleanField(default=False) |
| 37 | is_beta_release = BooleanField(default=False) |
| 38 | first_seen_on = DateField() |
| 39 | released_on = DateField() |
| 40 | heartbeats = IntegerField(default=0) |
| 41 | prob_crashes = IntegerField(default=0) |
| 42 | smpl = IntegerField(default=0) |
| 43 | other = IntegerField(default=0) |
Borjan Tchakaloff | 01e102c | 2018-02-19 17:47:45 +0100 | [diff] [blame] | 44 | |
| 45 | class Meta: |
| 46 | abstract = True |
| 47 | |
Borjan Tchakaloff | d50f365 | 2018-08-03 17:00:23 +0200 | [diff] [blame] | 48 | |
Mitja Nikolaus | 9c3b29e | 2018-08-22 11:17:50 +0200 | [diff] [blame] | 49 | class _DailyVersionStats(Model): |
Borjan Tchakaloff | d50f365 | 2018-08-03 17:00:23 +0200 | [diff] [blame] | 50 | """The base class for daily stats of a version. |
| 51 | |
| 52 | Sub-classes MUST define the foreign key `version` pointing back to the |
| 53 | `_VersionStats` implementation they are gathering stats for. |
| 54 | |
| 55 | Attributes: |
Mitja Nikolaus | 9c3b29e | 2018-08-22 11:17:50 +0200 | [diff] [blame] | 56 | date: Day considered for the stats. |
| 57 | heartbeats: |
| 58 | The total heartbeats counted for this version on the day `date`. |
| 59 | prob_crashes: |
| 60 | The total probable crash reports counted for this version on the |
| 61 | day `date`. |
| 62 | smpl: The total SMPL reports counted for this version on the day `date`. |
| 63 | other: |
| 64 | The total of other reports counted for this version on the day |
| 65 | `date`. |
Borjan Tchakaloff | d50f365 | 2018-08-03 17:00:23 +0200 | [diff] [blame] | 66 | |
| 67 | """ |
| 68 | |
Mitja Nikolaus | 9c3b29e | 2018-08-22 11:17:50 +0200 | [diff] [blame] | 69 | date = DateField() |
| 70 | heartbeats = IntegerField(default=0) |
| 71 | prob_crashes = IntegerField(default=0) |
| 72 | smpl = IntegerField(default=0) |
| 73 | other = IntegerField(default=0) |
Borjan Tchakaloff | 01e102c | 2018-02-19 17:47:45 +0100 | [diff] [blame] | 74 | |
| 75 | class Meta: |
| 76 | abstract = True |
| 77 | |
| 78 | |
| 79 | class Version(_VersionStats): |
Borjan Tchakaloff | d50f365 | 2018-08-03 17:00:23 +0200 | [diff] [blame] | 80 | """The all-time stats of a software version. |
| 81 | |
| 82 | Attributes: |
Mitja Nikolaus | 9c3b29e | 2018-08-22 11:17:50 +0200 | [diff] [blame] | 83 | build_fingerprint: |
| 84 | The software build fingerprint uniquely identifying this version. |
Borjan Tchakaloff | d50f365 | 2018-08-03 17:00:23 +0200 | [diff] [blame] | 85 | |
| 86 | """ |
| 87 | |
Mitja Nikolaus | 9c3b29e | 2018-08-22 11:17:50 +0200 | [diff] [blame] | 88 | build_fingerprint = CharField(max_length=200, unique=True) |
Borjan Tchakaloff | 01e102c | 2018-02-19 17:47:45 +0100 | [diff] [blame] | 89 | |
Borjan Tchakaloff | d50f365 | 2018-08-03 17:00:23 +0200 | [diff] [blame] | 90 | def __str__(self): # noqa: D105 |
Dirk Vogt | 1accb67 | 2017-05-10 14:07:42 +0200 | [diff] [blame] | 91 | return self.build_fingerprint |
Borjan Tchakaloff | 01e102c | 2018-02-19 17:47:45 +0100 | [diff] [blame] | 92 | |
Borjan Tchakaloff | d50f365 | 2018-08-03 17:00:23 +0200 | [diff] [blame] | 93 | |
Borjan Tchakaloff | 01e102c | 2018-02-19 17:47:45 +0100 | [diff] [blame] | 94 | class VersionDaily(_DailyVersionStats): |
Borjan Tchakaloff | d50f365 | 2018-08-03 17:00:23 +0200 | [diff] [blame] | 95 | """The daily stats of a software version. |
| 96 | |
| 97 | Attributes: |
Mitja Nikolaus | 9c3b29e | 2018-08-22 11:17:50 +0200 | [diff] [blame] | 98 | version: |
| 99 | The software version object (`Version`) these daily stats are about. |
Borjan Tchakaloff | d50f365 | 2018-08-03 17:00:23 +0200 | [diff] [blame] | 100 | |
| 101 | """ |
| 102 | |
Mitja Nikolaus | 9c3b29e | 2018-08-22 11:17:50 +0200 | [diff] [blame] | 103 | version = ForeignKey( |
| 104 | Version, db_index=True, related_name="daily_stats", on_delete=CASCADE |
Mitja Nikolaus | cb50f2c | 2018-08-24 13:54:48 +0200 | [diff] [blame] | 105 | ) |
Borjan Tchakaloff | 08974d6 | 2018-02-19 16:02:20 +0100 | [diff] [blame] | 106 | |
| 107 | |
| 108 | class RadioVersion(_VersionStats): |
Borjan Tchakaloff | d50f365 | 2018-08-03 17:00:23 +0200 | [diff] [blame] | 109 | """The all-time stats of a radio version. |
| 110 | |
| 111 | Attributes: |
Mitja Nikolaus | 9c3b29e | 2018-08-22 11:17:50 +0200 | [diff] [blame] | 112 | radio_version: |
| 113 | The radio version number uniquely identifying this version. |
Borjan Tchakaloff | d50f365 | 2018-08-03 17:00:23 +0200 | [diff] [blame] | 114 | |
| 115 | """ |
| 116 | |
Mitja Nikolaus | 9c3b29e | 2018-08-22 11:17:50 +0200 | [diff] [blame] | 117 | radio_version = CharField(max_length=200, unique=True) |
Borjan Tchakaloff | 08974d6 | 2018-02-19 16:02:20 +0100 | [diff] [blame] | 118 | |
Borjan Tchakaloff | d50f365 | 2018-08-03 17:00:23 +0200 | [diff] [blame] | 119 | def __str__(self): # noqa: D105 |
Borjan Tchakaloff | 08974d6 | 2018-02-19 16:02:20 +0100 | [diff] [blame] | 120 | return self.radio_version |
| 121 | |
Borjan Tchakaloff | d50f365 | 2018-08-03 17:00:23 +0200 | [diff] [blame] | 122 | |
Borjan Tchakaloff | 08974d6 | 2018-02-19 16:02:20 +0100 | [diff] [blame] | 123 | class RadioVersionDaily(_DailyVersionStats): |
Borjan Tchakaloff | d50f365 | 2018-08-03 17:00:23 +0200 | [diff] [blame] | 124 | """The daily stats of a radio version. |
| 125 | |
| 126 | Attributes: |
Mitja Nikolaus | 9c3b29e | 2018-08-22 11:17:50 +0200 | [diff] [blame] | 127 | version: |
| 128 | The radio version object (`RadioVersion`) these daily stats are |
| 129 | about. |
Borjan Tchakaloff | d50f365 | 2018-08-03 17:00:23 +0200 | [diff] [blame] | 130 | |
| 131 | """ |
| 132 | |
Mitja Nikolaus | 9c3b29e | 2018-08-22 11:17:50 +0200 | [diff] [blame] | 133 | version = ForeignKey( |
Mitja Nikolaus | cb50f2c | 2018-08-24 13:54:48 +0200 | [diff] [blame] | 134 | RadioVersion, |
| 135 | db_index=True, |
| 136 | related_name="daily_stats", |
Mitja Nikolaus | 9c3b29e | 2018-08-22 11:17:50 +0200 | [diff] [blame] | 137 | on_delete=CASCADE, |
Mitja Nikolaus | cb50f2c | 2018-08-24 13:54:48 +0200 | [diff] [blame] | 138 | ) |
Borjan Tchakaloff | b98dba7 | 2018-03-16 11:04:47 +0400 | [diff] [blame] | 139 | |
| 140 | |
Mitja Nikolaus | 9c3b29e | 2018-08-22 11:17:50 +0200 | [diff] [blame] | 141 | class StatsMetadata(Model): |
Borjan Tchakaloff | b98dba7 | 2018-03-16 11:04:47 +0400 | [diff] [blame] | 142 | """The stats metadata. |
| 143 | |
| 144 | Attributes: |
Mitja Nikolaus | 9c3b29e | 2018-08-22 11:17:50 +0200 | [diff] [blame] | 145 | updated_at: The last time the stats were updated. |
Borjan Tchakaloff | b98dba7 | 2018-03-16 11:04:47 +0400 | [diff] [blame] | 146 | |
| 147 | """ |
| 148 | |
Mitja Nikolaus | 9c3b29e | 2018-08-22 11:17:50 +0200 | [diff] [blame] | 149 | updated_at = DateTimeField() |