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

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: Fix nits. 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(path_1, path_2):
stgao 2016/04/21 17:31:54 Probably, we could start with a simple strict equa
Sharu Jiang 2016/04/21 22:38:50 I prefer leave this as it is now, let's experiment
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 path_1 (str): First path.
16 path_2 (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 = path_1.lower().split('/')
24 path_parts_2 = path_2.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 # Get number of same path parts between path_1 and path_2. For example:
41 # a/b/b/b/f.cc and a/b/b/c/d/f.cc have 4 path parts the same in total.
42 total_same_parts = sum([min(parts_count_1[part], parts_count_2[part]) for
43 part in parts_count_1 if part in path_parts_2])
44
45 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