Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(319)

Side by Side Diff: appengine/findit/model/base_triaged_model.py

Issue 2416303002: [Findit] Adding support for triaging suspected builds from flake analysis (Closed)
Patch Set: Clean up and adding unit tests Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 from google.appengine.ext import ndb
6 from google.appengine.api import users
7
8 from common import appengine_util
9 from common import time_util
10 from model import triage_status
11
12
13 class TriageResult(ndb.Model):
14 # The user who updated this result.
15 user_name = ndb.StringProperty(default=None, indexed=False)
16
17 # The time this triage result was determined.
18 triaged_time = ndb.DateTimeProperty(indexed=False, auto_now=True)
19
20 # The result of the analysis as correct or not. If not triaged, the value
21 # should be None. Other traige result codes are up to the child class to set.
22 triage_result = ndb.IntegerProperty(indexed=True, default=None)
23
24 # Record which version of that generated the analysis this result is to be a
25 # part of. Since not all triaged models are versioned, record the version
26 # number as a string for those that are versioned or Findit's version for
27 # those that aren't.
28 version = ndb.StringProperty(indexed=False)
chanli 2016/10/14 21:25:09 This is very confusing. I don't think you should m
lijeffrey 2016/10/14 23:11:31 Done. Created findit_version and version_number.
29
30 # Other information about this result. For example, cl_info for suspected CLs
31 # or the suspected range for a flake analysis.
32 suspect_info = ndb.StringProperty(default=None, indexed=False)
chanli 2016/10/14 21:25:09 Based on the comments, this value should not be a
lijeffrey 2016/10/14 23:11:31 Changed to Json property
33
34
35 class TriagedModel(ndb.Model):
36 """The parent class for models that can have traige results."""
37
38 def UpdateTriageResult(self, triage_result, suspect_info, user_name,
39 version=None):
40 result = TriageResult()
41 result.user_name = user_name
42 result.triage_result = triage_result
43 result.version = (
44 str(version) if version else appengine_util.GetCurrentVersion())
45 result.suspect_info = suspect_info
46 self.triage_history.append(result)
47
48 # Record the triage result history.
49 triage_history = ndb.LocalStructuredProperty(
chanli 2016/10/14 21:25:09 Nit: Do you ming move this to the end of the class
lijeffrey 2016/10/14 23:11:31 Done.
50 TriageResult, repeated=True, indexed=False, compressed=True)
51
52 @staticmethod
53 def GetTriageHistory(analysis):
54 """Gets the triage history of a WfAnalysis as a list.
chanli 2016/10/14 21:25:09 This is not necessarily a WfAnalysis, right? Actua
lijeffrey 2016/10/14 23:11:31 Oh yes sorry I got ahead of myself. That is the ev
chanli 2016/10/15 01:47:21 I actually have a second question here: why make t
55
56 Args:
57 analysis (WfAnalysis): An instance of WfAnalysis assumed to inherit
58 TriagedModel.
59
60 Returns:
61 A list of dicts representing the triage history of the analysis.
62 """
63 if (not users.is_current_user_admin() or
64 not analysis.completed or
65 not analysis.triage_history): # pragma: no cover
66 return None
67
68 triage_history = []
69 for triage_record in analysis.triage_history:
70 triage_history.append({
71 'triaged_time': time_util.FormatDatetime(triage_record.triaged_time),
72 'user_name': triage_record.user_name,
73 'suspect_info': triage_record.suspect_info,
74 'triage_result': (
75 triage_status.TRIAGE_STATUS_TO_DESCRIPTION.get(
76 triage_record.triage_result)),
77 'version': triage_record.version,
78 })
79
80 return triage_history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698