get working

mike/faster-chat-merge
Mike Lang 3 weeks ago
parent 335e29e1bc
commit 3ad24f5aec

@ -81,8 +81,13 @@ def merge_messages(left, right):
return result return result
def load(file):
with open(file) as f:
return [json.loads(line) for line in f.read().strip().split("\n")]
def main(*files): def main(*files):
batches = [json.load(open(file)) for file in files] batches = [load(file) for file in files]
result = batches[0] result = batches[0]
start = time.monotonic() start = time.monotonic()
for batch in batches[1:]: for batch in batches[1:]:

@ -50,7 +50,7 @@ def merge_messages(left, right):
message, candidates = right.pop(0), left message, candidates = right.pop(0), left
# Scan candidates for matching message until found or we know there is no match # Scan candidates for matching message until found or we know there is no match
id = message.get("tags", {}).get("id") id = (message.get("tags") or {}).get("id")
end = message['time'] + message['time_range'] end = message['time'] + message['time_range']
merged = None merged = None
for index, candidate in enumerate(candidates): for index, candidate in enumerate(candidates):
@ -62,7 +62,7 @@ def merge_messages(left, right):
if merged is not None: if merged is not None:
candidates.pop(index) candidates.pop(index)
break break
elif candidate.get("tags", {}).get("id") == id: elif (candidate.get("tags") or {}).get("id") == id:
merged = merge_message(message, candidate) merged = merge_message(message, candidate)
if merged is None: if merged is None:
raise ValueError("TODO") raise ValueError("TODO")
@ -82,8 +82,13 @@ def merge_messages(left, right):
return result return result
def load(file):
with open(file) as f:
return [json.loads(line) for line in f.read().strip().split("\n")]
def main(*files): def main(*files):
batches = [json.load(open(file)) for file in files] batches = [load(file) for file in files]
result = batches[0] result = batches[0]
start = time.monotonic() start = time.monotonic()
for batch in batches[1:]: for batch in batches[1:]:

Loading…
Cancel
Save