Skip to content

Commit

Permalink
graph_builder: better stats
Browse files Browse the repository at this point in the history
Signed-off-by: Mihai Bivol <mm.bivol@gmail.com>
  • Loading branch information
mihaibivol committed May 9, 2016
1 parent dff5488 commit 00701c4
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions json_merger/graph_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __init__(self, lst, root):
self.in_result_idx = set()
self.not_in_result_idx = set(range(len(lst)))
self.not_in_result_root_match_idx = set()
self.matched_root_idx_pairs = set()
self.root_matches = {}

def move_to_result(self, lst_idx):
self.in_result_idx.add(lst_idx)
Expand All @@ -69,7 +69,7 @@ def move_to_result(self, lst_idx):
self.not_in_result_root_match_idx.remove(lst_idx)

def add_root_match(self, lst_idx, root_idx):
self.matched_root_idx_pairs.add((lst_idx, root_idx))
self.root_matches[lst_idx] = root_idx
if lst_idx in self.in_result_idx:
return
self.not_in_result_root_match_idx.add(lst_idx)
Expand All @@ -95,6 +95,17 @@ def not_in_result_root_match(self):
def not_in_result_not_root_match(self):
return [self.lst[e] for e in self.not_in_result_not_root_match_idx]

@property
def not_in_result_root_match_pairs(self):
return [(self.lst[e], self.root[self.root_matches[e]])
for e in self.not_in_result_root_match_idx]

@property
def not_matched_root_objects(self):
matched_root_idx = set(self.root_matches.values())
return [o for idx, o in enumerate(self.root)
if idx not in matched_root_idx]


class ListMatchGraphBuilder(object):

Expand Down Expand Up @@ -187,12 +198,12 @@ def _build_stats(self):
if update_idx >= 0:
self.update_stats.move_to_result(update_idx)

for idx in self.head_stats.not_in_result_idx:
for idx in xrange(len(self.head)):
root_idx, root = self._get_match('root', 'head', idx)
if root_idx >= 0:
self.head_stats.add_root_match(idx, root_idx)

for idx in self.update_stats.not_in_result_idx:
for idx in range(len(self.update)):
root_idx, root = self._get_match('root', 'update', idx)
if root_idx >= 0:
self.update_stats.add_root_match(idx, root_idx)
Expand Down

0 comments on commit 00701c4

Please sign in to comment.