mirror of
https://github.com/MISP/misp-galaxy.git
synced 2024-11-29 18:27:19 +00:00
ref [cluster] remove duplicates
This commit is contained in:
parent
b85fd1538e
commit
5d24d645d3
1 changed files with 14 additions and 23 deletions
|
@ -12,10 +12,14 @@ class Cluster:
|
||||||
self.value = value
|
self.value = value
|
||||||
self.related_list = related_list
|
self.related_list = related_list
|
||||||
self.meta = meta
|
self.meta = meta
|
||||||
self.entry = ""
|
|
||||||
self.galaxy = galaxy
|
self.galaxy = galaxy
|
||||||
|
|
||||||
|
self.entry = ""
|
||||||
self.statistics = None
|
self.statistics = None
|
||||||
|
|
||||||
|
def __lt__(self, other):
|
||||||
|
return self.uuid < other.uuid
|
||||||
|
|
||||||
def set_statistics(self, statistics):
|
def set_statistics(self, statistics):
|
||||||
self.statistics = statistics
|
self.statistics = statistics
|
||||||
|
|
||||||
|
@ -156,32 +160,19 @@ class Cluster:
|
||||||
if empty_uuids > 0:
|
if empty_uuids > 0:
|
||||||
self.statistics.empty_uuids_dict[self.value] = empty_uuids
|
self.statistics.empty_uuids_dict[self.value] = empty_uuids
|
||||||
|
|
||||||
# Remove duplicates
|
return self._remove_duplicates(related_clusters)
|
||||||
to_remove = set()
|
|
||||||
|
def _remove_duplicates(self, related_clusters):
|
||||||
cluster_dict = {}
|
cluster_dict = {}
|
||||||
for cluster in related_clusters:
|
for cluster in related_clusters:
|
||||||
key1 = (cluster[0], cluster[1])
|
key = tuple(sorted((cluster[0], cluster[1])))
|
||||||
key2 = (cluster[1], cluster[0])
|
|
||||||
|
|
||||||
if key1 in cluster_dict:
|
|
||||||
if cluster_dict[key1][2] > cluster[2]:
|
|
||||||
to_remove.add(cluster_dict[key1])
|
|
||||||
cluster_dict[key1] = cluster
|
|
||||||
else:
|
|
||||||
to_remove.add(cluster)
|
|
||||||
|
|
||||||
elif key2 in cluster_dict:
|
|
||||||
if cluster_dict[key2][2] > cluster[2]:
|
|
||||||
to_remove.add(cluster_dict[key2])
|
|
||||||
cluster_dict[key2] = cluster
|
|
||||||
else:
|
|
||||||
to_remove.add(cluster)
|
|
||||||
|
|
||||||
|
if key in cluster_dict:
|
||||||
|
if cluster_dict[key][2] > cluster[2]:
|
||||||
|
cluster_dict[key] = cluster
|
||||||
else:
|
else:
|
||||||
cluster_dict[key1] = cluster
|
cluster_dict[key] = cluster
|
||||||
related_clusters = [
|
related_clusters = list(cluster_dict.values())
|
||||||
cluster for cluster in related_clusters if cluster not in to_remove
|
|
||||||
]
|
|
||||||
|
|
||||||
return related_clusters
|
return related_clusters
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue