Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

message_evaluation.py 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import re
  2. from typing import Dict
  3. from million.model.message import Message
  4. import million.analyze.dns_solver as dns
  5. _memoization: Dict[Message, int] = {}
  6. _dns_solver: dns.DNS_solver = dns.DNS_solver()
  7. def get(msg: Message) -> int:
  8. """
  9. Returns the estimated value counted in this message
  10. """
  11. return _memoization.get(msg, _compute(msg))
  12. def reset(msg: Message) -> None:
  13. """
  14. Drop memorized value of this Message
  15. """
  16. if msg in _memoization:
  17. _memoization.pop(msg)
  18. def reset() -> None:
  19. """
  20. Drop every memorized message value
  21. """
  22. _memoization.clear()
  23. def _compute(msg: Message) -> int:
  24. value = _dns_solver.solve(msg) or _computeContent(msg) or None
  25. _memoization[msg] = value
  26. return value
  27. # 1🍁 pour 1420 ?
  28. # @Elias Cheddar pour 69 ?
  29. def _computeContent(msg: Message) -> int:
  30. if not msg.content:
  31. return
  32. s = re.sub(r'[^\s\d.,]|[.,]{2,}',"", msg.content)
  33. match = re.search(r"\d+", s)
  34. if match:
  35. return int(match.group())
  36. return None