Browse Source

on change l'évaluation du comptage pour passer

les tests
pull/5/head
Figg 9 months ago
parent
commit
57b215f22c
1 changed files with 20 additions and 9 deletions
  1. 20
    9
      million/analyze/message_evaluation.py

+ 20
- 9
million/analyze/message_evaluation.py View File

1
 from math import floor
1
 from math import floor
2
+import re
2
 from typing import Dict
3
 from typing import Dict
3
 from million.model.message import Message
4
 from million.model.message import Message
4
 
5
 
7
 # TODO WIP
8
 # TODO WIP
8
 # - DNS to resolve audio, gif, pictures with counts
9
 # - DNS to resolve audio, gif, pictures with counts
9
 def __compute__(msg: Message) -> int:
10
 def __compute__(msg: Message) -> int:
10
-    value = None
11
-    # Remove any number that is not a digit
11
+    value = __computeContent(msg)
12
+
13
+    memoization[msg] = value
14
+    return value
15
+
16
+def __computeContent(msg: Message) -> int:
12
     # TODO parse potential math expressions in content
17
     # TODO parse potential math expressions in content
13
-    cleaned_content = ''.join([c for c in msg.content if c.isdigit()])
14
-    try:
15
-        value = floor(float(cleaned_content))
16
-    except Exception as e:
17
-        raise ValueError(
18
-            f"Message {cleaned_content} does not contain a number ({e})")
18
+    match = re.search(r"\d+", msg.content)
19
+    
20
+    if match:
21
+        value = int(match[0])
22
+    else:
23
+        value = None
19
     
24
     
20
-    memoization[msg] = value
21
     return value
25
     return value
22
 
26
 
27
+def reset(msg: Message) -> None:
28
+    if msg in memoization:
29
+        memoization.pop(msg)
30
+
31
+def reset() -> None:
32
+    memoization.clear()
33
+
23
 def get(msg: Message) -> int:
34
 def get(msg: Message) -> int:
24
     """
35
     """
25
     Returns the estimated value counted in this message
36
     Returns the estimated value counted in this message

Loading…
Cancel
Save