process-locations.lisp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. (defun doc->point (doc)
  2. (geo:point-deg
  3. (/ (get-element "latitudeE7" doc) 1d7)
  4. (/ (get-element "longitudeE7" doc) 1d7)))
  5. (defun doc->ts (doc)
  6. (local-time:unix-to-timestamp
  7. (floor (get-element "timestampMs" doc) 1000)))
  8. (defun day-kv (date)
  9. (let* ((ts (local-time:parse-timestring date))
  10. (nd (local-time:timestamp+ ts 1 :day)))
  11. ($between "timestampMs"
  12. (* 1000 (local-time:timestamp-to-unix ts))
  13. (* 1000 (local-time:timestamp-to-unix nd)))))
  14. (defun extract-places (docs)
  15. (loop
  16. for doc in docs
  17. for point = (doc->point doc)
  18. with last-place and moved and need-add
  19. when last-place do (setf moved
  20. (geo:distance>=
  21. (geo:distance-between
  22. point
  23. (doc->point last-place))
  24. (geo:distance-meters 200)))
  25. when moved do (setf last-place doc
  26. need-add t)
  27. when (and need-add
  28. (> (local-time:timestamp-difference
  29. (doc->ts doc)
  30. (doc->ts last-place))
  31. 400))
  32. collect (cons (doc->ts last-place) (doc->point last-place))
  33. and do (setf need-add nil)
  34. when (not last-place) do (setf last-place doc)
  35. ))