From d4dd016038eceda6140b2e946877ef6caf2bb22c Mon Sep 17 00:00:00 2001 From: contrapunctus Date: Wed, 12 Oct 2022 23:06:19 +0530 Subject: [PATCH] Record locations of walk/run tracks --- init.org | 74 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 25 deletions(-) diff --git a/init.org b/init.org index 3ce71ee..666df35 100644 --- a/init.org +++ b/init.org @@ -2417,31 +2417,55 @@ What if... (defun my-chronometrist-copy-exercise-data () "Add exercise data from OsmAnd tracks to Chronometrist." (interactive) - (if-let* ((date-iso (read-string "Date (ISO-8601): " (format-time-string "%F"))) - (date (parse-iso8601-time-string date-iso)) - (dir (concat "/media/data/phone/contrapunctus/Nokia 6.1/Android/data/net.osmand.plus/files/tracks/rec/" - (format-time-string "%+4Y-%m/" date))) - (dir-check (file-exists-p dir)) - (plists (cl-loop with activity - for file in (directory-files dir) - when (and (string-match-p (format-time-string "^%F_" date) - file) - (or (and (string-match-p "(walk)" file) - (setq activity :walking)) - (and (string-match-p "(run)" file) - (setq activity :running)))) - collect - (with-current-buffer - (get-buffer-create - (find-file-noselect (concat dir file))) - (append '(:name "Exercise") - `(,activity (,(floor (my-gpx-distance file)) . "meters")) - (my-get-gpx-timestamps)) - ;; (chronometrist-insert (chronometrist-active-backend)) - ))) - (string (mapconcat (lambda (plist) - (chronometrist-plist-pp plist)) - plists "\n"))) + ;; Date for which to get data + (if-let* + ((date-iso (read-string "Date (ISO-8601): " (format-time-string "%F"))) + (date (parse-iso8601-time-string date-iso)) + (dir (concat + "/media/data/phone/contrapunctus/" + "Nokia 6.1/Android/data/net.osmand.plus/files/tracks/rec/" + (format-time-string "%+4Y-%m/" date))) + (dir-check (file-exists-p dir)) + (plists (cl-loop with activity + for file in (directory-files dir) + when (and (string-match-p (format-time-string "^%F_" date) + file) + (or (and (string-match-p "(walk)" file) + (setq activity :walking)) + (and (string-match-p "(run)" file) + (setq activity :running)))) + collect + (-let* ((file-name file) + ((from to) + (progn + (string-match + (rx (group (+? num) "-" (= 2 num) "-" (= 2 num) + "_" (= 2 num) "-" (= 2 num) + "_" (= 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) (message "Copied %s to kill ring" string)) (message "No suitable GPX files found")))