-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfail_cluster.py
More file actions
42 lines (29 loc) · 855 Bytes
/
fail_cluster.py
File metadata and controls
42 lines (29 loc) · 855 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import hashlib
import re
class FailureCluster:
def __init__(self):
self.clusters = {}
def _norm(self, e):
if not e:
return "no_error"
e = e.lower()
e = re.sub(r"\d+", "NUM", e)
return e
def signature(self, e):
return hashlib.md5(self._norm(e).encode()).hexdigest()[:12]
def assign(self, e):
sig = self.signature(e)
for cid, c in self.clusters.items():
if sig in c["members"]:
return cid
self.clusters[sig] = {
"prototype": self._norm(e),
"members": {sig}
}
return sig
def similar(self, e):
sig = self.signature(e)
for cid, c in self.clusters.items():
if sig in c["members"]:
return cid, c["members"]
return None, set()