recog.py 922 B

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