| 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.datastore.datastore_query import Cursor | 5 from google.appengine.datastore.datastore_query import Cursor |
| 6 from google.appengine.ext import ndb | 6 from google.appengine.ext import ndb |
| 7 from google.appengine.ext.webapp import template | 7 from google.appengine.ext.webapp import template |
| 8 | 8 |
| 9 from model.flake import Flake | 9 from model.flake import Flake |
| 10 from status.util import is_last_hour | 10 from status.util import is_last_hour |
| 11 from status.util import is_last_day | 11 from status.util import is_last_day |
| 12 from status.util import is_last_week | 12 from status.util import is_last_week |
| 13 from status.util import is_last_month | 13 from status.util import is_last_month |
| 14 | 14 |
| 15 import datetime | 15 import datetime |
| 16 import logging | 16 import logging |
| 17 import time | 17 import time |
| 18 import webapp2 | 18 import webapp2 |
| 19 | 19 |
| 20 | 20 |
| 21 MAX_OCCURRENCES_PER_FLAKE_ON_INDEX_PAGE = 4 |
| 22 |
| 23 |
| 21 def filterNone(elements): | 24 def filterNone(elements): |
| 22 return [e for e in elements if e is not None] | 25 return [e for e in elements if e is not None] |
| 23 | 26 |
| 24 def FlakeSortFunction(s): # pragma: no cover | 27 def FlakeSortFunction(s): # pragma: no cover |
| 25 return s.builder + str(time.mktime(s.time_finished.timetuple())) | 28 return s.builder + str(time.mktime(s.time_finished.timetuple())) |
| 26 | 29 |
| 27 def GetFilteredOccurences(flake, time_formatter, | 30 def GetFilteredOccurences(flake, time_formatter, |
| 28 filter_function): # pragma: no cover | 31 filter_function): # pragma: no cover |
| 29 occurrences = filterNone(ndb.get_multi(flake.occurrences)) | 32 occurrences = filterNone(ndb.get_multi( |
| 33 flake.occurrences[-MAX_OCCURRENCES_PER_FLAKE_ON_INDEX_PAGE:])) |
| 30 | 34 |
| 31 failure_run_keys = [] | 35 failure_run_keys = [] |
| 32 patchsets_keys = [] | 36 patchsets_keys = [] |
| 33 for o in occurrences: | 37 for o in occurrences: |
| 34 failure_run_keys.append(o.failure_run) | 38 failure_run_keys.append(o.failure_run) |
| 35 patchsets_keys.append(o.failure_run.parent()) | 39 patchsets_keys.append(o.failure_run.parent()) |
| 36 | 40 |
| 37 failure_runs = filterNone(ndb.get_multi(failure_run_keys)) | 41 failure_runs = filterNone(ndb.get_multi(failure_run_keys)) |
| 38 patchsets = filterNone(ndb.get_multi(patchsets_keys)) | 42 patchsets = filterNone(ndb.get_multi(patchsets_keys)) |
| 39 | 43 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 time_format = '%H:%M:%S' | 96 time_format = '%H:%M:%S' |
| 93 else: | 97 else: |
| 94 time_format = '%Y-%m-%d %H:%M:%S' | 98 time_format = '%Y-%m-%d %H:%M:%S' |
| 95 | 99 |
| 96 def time_formatter(t): | 100 def time_formatter(t): |
| 97 return t.strftime(time_format) | 101 return t.strftime(time_format) |
| 98 | 102 |
| 99 for f in flakes: | 103 for f in flakes: |
| 100 f.filtered_occurrences = GetFilteredOccurences( | 104 f.filtered_occurrences = GetFilteredOccurences( |
| 101 f, time_formatter, filter_by_range) | 105 f, time_formatter, filter_by_range) |
| 106 if len(f.occurrences) > MAX_OCCURRENCES_PER_FLAKE_ON_INDEX_PAGE: |
| 107 f.more_occurrences = True |
| 102 | 108 |
| 103 values = { | 109 values = { |
| 104 'range': time_range, | 110 'range': time_range, |
| 105 'flakes': flakes, | 111 'flakes': flakes, |
| 106 'more': more, | 112 'more': more, |
| 107 'cursor': next_cursor.urlsafe() if next_cursor else '', | 113 'cursor': next_cursor.urlsafe() if next_cursor else '', |
| 108 } | 114 } |
| 109 self.response.write(template.render('templates/index.html', values)) | 115 self.response.write(template.render('templates/index.html', values)) |
| OLD | NEW |