OLD | NEW |
---|---|
(Empty) | |
1 # Copyright 2016 The Chromium Authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
5 """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.
| |
6 | |
7 import datetime | |
8 | |
9 | |
10 def is_last_hour(date): | |
11 return (datetime.datetime.utcnow() - date) < datetime.timedelta(hours=1) | |
12 | |
13 | |
14 def is_last_day(date): | |
15 return (datetime.datetime.utcnow() - date) < datetime.timedelta(days=1) | |
16 | |
17 | |
18 def is_last_week(date): | |
19 return (datetime.datetime.utcnow() - date) < datetime.timedelta(weeks=1) | |
20 | |
21 | |
22 def is_last_month(date): | |
23 return (datetime.datetime.utcnow() - date) < datetime.timedelta(days=31) | |
24 | |
25 | |
26 def add_occurrence_time_to_flake(flake, occurrence_time): | |
27 if occurrence_time > flake.last_time_seen: | |
28 flake.last_time_seen = occurrence_time | |
29 if is_last_hour(occurrence_time): | |
30 flake.count_hour += 1 | |
31 flake.last_hour = True | |
32 if is_last_day(occurrence_time): | |
33 flake.count_day += 1 | |
34 flake.last_day = True | |
35 if is_last_week(occurrence_time): | |
36 flake.count_week += 1 | |
37 flake.last_week = True | |
38 if is_last_month(occurrence_time): | |
39 flake.count_month += 1 | |
40 flake.last_month = True | |
41 flake.count_all += 1 | |
OLD | NEW |