| 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 from collections import namedtuple | 5 from collections import namedtuple |
| 6 from collections import defaultdict | 6 from collections import defaultdict |
| 7 import logging | 7 import logging |
| 8 import re | 8 import re |
| 9 | 9 |
| 10 from crash.component import Component | 10 from crash.component import Component |
| 11 from crash.occurrence import RankByOccurrence | 11 from crash.occurrence import RankByOccurrence |
| 12 from lib.gitiles.diff import ChangeType | 12 from libs.gitiles.diff import ChangeType |
| 13 |
| 13 | 14 |
| 14 class ComponentClassifier(object): | 15 class ComponentClassifier(object): |
| 15 """Determines the component of a crash. | 16 """Determines the component of a crash. |
| 16 | 17 |
| 17 For example: ['Blink>DOM', 'Blink>HTML']. | 18 For example: ['Blink>DOM', 'Blink>HTML']. |
| 18 """ | 19 """ |
| 19 | 20 |
| 20 def __init__(self, components, top_n): | 21 def __init__(self, components, top_n): |
| 21 """Build a classifier for components. | 22 """Build a classifier for components. |
| 22 | 23 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 top_n: number of components assigned to this change log, default is 2 | 107 top_n: number of components assigned to this change log, default is 2 |
| 107 | 108 |
| 108 Returns: | 109 Returns: |
| 109 List of components | 110 List of components |
| 110 """ | 111 """ |
| 111 if not change_log: | 112 if not change_log: |
| 112 return None | 113 return None |
| 113 | 114 |
| 114 classes = map(self.GetClassFromFileChangeInfo, change_log.touched_files) | 115 classes = map(self.GetClassFromFileChangeInfo, change_log.touched_files) |
| 115 return RankByOccurrence(classes, top_n, rank_function=lambda x:-len(x)) | 116 return RankByOccurrence(classes, top_n, rank_function=lambda x:-len(x)) |
| OLD | NEW |