Chromium Code Reviews| Index: appengine/chromium_try_flakes/status/util.py |
| diff --git a/appengine/chromium_try_flakes/status/util.py b/appengine/chromium_try_flakes/status/util.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..da03496045ddedefcc7543be1c30a0e38cecd44d |
| --- /dev/null |
| +++ b/appengine/chromium_try_flakes/status/util.py |
| @@ -0,0 +1,41 @@ |
| +# Copyright 2016 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +"""Utility functions for handling flakes.""" |
|
Sergiy Byelozyorov
2016/02/02 21:27:27
This is copied from stats/cq_status.py. If kept th
tandrii(chromium)
2016/02/02 21:54:18
yeah, new file is LGTM.
|
| + |
| +import datetime |
| + |
| + |
| +def is_last_hour(date): |
| + return (datetime.datetime.utcnow() - date) < datetime.timedelta(hours=1) |
| + |
| + |
| +def is_last_day(date): |
| + return (datetime.datetime.utcnow() - date) < datetime.timedelta(days=1) |
| + |
| + |
| +def is_last_week(date): |
| + return (datetime.datetime.utcnow() - date) < datetime.timedelta(weeks=1) |
| + |
| + |
| +def is_last_month(date): |
| + return (datetime.datetime.utcnow() - date) < datetime.timedelta(days=31) |
| + |
| + |
| +def add_occurrence_time_to_flake(flake, occurrence_time): |
| + if occurrence_time > flake.last_time_seen: |
| + flake.last_time_seen = occurrence_time |
| + if is_last_hour(occurrence_time): |
| + flake.count_hour += 1 |
| + flake.last_hour = True |
| + if is_last_day(occurrence_time): |
| + flake.count_day += 1 |
| + flake.last_day = True |
| + if is_last_week(occurrence_time): |
| + flake.count_week += 1 |
| + flake.last_week = True |
| + if is_last_month(occurrence_time): |
| + flake.count_month += 1 |
| + flake.last_month = True |
| + flake.count_all += 1 |