Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_WITHOUT_SHOW_ALL = 50 | |
|
shishkander
2016/05/06 21:41:09
suggestion:
MAX_OCCURRENCES_BY_DEFAULT = 50
Sergiy Byelozyorov
2016/05/06 21:55:09
Done.
| |
| 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 if show_all: |
| 27 for o in flake.occurrences: | 28 occurrences = filterNone(ndb.get_multi(flake.occurrences)) |
| 28 occurrence_keys.append(o) | 29 else: |
| 29 | 30 occurrences = filterNone(ndb.get_multi( |
| 30 occurrences = filterNone(ndb.get_multi(occurrence_keys)) | 31 flake.occurrences[-MAX_OCCURRENCES_WITHOUT_SHOW_ALL:])) |
|
shishkander
2016/05/06 21:41:09
suggestoion:
from_index = 0 if show_all else -MAX_
Sergiy Byelozyorov
2016/05/06 21:55:09
Done.
| |
| 31 | 32 |
| 32 failure_runs_keys = [] | 33 failure_runs_keys = [] |
| 33 patchsets_keys = [] | 34 patchsets_keys = [] |
| 34 flakes = [] | 35 flakes = [] |
| 35 for o in occurrences: | 36 for o in occurrences: |
| 36 failure_runs_keys.append(o.failure_run) | 37 failure_runs_keys.append(o.failure_run) |
| 37 patchsets_keys.append(o.failure_run.parent()) | 38 patchsets_keys.append(o.failure_run.parent()) |
| 38 flakes.append(f for f in o.flakes if f.failure == flake.name) | 39 flakes.append(f for f in o.flakes if f.failure == flake.name) |
| 39 | 40 |
| 40 failure_runs = filterNone(ndb.get_multi(failure_runs_keys)) | 41 failure_runs = filterNone(ndb.get_multi(failure_runs_keys)) |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 70 if failure_runs_extended: | 71 if failure_runs_extended: |
| 71 current_group = [failure_runs_extended[0]] | 72 current_group = [failure_runs_extended[0]] |
| 72 for f in failure_runs_extended[1:]: | 73 for f in failure_runs_extended[1:]: |
| 73 if current_group[-1].time_finished - f.time_finished < MAX_GROUP_DISTANCE: | 74 if current_group[-1].time_finished - f.time_finished < MAX_GROUP_DISTANCE: |
| 74 current_group.append(f) | 75 current_group.append(f) |
| 75 else: | 76 else: |
| 76 grouped_runs.append(current_group) | 77 grouped_runs.append(current_group) |
| 77 current_group = [f] | 78 current_group = [f] |
| 78 grouped_runs.append(current_group) | 79 grouped_runs.append(current_group) |
| 79 | 80 |
| 81 show_all_link = (len(flake.occurrences) > MAX_OCCURRENCES_WITHOUT_SHOW_ALL and | |
| 82 not show_all) | |
| 80 values = { | 83 values = { |
| 81 'flake': flake, | 84 'flake': flake, |
| 82 'grouped_runs': grouped_runs, | 85 'grouped_runs': grouped_runs, |
| 86 'show_all_link': show_all_link, | |
| 83 'time_now': datetime.datetime.utcnow(), | 87 'time_now': datetime.datetime.utcnow(), |
| 84 } | 88 } |
| 85 | 89 |
| 86 return template.render('templates/all_flake_occurrences.html', values) | 90 return template.render('templates/all_flake_occurrences.html', values) |
| 87 | 91 |
| 88 class AllFlakeOccurrences(webapp2.RequestHandler): # pragma: no cover | 92 class AllFlakeOccurrences(webapp2.RequestHandler): # pragma: no cover |
| 89 def get(self): | 93 def get(self): |
| 90 key = self.request.get('key') | 94 key = self.request.get('key') |
| 91 flake = ndb.Key(urlsafe=key).get() | 95 flake = ndb.Key(urlsafe=key).get() |
| 96 show_all = self.request.get('show_all', 0) | |
| 92 | 97 |
| 93 if not flake: | 98 if not flake: |
| 94 self.response.set_status(404, 'Flake with id %s does not exist' % key) | 99 self.response.set_status(404, 'Flake with id %s does not exist' % key) |
| 95 return | 100 return |
| 96 | 101 |
| 97 self.response.write(show_all_flakes(flake)) | 102 self.response.write(show_all_flakes(flake, show_all)) |
| OLD | NEW |