recog.py 917 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import data
  2. def list_have_location(l):
  3. for d in l:
  4. if not data.have_location(d):
  5. return False
  6. return True
  7. def list_have_continue_maybe_indoor(l):
  8. last_indoor = False
  9. for d in l:
  10. indoor = data.maybe_indoor(d)
  11. if indoor and last_indoor:
  12. return True
  13. last_indoor = indoor
  14. return False
  15. def check_entry(before, curr, after):
  16. if not list_have_location(before):
  17. return None
  18. if not data.have_location(curr):
  19. return None
  20. if not data.maybe_entry(curr):
  21. return None
  22. if data.maybe_entry(before[-1]):
  23. return None
  24. if not list_have_continue_maybe_indoor(after):
  25. return None
  26. return before[-1]
  27. def recognize_entries(l):
  28. ret = []
  29. for i in range(60, len(l) - 12):
  30. x = check_entry(l[i-60:i], l[i], l[i+1:i+13])
  31. if not x is None:
  32. ret.append(x)
  33. return ret