Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: appengine/chromium_try_flakes/handlers/all_flake_occurrences.py

Issue 1945903004: Add show-all feature to the all-flake-occurrences page (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@deprecate_bug_friendly
Patch Set: Addressed comments Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | appengine/chromium_try_flakes/templates/all_flake_occurrences.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 from google.appengine.ext import ndb 5 from google.appengine.ext import ndb
6 from google.appengine.ext.webapp import template 6 from google.appengine.ext.webapp import template
7 7
8 from model.flake import Flake 8 from model.flake import Flake
9 9
10 import datetime 10 import datetime
11 import logging 11 import logging
12 import time 12 import time
13 import webapp2 13 import webapp2
14 14
15 15
16 MAX_GROUP_DISTANCE = datetime.timedelta(days=3) 16 MAX_GROUP_DISTANCE = datetime.timedelta(days=3)
17 MAX_OCCURRENCES_DEFAULT = 50
17 18
18 19
19 def RunsSortFunction(s): # pragma: no cover 20 def RunsSortFunction(s): # pragma: no cover
20 return s.time_finished 21 return s.time_finished
21 22
22 def filterNone(elements): 23 def filterNone(elements):
23 return [e for e in elements if e is not None] 24 return [e for e in elements if e is not None]
24 25
25 def show_all_flakes(flake): # pragma: no cover 26 def show_all_flakes(flake, show_all): # pragma: no cover
26 occurrence_keys = [] 27 from_index = 0 if show_all else -MAX_OCCURRENCES_DEFAULT
27 for o in flake.occurrences: 28 occurrences = filterNone(ndb.get_multi(flake.occurrences[from_index:]))
28 occurrence_keys.append(o)
29
30 occurrences = filterNone(ndb.get_multi(occurrence_keys))
31 29
32 failure_runs_keys = [] 30 failure_runs_keys = []
33 patchsets_keys = [] 31 patchsets_keys = []
34 flakes = [] 32 flakes = []
35 for o in occurrences: 33 for o in occurrences:
36 failure_runs_keys.append(o.failure_run) 34 failure_runs_keys.append(o.failure_run)
37 patchsets_keys.append(o.failure_run.parent()) 35 patchsets_keys.append(o.failure_run.parent())
38 flakes.append(f for f in o.flakes if f.failure == flake.name) 36 flakes.append(f for f in o.flakes if f.failure == flake.name)
39 37
40 failure_runs = filterNone(ndb.get_multi(failure_runs_keys)) 38 failure_runs = filterNone(ndb.get_multi(failure_runs_keys))
(...skipping 29 matching lines...) Expand all
70 if failure_runs_extended: 68 if failure_runs_extended:
71 current_group = [failure_runs_extended[0]] 69 current_group = [failure_runs_extended[0]]
72 for f in failure_runs_extended[1:]: 70 for f in failure_runs_extended[1:]:
73 if current_group[-1].time_finished - f.time_finished < MAX_GROUP_DISTANCE: 71 if current_group[-1].time_finished - f.time_finished < MAX_GROUP_DISTANCE:
74 current_group.append(f) 72 current_group.append(f)
75 else: 73 else:
76 grouped_runs.append(current_group) 74 grouped_runs.append(current_group)
77 current_group = [f] 75 current_group = [f]
78 grouped_runs.append(current_group) 76 grouped_runs.append(current_group)
79 77
78 show_all_link = (len(flake.occurrences) > MAX_OCCURRENCES_DEFAULT and
79 not show_all)
80 values = { 80 values = {
81 'flake': flake, 81 'flake': flake,
82 'grouped_runs': grouped_runs, 82 'grouped_runs': grouped_runs,
83 'show_all_link': show_all_link,
83 'time_now': datetime.datetime.utcnow(), 84 'time_now': datetime.datetime.utcnow(),
84 } 85 }
85 86
86 return template.render('templates/all_flake_occurrences.html', values) 87 return template.render('templates/all_flake_occurrences.html', values)
87 88
88 class AllFlakeOccurrences(webapp2.RequestHandler): # pragma: no cover 89 class AllFlakeOccurrences(webapp2.RequestHandler): # pragma: no cover
89 def get(self): 90 def get(self):
90 key = self.request.get('key') 91 key = self.request.get('key')
91 flake = ndb.Key(urlsafe=key).get() 92 flake = ndb.Key(urlsafe=key).get()
93 show_all = self.request.get('show_all', 0)
92 94
93 if not flake: 95 if not flake:
94 self.response.set_status(404, 'Flake with id %s does not exist' % key) 96 self.response.set_status(404, 'Flake with id %s does not exist' % key)
95 return 97 return
96 98
97 self.response.write(show_all_flakes(flake)) 99 self.response.write(show_all_flakes(flake, show_all))
OLDNEW
« no previous file with comments | « no previous file | appengine/chromium_try_flakes/templates/all_flake_occurrences.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698