Browse Source

Ajout de commentaires

pull/5/head
Figg 8 months ago
parent
commit
6600ccb799
3 changed files with 30 additions and 1 deletions
  1. 13
    0
      million/analyze/find_holes.py
  2. 2
    1
      million/analyze/message_evaluation.py
  3. 15
    0
      million/parse/fb_exports.py

+ 13
- 0
million/analyze/find_holes.py View File

@@ -7,6 +7,10 @@ import million.analyze.message_evaluation as msg_val
7 7
 
8 8
 
9 9
 def compute_sequences(messages: List[Message], accepted_max: int = 1_000_000) -> List[Sequence]:
10
+    """ 
11
+    Takes a list of messages as input and returns a list of sequences
12
+    for every following messages with following 'counted values'
13
+    """
10 14
     sequences: List[Sequence] = [Sequence(start_message=messages[0])]
11 15
     
12 16
     for message in messages[1:]:
@@ -21,6 +25,10 @@ def compute_sequences(messages: List[Message], accepted_max: int = 1_000_000) ->
21 25
 
22 26
 
23 27
 def merge_duplicates(sequences: List[Sequence]) -> List[Sequence]:
28
+    """ 
29
+    Take sequences as an input and returns a list with every
30
+    overlapping input sequences merged in one
31
+    """
24 32
     o_sequences = sorted(sequences, key= lambda s : s.start())
25 33
     current = o_sequences[0]
26 34
 
@@ -38,6 +46,10 @@ def merge_duplicates(sequences: List[Sequence]) -> List[Sequence]:
38 46
 
39 47
 
40 48
 def invert_sequences(sequences: List[Sequence]) -> List[Sequence]:
49
+    """ 
50
+    Returns the sequences representing the spaces between
51
+    the ones given as input
52
+    """
41 53
     result = []
42 54
 
43 55
     for previous, current in zip(sequences[:-1],sequences[1:]):
@@ -51,6 +63,7 @@ def invert_sequences(sequences: List[Sequence]) -> List[Sequence]:
51 63
 def find_holes(messages: List[Message], accepted_max: int = 1_000_000) -> List[Sequence]:
52 64
     """
53 65
     Find the holes in the conversation
66
+    TODO might need to be moved inside scripts/find_holes
54 67
     """
55 68
     sequences = compute_sequences(messages, accepted_max)
56 69
     merged = merge_duplicates(sequences)

+ 2
- 1
million/analyze/message_evaluation.py View File

@@ -21,6 +21,7 @@ def __compute__(msg: Message) -> int:
21 21
     return value
22 22
 
23 23
 def get(msg: Message) -> int:
24
-    """ Returns the estimated value counted in this message
24
+    """
25
+    Returns the estimated value counted in this message
25 26
     """
26 27
     return memoization.get(msg, __compute__(msg))

+ 15
- 0
million/parse/fb_exports.py View File

@@ -6,16 +6,27 @@ from million.model.fb_export import FacebookExport
6 6
 
7 7
 
8 8
 def is_file_valid(file_name: str) -> bool:
9
+    """ 
10
+    Check if this file can be parsed into a FacebookExport
11
+    (Actually only check if its a json file atm)
12
+    """
9 13
     # NOTE is there a way to peek inside a json file to
10 14
     # check its internal structure ?
11 15
     return os.path.splitext(file_name)[-1].lower() == '.json'
12 16
 
13 17
 def valid_dirfiles(file_dir: str) -> List[str]:
18
+    """ 
19
+    Returns a list of parsable files contained
20
+    in this directory
21
+    """
14 22
     return [os.path.join(file_dir, file_name)
15 23
             for file_name in os.listdir(file_dir)
16 24
             if is_file_valid(file_name)]
17 25
 
18 26
 def parse_file(file_name: str) -> FacebookExport:
27
+    """ 
28
+    Parses a single parsable file into a FacebookExport Object
29
+    """
19 30
     if not is_file_valid(file_name): return None
20 31
 
21 32
     with open(file_name, 'rb') as f:
@@ -23,6 +34,10 @@ def parse_file(file_name: str) -> FacebookExport:
23 34
         return FacebookExport.model_validate_json(json_data)
24 35
 
25 36
 def parse_dirfiles(file_dir: str) -> FacebookExport:
37
+    """ 
38
+    Parses every parsable files inside this directory
39
+    into a single FacebookExport Object
40
+    """
26 41
     exports = [parse_file(f) for f in valid_dirfiles(file_dir)]
27 42
     
28 43
     result = exports[0]

Loading…
Cancel
Save