blob: 461db80519083ea35f5ff7db101939599e707e47 [file] [log] [blame]
Borjan Tchakaloffd50f3652018-08-03 17:00:23 +02001"""The stats models."""
Mitja Nikolaus9c3b29e2018-08-22 11:17:50 +02002from django.db.models import (
3 BooleanField,
4 CASCADE,
5 CharField,
6 DateField,
7 DateTimeField,
8 ForeignKey,
9 IntegerField,
10 Model,
11)
Dirk Vogt62ff7f22017-05-04 16:07:21 +020012
Dirk Vogt1accb672017-05-10 14:07:42 +020013
Mitja Nikolaus9c3b29e2018-08-22 11:17:50 +020014class _VersionStats(Model):
Borjan Tchakaloffd50f3652018-08-03 17:00:23 +020015 """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 Nikolaus9c3b29e2018-08-22 11:17:50 +020021 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 Tchakaloffd50f3652018-08-03 17:00:23 +020033
34 """
35
Mitja Nikolaus9c3b29e2018-08-22 11:17:50 +020036 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 Tchakaloff01e102c2018-02-19 17:47:45 +010044
45 class Meta:
46 abstract = True
47
Borjan Tchakaloffd50f3652018-08-03 17:00:23 +020048
Mitja Nikolaus9c3b29e2018-08-22 11:17:50 +020049class _DailyVersionStats(Model):
Borjan Tchakaloffd50f3652018-08-03 17:00:23 +020050 """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 Nikolaus9c3b29e2018-08-22 11:17:50 +020056 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 Tchakaloffd50f3652018-08-03 17:00:23 +020066
67 """
68
Mitja Nikolaus9c3b29e2018-08-22 11:17:50 +020069 date = DateField()
70 heartbeats = IntegerField(default=0)
71 prob_crashes = IntegerField(default=0)
72 smpl = IntegerField(default=0)
73 other = IntegerField(default=0)
Borjan Tchakaloff01e102c2018-02-19 17:47:45 +010074
75 class Meta:
76 abstract = True
77
78
79class Version(_VersionStats):
Borjan Tchakaloffd50f3652018-08-03 17:00:23 +020080 """The all-time stats of a software version.
81
82 Attributes:
Mitja Nikolaus9c3b29e2018-08-22 11:17:50 +020083 build_fingerprint:
84 The software build fingerprint uniquely identifying this version.
Borjan Tchakaloffd50f3652018-08-03 17:00:23 +020085
86 """
87
Mitja Nikolaus9c3b29e2018-08-22 11:17:50 +020088 build_fingerprint = CharField(max_length=200, unique=True)
Borjan Tchakaloff01e102c2018-02-19 17:47:45 +010089
Borjan Tchakaloffd50f3652018-08-03 17:00:23 +020090 def __str__(self): # noqa: D105
Dirk Vogt1accb672017-05-10 14:07:42 +020091 return self.build_fingerprint
Borjan Tchakaloff01e102c2018-02-19 17:47:45 +010092
Borjan Tchakaloffd50f3652018-08-03 17:00:23 +020093
Borjan Tchakaloff01e102c2018-02-19 17:47:45 +010094class VersionDaily(_DailyVersionStats):
Borjan Tchakaloffd50f3652018-08-03 17:00:23 +020095 """The daily stats of a software version.
96
97 Attributes:
Mitja Nikolaus9c3b29e2018-08-22 11:17:50 +020098 version:
99 The software version object (`Version`) these daily stats are about.
Borjan Tchakaloffd50f3652018-08-03 17:00:23 +0200100
101 """
102
Mitja Nikolaus9c3b29e2018-08-22 11:17:50 +0200103 version = ForeignKey(
104 Version, db_index=True, related_name="daily_stats", on_delete=CASCADE
Mitja Nikolauscb50f2c2018-08-24 13:54:48 +0200105 )
Borjan Tchakaloff08974d62018-02-19 16:02:20 +0100106
107
108class RadioVersion(_VersionStats):
Borjan Tchakaloffd50f3652018-08-03 17:00:23 +0200109 """The all-time stats of a radio version.
110
111 Attributes:
Mitja Nikolaus9c3b29e2018-08-22 11:17:50 +0200112 radio_version:
113 The radio version number uniquely identifying this version.
Borjan Tchakaloffd50f3652018-08-03 17:00:23 +0200114
115 """
116
Mitja Nikolaus9c3b29e2018-08-22 11:17:50 +0200117 radio_version = CharField(max_length=200, unique=True)
Borjan Tchakaloff08974d62018-02-19 16:02:20 +0100118
Borjan Tchakaloffd50f3652018-08-03 17:00:23 +0200119 def __str__(self): # noqa: D105
Borjan Tchakaloff08974d62018-02-19 16:02:20 +0100120 return self.radio_version
121
Borjan Tchakaloffd50f3652018-08-03 17:00:23 +0200122
Borjan Tchakaloff08974d62018-02-19 16:02:20 +0100123class RadioVersionDaily(_DailyVersionStats):
Borjan Tchakaloffd50f3652018-08-03 17:00:23 +0200124 """The daily stats of a radio version.
125
126 Attributes:
Mitja Nikolaus9c3b29e2018-08-22 11:17:50 +0200127 version:
128 The radio version object (`RadioVersion`) these daily stats are
129 about.
Borjan Tchakaloffd50f3652018-08-03 17:00:23 +0200130
131 """
132
Mitja Nikolaus9c3b29e2018-08-22 11:17:50 +0200133 version = ForeignKey(
Mitja Nikolauscb50f2c2018-08-24 13:54:48 +0200134 RadioVersion,
135 db_index=True,
136 related_name="daily_stats",
Mitja Nikolaus9c3b29e2018-08-22 11:17:50 +0200137 on_delete=CASCADE,
Mitja Nikolauscb50f2c2018-08-24 13:54:48 +0200138 )
Borjan Tchakaloffb98dba72018-03-16 11:04:47 +0400139
140
Mitja Nikolaus9c3b29e2018-08-22 11:17:50 +0200141class StatsMetadata(Model):
Borjan Tchakaloffb98dba72018-03-16 11:04:47 +0400142 """The stats metadata.
143
144 Attributes:
Mitja Nikolaus9c3b29e2018-08-22 11:17:50 +0200145 updated_at: The last time the stats were updated.
Borjan Tchakaloffb98dba72018-03-16 11:04:47 +0400146
147 """
148
Mitja Nikolaus9c3b29e2018-08-22 11:17:50 +0200149 updated_at = DateTimeField()