Bladeren bron

Modif de la classe séquence et des scripts

l'utilisant
pull/5/head
Figg 8 maanden geleden
bovenliggende
commit
8cb1003f42
3 gewijzigde bestanden met toevoegingen van 18 en 20 verwijderingen
  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 Bestand weergeven

@@ -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
             ))

+ 8
- 4
million/model/sequence.py Bestand weergeven

@@ -1,12 +1,16 @@
1 1
 
2
-from typing import Optional
3 2
 from pydantic import BaseModel
4 3
 
5 4
 from million.model.message import Message
5
+import million.analyze.message_evaluation as msg_ev
6 6
 
7 7
 
8 8
 class Sequence(BaseModel):
9
-    start: int
10 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 Bestand weergeven

@@ -14,7 +14,7 @@ filtered = retain_counts(export.messages)
14 14
 
15 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 19
 print(f"Actual counted: {actual_counted}")
20 20
 

Laden…
Annuleren
Opslaan