webkit-perf.appspot.com should accept test results without medians
[WebKit-https.git] / Websites / webkit-perf.appspot.com / models.py
1 #!/usr/bin/env python
2 # Copyright (C) 2012 Google Inc. All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
6 # met:
7 #
8 #     * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 #     * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following disclaimer
12 # in the documentation and/or other materials provided with the
13 # distribution.
14 #     * Neither the name of Google Inc. nor the names of its
15 # contributors may be used to endorse or promote products derived from
16 # this software without specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 import hashlib
31 import re
32
33 from google.appengine.ext import db
34
35
36 class NumericIdHolder(db.Model):
37     owner = db.ReferenceProperty()
38     # Dummy class whose sole purpose is to generate key().id()
39
40
41 def create_in_transaction_with_numeric_id_holder(callback):
42     id_holder = NumericIdHolder()
43     id_holder.put()
44     id_holder = NumericIdHolder.get(id_holder.key())
45     owner = db.run_in_transaction(callback, id_holder.key().id())
46     if owner:
47         id_holder.owner = owner
48         id_holder.put()
49     else:
50         id_holder.delete()
51     return owner
52
53
54 def delete_model_with_numeric_id_holder(model):
55     id_holder = NumericIdHolder.get_by_id(model.id)
56     model.delete()
57     id_holder.delete()
58
59
60 def modelFromNumericId(id, expected_kind):
61     id_holder = NumericIdHolder.get_by_id(id)
62     return id_holder.owner if id_holder and id_holder.owner and isinstance(id_holder.owner, expected_kind) else None
63
64
65 class Branch(db.Model):
66     id = db.IntegerProperty(required=True)
67     name = db.StringProperty(required=True)
68
69
70 class Platform(db.Model):
71     id = db.IntegerProperty(required=True)
72     name = db.StringProperty(required=True)
73
74
75 class Builder(db.Model):
76     name = db.StringProperty(required=True)
77     password = db.StringProperty(required=True)
78
79     def authenticate(self, raw_password):
80         return self.password == hashlib.sha256(raw_password).hexdigest()
81
82     @staticmethod
83     def hashed_password(raw_password):
84         return hashlib.sha256(raw_password).hexdigest()
85
86
87 class Build(db.Model):
88     branch = db.ReferenceProperty(Branch, required=True, collection_name='build_branch')
89     platform = db.ReferenceProperty(Platform, required=True, collection_name='build_platform')
90     builder = db.ReferenceProperty(Builder, required=True, collection_name='builder_key')
91     buildNumber = db.IntegerProperty(required=True)
92     revision = db.IntegerProperty(required=True)
93     timestamp = db.DateTimeProperty(required=True)
94
95
96 # Used to generate TestMap in the manifest efficiently
97 class Test(db.Model):
98     id = db.IntegerProperty(required=True)
99     name = db.StringProperty(required=True)
100     branches = db.ListProperty(db.Key)
101     platforms = db.ListProperty(db.Key)
102
103     @staticmethod
104     def cache_key(test_id, branch_id, platform_id):
105         return 'runs:%d,%d,%d' % (test_id, branch_id, platform_id)
106
107
108 class TestResult(db.Model):
109     name = db.StringProperty(required=True)
110     build = db.ReferenceProperty(Build, required=True)
111     value = db.FloatProperty(required=True)
112     valueMedian = db.FloatProperty()
113     valueStdev = db.FloatProperty()
114     valueMin = db.FloatProperty()
115     valueMax = db.FloatProperty()
116
117
118 # Temporarily log reports sent by bots
119 class ReportLog(db.Model):
120     timestamp = db.DateTimeProperty(required=True)
121     headers = db.TextProperty()
122     payload = db.TextProperty()