| 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 | 17 |
| 18 | 18 |
| 19 def RunsSortFunction(s): # pragma: no cover | 19 def RunsSortFunction(s): # pragma: no cover |
| 20 return s.time_finished | 20 return s.time_finished |
| 21 | 21 |
| 22 def filterNone(elements): | 22 def filterNone(elements): |
| 23 return [e for e in elements if e is not None] | 23 return [e for e in elements if e is not None] |
| 24 | 24 |
| 25 def show_all_flakes(flake, bug_friendly): # pragma: no cover | 25 def show_all_flakes(flake): # pragma: no cover |
| 26 occurrence_keys = [] | 26 occurrence_keys = [] |
| 27 for o in flake.occurrences: | 27 for o in flake.occurrences: |
| 28 occurrence_keys.append(o) | 28 occurrence_keys.append(o) |
| 29 | 29 |
| 30 occurrences = filterNone(ndb.get_multi(occurrence_keys)) | 30 occurrences = filterNone(ndb.get_multi(occurrence_keys)) |
| 31 | 31 |
| 32 failure_runs_keys = [] | 32 failure_runs_keys = [] |
| 33 patchsets_keys = [] | 33 patchsets_keys = [] |
| 34 flakes = [] | 34 flakes = [] |
| 35 for o in occurrences: | 35 for o in occurrences: |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 if current_group[-1].time_finished - f.time_finished < MAX_GROUP_DISTANCE: | 73 if current_group[-1].time_finished - f.time_finished < MAX_GROUP_DISTANCE: |
| 74 current_group.append(f) | 74 current_group.append(f) |
| 75 else: | 75 else: |
| 76 grouped_runs.append(current_group) | 76 grouped_runs.append(current_group) |
| 77 current_group = [f] | 77 current_group = [f] |
| 78 grouped_runs.append(current_group) | 78 grouped_runs.append(current_group) |
| 79 | 79 |
| 80 values = { | 80 values = { |
| 81 'flake': flake, | 81 'flake': flake, |
| 82 'grouped_runs': grouped_runs, | 82 'grouped_runs': grouped_runs, |
| 83 'bug_friendly': bug_friendly, | |
| 84 'time_now': datetime.datetime.utcnow(), | 83 'time_now': datetime.datetime.utcnow(), |
| 85 } | 84 } |
| 86 | 85 |
| 87 return template.render('templates/all_flake_occurrences.html', values) | 86 return template.render('templates/all_flake_occurrences.html', values) |
| 88 | 87 |
| 89 class AllFlakeOccurrences(webapp2.RequestHandler): # pragma: no cover | 88 class AllFlakeOccurrences(webapp2.RequestHandler): # pragma: no cover |
| 90 def get(self): | 89 def get(self): |
| 91 key = self.request.get('key') | 90 key = self.request.get('key') |
| 92 flake = ndb.Key(urlsafe=key).get() | 91 flake = ndb.Key(urlsafe=key).get() |
| 93 bug_friendly = self.request.get('bug_friendly', 0) | |
| 94 | 92 |
| 95 if not flake: | 93 if not flake: |
| 96 self.response.set_status(404, 'Flake with id %s does not exist' % key) | 94 self.response.set_status(404, 'Flake with id %s does not exist' % key) |
| 97 return | 95 return |
| 98 | 96 |
| 99 self.response.write(show_all_flakes(flake, bug_friendly)) | 97 self.response.write(show_all_flakes(flake)) |
| OLD | NEW |