recog.py 911 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 recognize_entries(l):
  17. print(l)
  18. ret = []
  19. j = 0
  20. for i in range(len(l)):
  21. while j < len(l) and l[j].timestamp - l[i].timestamp < 60:
  22. j += 1
  23. if j - i < 12:
  24. continue
  25. if count_have_location(l[i:j]) < j - i:
  26. continue
  27. if j >= len(l) or not data.maybe_entry(l[j]):
  28. continue
  29. if data.maybe_entry(l[j-1]):
  30. continue
  31. if not list_have_continue_maybe_indoor(l[j+1:j+13]):
  32. continue
  33. ret.append(l[j-1])
  34. return ret