|
@@ -10,9 +10,7 @@ import million.analyze.message_evaluation as msg_ev
|
10
|
10
|
def compute_sequences(messages: List[Message], accepted_max: int = 1_000_000) -> List[Sequence]:
|
11
|
11
|
sequences: List[Sequence] = []
|
12
|
12
|
current_sequence = Sequence(
|
13
|
|
- start = msg_ev.compute(messages[0]),
|
14
|
13
|
start_message=messages[0],
|
15
|
|
- end = msg_ev.compute(messages[0]),
|
16
|
14
|
end_message=messages[0]
|
17
|
15
|
)
|
18
|
16
|
for i in range(1, len(messages)):
|
|
@@ -20,39 +18,35 @@ def compute_sequences(messages: List[Message], accepted_max: int = 1_000_000) ->
|
20
|
18
|
message_value = msg_ev.compute(message)
|
21
|
19
|
if message_value > accepted_max:
|
22
|
20
|
continue
|
23
|
|
- if message_value - current_sequence.end == 1:
|
24
|
|
- current_sequence.end = message_value
|
|
21
|
+ if message_value - current_sequence.end() == 1:
|
25
|
22
|
current_sequence.end_message = message
|
26
|
23
|
else:
|
27
|
24
|
sequences.append(current_sequence)
|
28
|
25
|
current_sequence = Sequence(
|
29
|
|
- start=message_value,
|
30
|
26
|
start_message=message,
|
31
|
|
- end=message_value,
|
32
|
27
|
end_message=message
|
33
|
28
|
)
|
34
|
29
|
|
35
|
30
|
# order the sequences by start
|
36
|
|
- sequences.sort(key=lambda s: s.start)
|
|
31
|
+ sequences.sort(key=lambda s: s.start())
|
37
|
32
|
|
38
|
33
|
merged_sequences: List[Sequence] = []
|
39
|
34
|
current_sequence = sequences[0]
|
40
|
35
|
for i in range(1, len(sequences)):
|
41
|
36
|
sequence = sequences[i]
|
42
|
|
- sequence_start_is_in_current_sequence = current_sequence.start <= sequence.start and current_sequence.end >= sequence.start
|
43
|
|
- sequence_end_is_further = sequence.end > current_sequence.end
|
44
|
|
- sequence_start_is_current_end_or_next = sequence.start == current_sequence.end + 1
|
|
37
|
+ sequence_start_is_in_current_sequence = current_sequence.start() <= sequence.start() and current_sequence.end() >= sequence.start()
|
|
38
|
+ sequence_end_is_further = sequence.end() > current_sequence.end()
|
|
39
|
+ sequence_start_is_current_end_or_next = sequence.start() == current_sequence.end() + 1
|
45
|
40
|
|
46
|
41
|
if sequence_start_is_in_current_sequence or sequence_start_is_current_end_or_next:
|
47
|
42
|
if sequence_end_is_further:
|
48
|
|
- current_sequence.end = sequence.end
|
49
|
43
|
current_sequence.end_message = sequence.end_message
|
50
|
44
|
else:
|
51
|
45
|
merged_sequences.append(current_sequence)
|
52
|
46
|
current_sequence = sequence
|
53
|
47
|
|
54
|
48
|
# Having merged the sequences once, any sequence having start = end can be removed
|
55
|
|
- return [s for s in merged_sequences if s.start != s.end]
|
|
49
|
+ return [s for s in merged_sequences if s.start() != s.end()]
|
56
|
50
|
|
57
|
51
|
|
58
|
52
|
def find_holes(messages: List[Message], accepted_max: int = 1_000_000) -> List[Hole]:
|
|
@@ -64,10 +58,10 @@ def find_holes(messages: List[Message], accepted_max: int = 1_000_000) -> List[H
|
64
|
58
|
for i in range(1, len(merged_sequences)):
|
65
|
59
|
previous_sequence = merged_sequences[i - 1]
|
66
|
60
|
sequence = merged_sequences[i]
|
67
|
|
- if sequence.start - previous_sequence.end > 1:
|
|
61
|
+ if sequence.start() - previous_sequence.end() > 1:
|
68
|
62
|
holes.append(Hole(
|
69
|
|
- start=previous_sequence.end,
|
70
|
|
- end=sequence.start,
|
|
63
|
+ start=previous_sequence.end(),
|
|
64
|
+ end=sequence.start(),
|
71
|
65
|
start_message=previous_sequence.end_message,
|
72
|
66
|
end_message=sequence.start_message
|
73
|
67
|
))
|