浏览代码

Algo alternatif pour trouver les oublis

Squelette de l'algo
feature/findHolesV2
Figg 8 个月前
父节点
当前提交
6e6e958a73
共有 2 个文件被更改,包括 46 次插入0 次删除
  1. 30
    0
      million/analyze/find_holes.py
  2. 16
    0
      scripts/find_holesV2.py

+ 30
- 0
million/analyze/find_holes.py 查看文件

@@ -71,3 +71,33 @@ def find_holes(messages: List[Message], accepted_max: int = 1_000_000) -> List[H
71 71
                 end_message=sequence.start_message
72 72
             ))
73 73
     return holes
74
+
75
+def find_holesV2(messages: List[Message]) -> List[Hole]:
76
+    current = 1
77
+    msg_idx = 0
78
+    threshold = 1000
79
+
80
+    result = []
81
+
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
88
+
89
+            messages.remove(msgCurrent)
90
+            current += 1
91
+        else:
92
+            if len(result) == 0 or result[-1].end > 0:
93
+                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)
98
+                    )
99
+                result.append(hole)
100
+            elif current - result[-1].start > threshold:
101
+                break
102
+            
103
+    return result

+ 16
- 0
scripts/find_holesV2.py 查看文件

@@ -0,0 +1,16 @@
1
+from million.analyze.find_holes import find_holesV2
2
+from million.analyze.retain_counts import retain_counts
3
+from million.parse.fb_exports import FacebookExportParser
4
+
5
+
6
+DATA_PATH = './data/'
7
+parser = FacebookExportParser()
8
+
9
+export = parser.parse(DATA_PATH)
10
+filtered = retain_counts(export.messages)
11
+
12
+holes = find_holesV2(filtered)
13
+
14
+for hole in holes:
15
+    print(f"{hole.start} - {hole.end} ({hole.end - hole.start})")
16
+    print(hole.end_message)

正在加载...
取消
保存