~qajenkinsbot/qa-dashboard/production

« back to all changes in this revision

Viewing changes to smokeng/models.py

  • Committer: Joe Talbott
  • Date: 2013-05-14 01:17:05 UTC
  • mto: (1.1.411 qa-dashboard)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: joe.talbott@canonical.com-20130514011705-bcakz536ejsursu6
smokeng - Add smoke rewrite.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# QA Dashboard
 
2
# Copyright 2012-2013 Canonical Ltd.
 
3
 
 
4
# This program is free software: you can redistribute it and/or modify it
 
5
# under the terms of the GNU Affero General Public License version 3, as
 
6
# published by the Free Software Foundation.
 
7
 
 
8
# This program is distributed in the hope that it will be useful, but
 
9
# WITHOUT ANY WARRANTY; without even the implied warranties of
 
10
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
11
# PURPOSE.  See the GNU Affero General Public License for more details.
 
12
 
 
13
# You should have received a copy of the GNU Affero General Public License
 
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 
 
16
from django.db import models
 
17
 
 
18
from common.models import (
 
19
    DashboardBaseModel,
 
20
    Bug,
 
21
    JenkinsBuild,
 
22
)
 
23
 
 
24
 
 
25
class SmokeImage(DashboardBaseModel):
 
26
    class Meta:
 
27
        db_table = 'smoke_images'
 
28
 
 
29
    build_number = models.CharField(max_length=200)
 
30
    release = models.CharField(max_length=200)
 
31
    flavor = models.CharField(max_length=200)
 
32
    arch = models.CharField(max_length=200)
 
33
    variant = models.CharField(max_length=200)
 
34
 
 
35
    def __unicode__(self):
 
36
        return "{} {} {} {}".format(
 
37
            self.release,
 
38
            self.variant,
 
39
            self.arch,
 
40
            self.build_number,
 
41
        )
 
42
 
 
43
    def get_sum(self, field):
 
44
 
 
45
        objs = self.smokeresult_set.aggregate(models.Sum(field))
 
46
 
 
47
        if len(objs) == 0:
 
48
            return 0
 
49
        else:
 
50
            return objs['{}__sum'.format(field)]
 
51
 
 
52
    @property
 
53
    def pass_count(self):
 
54
        return self.get_sum('pass_count')
 
55
 
 
56
    @property
 
57
    def fail_count(self):
 
58
        return self.get_sum('fail_count')
 
59
 
 
60
    @property
 
61
    def error_count(self):
 
62
        return self.get_sum('error_count')
 
63
 
 
64
    @property
 
65
    def total_count(self):
 
66
        return self.get_sum('total_count')
 
67
 
 
68
    @property
 
69
    def pass_rate(self):
 
70
        agg_data = SmokeResult.objects.filter(
 
71
            image=self,
 
72
            publish=True,
 
73
        ).aggregate(
 
74
            models.Sum('pass_count'),
 
75
            models.Sum('total_count'),
 
76
        )
 
77
 
 
78
        if agg_data['total_count__sum'] == 0:
 
79
            return 0
 
80
 
 
81
        return float(100) * agg_data['pass_count__sum'] / agg_data['total_count__sum']
 
82
 
 
83
    @property
 
84
    def _bugs(self):
 
85
        return Bug.objects.filter(build_bugs__smokeresult__image=self)
 
86
 
 
87
 
 
88
class SmokeResult(DashboardBaseModel):
 
89
    class Meta:
 
90
        db_table = 'smoke_results'
 
91
    image = models.ForeignKey(SmokeImage)
 
92
    jenkins_build = models.ForeignKey(JenkinsBuild)
 
93
    name = models.CharField(max_length=255)
 
94
    fail_count = models.IntegerField()
 
95
    error_count = models.IntegerField(null=False, default=0)
 
96
    pass_count = models.IntegerField()
 
97
    total_count = models.IntegerField()
 
98
    ran_at = models.DateTimeField('date run')
 
99
 
 
100
    def __unicode__(self):
 
101
        return "{} - {}".format(
 
102
            self.name,
 
103
            self.ran_at,
 
104
        )
 
105
 
 
106
    @property
 
107
    def bugs(self):
 
108
        return self.jenkins_build.bugs.all()
 
109
 
 
110
    @property
 
111
    def bug_count(self):
 
112
        return self.jenkins_build.bugs.count()
 
113
 
 
114
    @property
 
115
    def logs(self):
 
116
        return self.smokelog_set.all()
 
117
 
 
118
    @property
 
119
    def log_count(self):
 
120
        return self.smokelog_set.count()
 
121
 
 
122
    @property
 
123
    def pass_rate(self):
 
124
        if self.total_count == 0:
 
125
            return 0
 
126
 
 
127
        return self.pass_count / self.total_count
 
128
 
 
129
class SmokeLog(DashboardBaseModel):
 
130
    class Meta:
 
131
        db_table = "smoke_logs"
 
132
 
 
133
    result = models.ForeignKey(SmokeResult)
 
134
    display_name = models.CharField(max_length=255, null=True)
 
135
    path = models.TextField()
 
136
 
 
137
class SmokeResultBug(DashboardBaseModel):
 
138
    class Meta:
 
139
        db_table = "smoke_result_bugs"
 
140
 
 
141
    bug = models.ForeignKey(Bug)
 
142
    result = models.ForeignKey(SmokeResult)