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

Side by Side Diff: appengine/findit/crash/crash_util.py

Issue 1861373003: [Findit] Initial code of findit for crash. Add scorers to apply heuristic rules. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Address comments. Created 4 years, 8 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 collections import defaultdict
6
7
8 def IsSameFilePath(path1, path2):
Martin Barbella 2016/04/19 22:21:28 With the style change below, these look a bit awkw
Sharu Jiang 2016/04/20 18:54:24 Done.
9 """Determines if two paths represent same path.
10
11 Compares the name of the folders in the path (by split('/')), and checks
12 if they match either more than 3 or min of path lengths.
13
14 Args:
15 path1 (str): First path.
16 path2 (str): Second path to compare.
17
18 Returns:
19 Boolean, True if it they are thought to be a same path, False otherwise.
20 """
21 # TODO(katesonia): Think of better way to determine whether 2 paths are the
22 # same or not.
23 path_parts_1 = path1.lower().split('/')
24 path_parts_2 = path2.lower().split('/')
25
26 if path_parts_1[-1] != path_parts_2[-1]:
27 return False
28
29 def _GetPathPartsCount(path_parts):
30 path_parts_count = defaultdict(int)
31
32 for path_part in path_parts:
33 path_parts_count[path_part] += 1
34
35 return path_parts_count
36
37 parts_count_1 = _GetPathPartsCount(path_parts_1)
38 parts_count_2 = _GetPathPartsCount(path_parts_2)
39
40 total_same_parts = sum([min(parts_count_1[part], parts_count_2[part]) for
Martin Barbella 2016/04/19 22:21:28 This is complicated enough that it warrants a comm
Sharu Jiang 2016/04/20 18:54:24 Done.
41 part in parts_count_1 if part in path_parts_2])
42
43 return total_same_parts >= (min(3, min(len(path_parts_1), len(path_parts_2))))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698