Browse Source

Modif de la classe séquence et des scripts

l'utilisant
pull/5/head
Figg 9 months ago
parent
commit
8cb1003f42
3 changed files with 18 additions and 20 deletions
  1. 9
    15
      million/analyze/find_holes.py
  2. 8
    4
      million/model/sequence.py
  3. 1
    1
      scripts/find_holes.py

+ 9
- 15
million/analyze/find_holes.py View File

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

+ 8
- 4
million/model/sequence.py View File

1
 
1
 
2
-from typing import Optional
3
 from pydantic import BaseModel
2
 from pydantic import BaseModel
4
 
3
 
5
 from million.model.message import Message
4
 from million.model.message import Message
5
+import million.analyze.message_evaluation as msg_ev
6
 
6
 
7
 
7
 
8
 class Sequence(BaseModel):
8
 class Sequence(BaseModel):
9
-    start: int
10
     start_message: Message
9
     start_message: Message
11
-    end: int
12
-    end_message: Message
10
+    end_message: Message | None
11
+
12
+    def start(self) -> int:
13
+        return msg_ev.compute(self.start_message)
14
+    
15
+    def end(self) -> int:
16
+        return msg_ev.compute(self.end_message)

+ 1
- 1
scripts/find_holes.py View File

14
 
14
 
15
 sequences = compute_sequences(filtered)
15
 sequences = compute_sequences(filtered)
16
 
16
 
17
-actual_counted = sum([s.end - s.start for s in sequences])
17
+actual_counted = sum([s.end() - s.start() for s in sequences])
18
 
18
 
19
 print(f"Actual counted: {actual_counted}")
19
 print(f"Actual counted: {actual_counted}")
20
 
20
 

Loading…
Cancel
Save