Record locations of walk/run tracks

This commit is contained in:
contrapunctus 2022-10-12 23:06:19 +05:30
parent bd2cef2768
commit d4dd016038
1 changed files with 49 additions and 25 deletions

View File

@ -2417,31 +2417,55 @@ What if...
(defun my-chronometrist-copy-exercise-data () (defun my-chronometrist-copy-exercise-data ()
"Add exercise data from OsmAnd tracks to Chronometrist." "Add exercise data from OsmAnd tracks to Chronometrist."
(interactive) (interactive)
(if-let* ((date-iso (read-string "Date (ISO-8601): " (format-time-string "%F"))) ;; Date for which to get data
(date (parse-iso8601-time-string date-iso)) (if-let*
(dir (concat "/media/data/phone/contrapunctus/Nokia 6.1/Android/data/net.osmand.plus/files/tracks/rec/" ((date-iso (read-string "Date (ISO-8601): " (format-time-string "%F")))
(format-time-string "%+4Y-%m/" date))) (date (parse-iso8601-time-string date-iso))
(dir-check (file-exists-p dir)) (dir (concat
(plists (cl-loop with activity "/media/data/phone/contrapunctus/"
for file in (directory-files dir) "Nokia 6.1/Android/data/net.osmand.plus/files/tracks/rec/"
when (and (string-match-p (format-time-string "^%F_" date) (format-time-string "%+4Y-%m/" date)))
file) (dir-check (file-exists-p dir))
(or (and (string-match-p "(walk)" file) (plists (cl-loop with activity
(setq activity :walking)) for file in (directory-files dir)
(and (string-match-p "(run)" file) when (and (string-match-p (format-time-string "^%F_" date)
(setq activity :running)))) file)
collect (or (and (string-match-p "(walk)" file)
(with-current-buffer (setq activity :walking))
(get-buffer-create (and (string-match-p "(run)" file)
(find-file-noselect (concat dir file))) (setq activity :running))))
(append '(:name "Exercise") collect
`(,activity (,(floor (my-gpx-distance file)) . "meters")) (-let* ((file-name file)
(my-get-gpx-timestamps)) ((from to)
;; (chronometrist-insert (chronometrist-active-backend)) (progn
))) (string-match
(string (mapconcat (lambda (plist) (rx (group (+? num) "-" (= 2 num) "-" (= 2 num)
(chronometrist-plist-pp plist)) "_" (= 2 num) "-" (= 2 num)
plists "\n"))) "_" (= 3 (any alpha)))
" "
(group "(" (or "walk" "run") ")")
" "
(group (+? (any printing)))
(group "\.gpx"))
file-name)
(split-string
(match-string 3 file-name) " - "))))
(with-current-buffer
(get-buffer-create
(find-file-noselect (concat dir file)))
(append '(:name "Exercise")
(list activity
(cons (floor (my-gpx-distance file))
"meters"))
(if to
(list :from from :to to)
(list :location from))
(my-get-gpx-timestamps))
;; (chronometrist-insert (chronometrist-active-backend))
))))
(string (mapconcat (lambda (plist)
(chronometrist-plist-pp plist))
plists "\n")))
(progn (kill-new string) (progn (kill-new string)
(message "Copied %s to kill ring" string)) (message "Copied %s to kill ring" string))
(message "No suitable GPX files found"))) (message "No suitable GPX files found")))