Bladeren bron

c'est la v2 de la v2

et c'est toujours pas au point
feature/findHolesV2
Figg 8 maanden geleden
bovenliggende
commit
b4ceb4278b
1 gewijzigde bestanden met toevoegingen van 39 en 19 verwijderingen
  1. 39
    19
      million/analyze/find_holes.py

+ 39
- 19
million/analyze/find_holes.py Bestand weergeven

@@ -76,28 +76,48 @@ def find_holesV2(messages: List[Message]) -> List[Hole]:
76 76
     current = 1
77 77
     msg_idx = 0
78 78
     threshold = 1000
79
+    limitAhead = 100
80
+    limitBehind = 20
79 81
 
80
-    result = []
82
+    holes = []
83
+
84
+    while msg_idx < len(messages):
85
+        #search value current in messages from msgIdx, with lookahead then lookbehind
86
+        
87
+        for i in range(0, limitAhead):
88
+            msgCurrent = messages[msg_idx + i]
89
+            
90
+            if msgCurrent.get_counted_value() == current: break
81 91
 
82
-    while True:
83
-        msgCurrent = next((m for m in messages if m.get_counted_value() == current), None)
84
-        if msgCurrent:
85
-            if len(result) > 0 and result[-1].end < 1:
86
-                result[-1].end = current-1
87
-                result[-1].end_message = msgCurrent
92
+        if msgCurrent.get_counted_value() != current:
93
+            for i in range(1, limitBehind):
94
+                msgCurrent = messages[msg_idx - i]
95
+            
96
+                if msgCurrent.get_counted_value() == current: break
88 97
 
89
-            messages.remove(msgCurrent)
90
-            current += 1
98
+        if msgCurrent.get_counted_value() == current:
99
+            # la valeur current a été trouvé dans la zone de recherche
100
+            print(f"{msgCurrent.sender_name} : {msgCurrent.content}")
101
+            # si un trou était ouvert il faut le fermer
102
+            if len(holes) > 0 and holes[-1].end == 0:
103
+                holes[-1].end = current-1
104
+                holes[-1].end_message = msgCurrent
105
+                print(f"\t{current-1}")
106
+            msg_idx += 1
91 107
         else:
92
-            if len(result) == 0 or result[-1].end > 0:
108
+            # la valeur current n'a pas été trouvée
109
+            # on est dans un trou
110
+            # si aucun trou n'est ouvert, on en crée un
111
+            if len(holes) == 0 or holes[-1].end > 0:
93 112
                 hole = Hole(
94
-                    start = current,
95
-                    end = 0,
96
-                    start_message = Message(sender_name='',timestamp_ms=0),
97
-                    end_message = Message(sender_name='',timestamp_ms=0)
113
+                    start=current,
114
+                    end=0,
115
+                    start_message=messages[msg_idx],
116
+                    end_message=Message(sender_name='',timestamp_ms=0)
98 117
                     )
99
-                result.append(hole)
100
-            elif current - result[-1].start > threshold:
101
-                break
102
-            
103
-    return result
118
+                holes.append(hole)
119
+                print(f"\t HOLE : {hole.start}\n\t\t...")
120
+
121
+        current += 1
122
+    
123
+    return holes

Laden…
Annuleren
Opslaan