Repository navigation
Expand file tree
/
Copy pathresults.py
More file actions
185 lines (159 loc) · 6.22 KB
/
Copy pathresults.py
File metadata and controls
185 lines (159 loc) · 6.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import logging
from datetime import datetime
from django.core.exceptions import ValidationError
from .models import (Environment, Project, Branch, Benchmark, Executable,
Revision, Result, Report)
from . import commits
logger = logging.getLogger(__name__)
# failed runs are recorded with a huge value; anything this big is bogus
SENTINEL_THRESHOLD = 1000000
def validate_result(item):
"""
Validates that a result dictionary has all needed parameters
It returns a tuple
Environment, False when no errors where found
Errormessage, True when there is an error
"""
mandatory_data = [
'commitid',
'branch',
'project',
'executable',
'benchmark',
'environment',
'result_value',
]
error = True
for key in mandatory_data:
if key not in item:
return 'Key "' + key + '" missing from request', error
elif key in item and item[key] == "":
return 'Value for key "' + key + '" empty in request', error
# 'source' is optional: uploaders that predate it (pyperformance on
# speed.python.org) get the 'legacy' default.
if 'source' in item and item['source'] not in dict(Benchmark.S_TYPES):
return 'Invalid source "%s"' % item['source'], error
try:
result_value = float(item['result_value'])
except (TypeError, ValueError):
return 'Value for key "result_value" is not a number', error
if result_value >= SENTINEL_THRESHOLD:
return ('Result value %s rejected: at or above the failed-run '
'sentinel threshold (%s)' % (
item['result_value'], SENTINEL_THRESHOLD), error)
# Check that the Environment exists
try:
e = Environment.objects.get(name=item['environment'])
error = False
return e, error
except Environment.DoesNotExist:
return "Environment %(environment)s not found" % item, error
def save_result(data, update_repo=True):
res, error = validate_result(data)
if error:
return res, True
else:
assert isinstance(res, Environment)
env = res
p, created = Project.objects.get_or_create(name=data["project"])
branch, created = Branch.objects.get_or_create(name=data["branch"],
project=p)
b, created = Benchmark.objects.get_or_create(
name=data["benchmark"], source=data.get("source", "legacy"))
if created:
if "description" in data:
b.description = data["description"]
if "units" in data:
b.units = data["units"]
if "units_title" in data:
b.units_title = data["units_title"]
if "lessisbetter" in data:
b.lessisbetter = data["lessisbetter"]
b.full_clean()
b.save()
try:
rev = branch.revisions.get(commitid=data['commitid'].split(":")[-1])
except Revision.DoesNotExist:
commitid = data['commitid'].split(':')[-1]
conflict = Revision.objects.filter(
commitid=commitid, branch__project=p
).exclude(branch=branch).first()
if conflict:
return (
"Revision %s already exists on branch '%s'; "
"refusing to add it to branch '%s'" % (
commitid, conflict.branch.name, data['branch'])
), True
rev_date = data.get("revision_date")
# "None" (as string) can happen when we urlencode the POST data
if not rev_date or rev_date in ["", "None"]:
rev_date = datetime.today()
# Only take the hash of a mercurial nnn:xxxhash commitid
rev = Revision(branch=branch, project=p,
commitid=commitid,
date=rev_date)
try:
rev.full_clean()
except ValidationError as e:
return str(e), True
if p.repo_type not in ("N", ""):
try:
commit_logs = commits.get_logs(rev, rev, update=update_repo)
except commits.exceptions.CommitLogError as e:
logger.warning("unable to save revision %s info: %s", rev, e,
exc_info=True)
else:
if commit_logs:
log = commit_logs[0]
rev.author = log['author']
rev.date = log['date']
rev.message = log['message']
rev.tag = log['tag']
rev.save()
exe, created = Executable.objects.get_or_create(
name=data['executable'],
project=p
)
try:
r = Result.objects.get(
revision=rev, executable=exe, benchmark=b, environment=env)
except Result.DoesNotExist:
r = Result(revision=rev, executable=exe, benchmark=b, environment=env)
r.value = data["result_value"]
if 'result_date' in data:
r.date = data["result_date"]
elif rev.date:
r.date = rev.date
else:
r.date = datetime.now()
r.std_dev = data.get('std_dev')
r.val_min = data.get('min')
r.val_max = data.get('max')
r.q1 = data.get('q1')
r.q3 = data.get('q3')
r.suite_version = data.get('suite_version', '')
r.full_clean()
r.save()
return (rev, exe, env), False
def create_report_if_enough_data(rev, exe, e):
"""Triggers Report creation when there are enough results"""
if exe.project.track is not True:
return False
last_revs = Revision.objects.filter(
branch=rev.branch
).order_by('-date')[:2]
if len(last_revs) > 1:
current_results = rev.results.filter(executable=exe, environment=e)
last_results = last_revs[1].results.filter(
executable=exe, environment=e)
# If there is are at least as many results as in the last revision,
# create new report
if len(current_results) >= len(last_results):
logger.debug("create_report_if_enough_data: About to create new report")
report, created = Report.objects.get_or_create(
executable=exe, environment=e, revision=rev
)
report.full_clean()
report.save()
logger.debug("Created new report for branch %s and revision %s",
rev.branch, rev.commitid)