| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 import hashlib | 5 import hashlib |
| 6 | 6 |
| 7 from google.appengine.ext import ndb | 7 from google.appengine.ext import ndb |
| 8 | 8 |
| 9 from model.crash.crash_analysis import CrashAnalysis | 9 from model.crash.crash_analysis import CrashAnalysis |
| 10 | 10 |
| 11 | 11 |
| 12 class FracasCrashAnalysis(CrashAnalysis): | 12 class FracasCrashAnalysis(CrashAnalysis): |
| 13 """Represents an analysis of a Chrome crash.""" | 13 """Represents an analysis of a Chrome crash.""" |
| 14 # Data of crash per million page loads for each Chrome version. | 14 # Data of crash per million page loads for each Chrome version. |
| 15 versions_to_cpm = ndb.JsonProperty(indexed=False) | 15 versions_to_historical = ndb.JsonProperty(indexed=False) |
| 16 | 16 |
| 17 def Reset(self): | 17 def Reset(self): |
| 18 super(FracasCrashAnalysis, self).Reset() | 18 super(FracasCrashAnalysis, self).Reset() |
| 19 self.versions_to_cpm = None | 19 self.versions_to_historical = None |
| 20 | 20 |
| 21 @ndb.ComputedProperty | 21 @ndb.ComputedProperty |
| 22 def channel(self): | 22 def channel(self): |
| 23 return self.key.pairs()[0][1].split('/')[0] | 23 return self.key.pairs()[0][1].split('/')[0] |
| 24 | 24 |
| 25 @ndb.ComputedProperty | 25 @ndb.ComputedProperty |
| 26 def platform(self): | 26 def platform(self): |
| 27 return self.key.pairs()[0][1].split('/')[1] | 27 return self.key.pairs()[0][1].split('/')[1] |
| 28 | 28 |
| 29 @staticmethod | 29 @staticmethod |
| 30 def _CreateKey(channel, platform, signature): | 30 def _CreateKey(channel, platform, signature): |
| 31 # Use sha1 hex digest of signature to avoid char conflict with '/'. | 31 # Use sha1 hex digest of signature to avoid char conflict with '/'. |
| 32 return ndb.Key('FracasCrashAnalysis', '%s/%s/%s' % ( | 32 return ndb.Key('FracasCrashAnalysis', '%s/%s/%s' % ( |
| 33 channel, platform, hashlib.sha1(signature).hexdigest())) | 33 channel, platform, hashlib.sha1(signature).hexdigest())) |
| 34 | 34 |
| 35 @classmethod | 35 @classmethod |
| 36 def Get(cls, channel, platform, signature): | 36 def Get(cls, channel, platform, signature): |
| 37 return cls._CreateKey(channel, platform, signature).get() | 37 return cls._CreateKey(channel, platform, signature).get() |
| 38 | 38 |
| 39 @classmethod | 39 @classmethod |
| 40 def Create(cls, channel, platform, signature): | 40 def Create(cls, channel, platform, signature): |
| 41 analysis = cls(key=cls._CreateKey(channel, platform, signature)) | 41 analysis = cls(key=cls._CreateKey(channel, platform, signature)) |
| 42 analysis.signature = signature | 42 analysis.signature = signature |
| 43 return analysis | 43 return analysis |
| OLD | NEW |