You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

find_holes.py 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. from typing import List
  2. from million.model.message import Message
  3. from million.model.sequence import Sequence
  4. import million.analyze.message_evaluation as msg_val
  5. def compute_sequences(messages: List[Message], accepted_max: int = 1_000_000) -> List[Sequence]:
  6. sequences: List[Sequence] = []
  7. current = Sequence(start_message=messages[0])
  8. for message in messages[1:]:
  9. if msg_val.get(message) > accepted_max: continue
  10. if msg_val.get(message) == current.end() + 1:
  11. current.end_message = message
  12. else:
  13. sequences.append(current)
  14. current = Sequence(start_message=message)
  15. sequences.sort(key=lambda s: s.start())
  16. merged_sequences: List[Sequence] = []
  17. previous = sequences[0]
  18. for sequence in sequences[1:]:
  19. if previous.overlaps(sequence):
  20. previous.merge(sequence)
  21. else:
  22. merged_sequences.append(previous)
  23. previous = sequence
  24. return [s for s in merged_sequences if s.length() > 1]
  25. def find_holes(messages: List[Message], accepted_max: int = 1_000_000) -> List[Sequence]:
  26. """
  27. Find the holes in the conversation
  28. """
  29. sequences = compute_sequences(messages, accepted_max)
  30. holes = []
  31. for previous, current in zip(sequences[:-1],sequences[1:]):
  32. holes.append(Sequence(
  33. start_message=previous.end_message,
  34. end_message=current.start_message
  35. ))
  36. return holes