diff --git a/elisp/chronometrist.el b/elisp/chronometrist.el index 161f916..80bc64c 100644 --- a/elisp/chronometrist.el +++ b/elisp/chronometrist.el @@ -368,12 +368,12 @@ treated as though their time is 00:00:00." (cl-defun chronometrist-task-time-one-day (task &optional (date (chronometrist-date-ts)) (backend (chronometrist-active-backend))) "Return total time spent on TASK today or on DATE, an ISO-8601 date. The return value is seconds, as an integer." - (let ((task-events (chronometrist-task-records-for-date backend task date))) - (if task-events - (->> (chronometrist-plists-to-durations task-events) + (let ((task-intervals (chronometrist-task-records-for-date backend task date))) + (if task-intervals + (->> (chronometrist-plists-to-durations task-intervals) (-reduce #'+) (truncate)) - ;; no events for this task on DATE, i.e. no time spent + ;; no intervals for this task on DATE, i.e. no time spent 0))) ;; task-time-one-day:1 ends here @@ -388,16 +388,16 @@ Return value is seconds as an integer." ;; active-time-on:1 ends here ;; [[file:chronometrist.org::*count-active-days][count-active-days:1]] -(cl-defun chronometrist-statistics-count-active-days (task table) +(cl-defun chronometrist-count-active-days (task hash-table) "Return the number of days the user spent any time on TASK. - TABLE must be a hash table - if not supplied, `chronometrist-events' is used. +HASH-TABLE must be a hash table as returned by `chronometrist-to-hash-table'. - This will not return correct results if TABLE contains records -which span midnights." - (cl-loop for events being the hash-values of table +This will not return correct results if HASH-TABLE contains +records which span midnights." + (cl-loop for intervals being the hash-values of hash-table count (seq-find (lambda (event) (equal task (plist-get event :name))) - events))) + intervals))) ;; count-active-days:1 ends here ;; [[file:chronometrist.org::*task-list][task-list:1]] @@ -428,14 +428,14 @@ PLIST-GROUP must be a tagged list as returned by ;; record-properties:1 ends here ;; [[file:chronometrist.org::*record-intervals][record-intervals:1]] -(defun chronometrist-record-intervals (plist-group) - "Return plists from PLIST-GROUP. -PLIST-GROUP must be a tagged list as returned by +(defun chronometrist-record-intervals (record) + "Return intervals (as a list of plists) from RECORD. +RECORD must be a tagged plist as returned by `chronometrist-latest-record'." - (cl-loop for elt being the elements of plist-group + (cl-loop for elt being the elements of record using (index i) when (chronometrist-plist-p elt) - return (seq-drop plist-group i))) + return (seq-drop record i))) ;; record-intervals:1 ends here ;; [[file:chronometrist.org::*iso-to-ts][iso-to-ts:1]] @@ -479,9 +479,6 @@ TS should be a ts struct (see `ts.el')." Optional argument UNIX-TIME should be a time value (see `current-time') accepted by `format-time-string'." (format-time-string "%FT%T%z" unix-time)) - -;; Note - this assumes that an event never crosses >1 day. This seems -;; sufficient for all conceivable cases. ;; format-time-iso8601:1 ends here ;; [[file:chronometrist.org::*split-time][split-time:1]] @@ -498,13 +495,13 @@ Return a list in the form (:start :stop STOP-TIME))" ;; FIXME - time zones are ignored; may cause issues with - ;; time-zone-spanning events + ;; time-zone-spanning intervals ;; The time on which the first provided day starts (according to `chronometrist-day-start-time') (let* ((stop-ts (chronometrist-iso-to-ts stop-time)) (first-day-start (chronometrist-apply-time day-start-time start-time)) (next-day-start (ts-adjust 'hour 24 first-day-start))) - ;; Does the event stop time exceed the next day start time? + ;; Does the interval stop time exceed the next day start time? (when (ts< next-day-start stop-ts) (let ((split-time (ts-format "%FT%T%z" next-day-start))) (list `(:start ,start-time :stop ,split-time) @@ -524,8 +521,8 @@ SECONDS must be a positive integer." ;; [[file:chronometrist.org::*interval][interval:1]] (defun chronometrist-interval (plist) - "Return the period of time covered by EVENT as a time value. -EVENT should be a plist (see `chronometrist-file')." + "Return the period of time covered by PLIST as a time value. +PLIST should be a plist (see `chronometrist-file')." (let* ((start-ts (chronometrist-iso-to-ts (plist-get plist :start))) (stop-iso (plist-get plist :stop)) ;; Add a stop time if it does not exist. @@ -1020,7 +1017,8 @@ across days.") ;; [[file:chronometrist.org::*to-list][to-list:1]] (cl-defgeneric chronometrist-to-list (backend) - "Return all records in BACKEND as a list of plists.") + "Return all intervals in BACKEND as a list of plists. +The resulting list does not contain record key-values.") ;; to-list:1 ends here ;; [[file:chronometrist.org::*memory-layer-empty-p][memory-layer-empty-p:1]] @@ -1770,8 +1768,8 @@ Return value is either a list in the form ;; [[file:chronometrist.org::*to-list][to-list:1]] (cl-defmethod chronometrist-to-list ((backend chronometrist-plist-group-backend)) (chronometrist-backend-run-assertions backend) - (chronometrist-loop-sexp-file for expr in (chronometrist-backend-file backend) - append (reverse (cl-rest expr)))) + (chronometrist-loop-sexp-file for record in (chronometrist-backend-file backend) + append (chronometrist-record-intervals record))) ;; to-list:1 ends here ;; [[file:chronometrist.org::*to-hash-table][to-hash-table:1]] @@ -2976,7 +2974,7 @@ It simply operates on the entire hash table TABLE (see reduced to the desired range using `chronometrist-ht-subset'." (cl-loop for task in (chronometrist-task-list) collect - (let* ((active-days (chronometrist-statistics-count-active-days task table)) + (let* ((active-days (chronometrist-count-active-days task table)) (active-percent (cl-case (plist-get chronometrist-statistics--ui-state :mode) ('week (* 100 (/ active-days 7.0))))) (active-percent (if (zerop active-days) diff --git a/elisp/chronometrist.org b/elisp/chronometrist.org index d630b44..ebc7d4b 100644 --- a/elisp/chronometrist.org +++ b/elisp/chronometrist.org @@ -959,14 +959,14 @@ PLIST-GROUP must be a tagged list as returned by *** record-intervals :function: #+BEGIN_SRC elisp -(defun chronometrist-record-intervals (plist-group) - "Return plists from PLIST-GROUP. -PLIST-GROUP must be a tagged list as returned by +(defun chronometrist-record-intervals (record) + "Return intervals (as a list of plists) from RECORD. +RECORD must be a tagged plist as returned by `chronometrist-latest-record'." - (cl-loop for elt being the elements of plist-group + (cl-loop for elt being the elements of record using (index i) when (chronometrist-plist-p elt) - return (seq-drop plist-group i))) + return (seq-drop record i))) #+END_SRC ** Time functions @@ -1701,7 +1701,8 @@ across days.") ***** to-list :generic:function: #+BEGIN_SRC emacs-lisp (cl-defgeneric chronometrist-to-list (backend) - "Return all records in BACKEND as a list of plists.") + "Return all intervals in BACKEND as a list of plists. +The resulting list does not contain record key-values.") #+END_SRC ***** memory-layer-empty-p :generic:function: @@ -2763,8 +2764,8 @@ Return value is either a list in the form #+BEGIN_SRC emacs-lisp (cl-defmethod chronometrist-to-list ((backend chronometrist-plist-group-backend)) (chronometrist-backend-run-assertions backend) - (chronometrist-loop-sexp-file for expr in (chronometrist-backend-file backend) - append (reverse (cl-rest expr)))) + (chronometrist-loop-sexp-file for record in (chronometrist-backend-file backend) + append (chronometrist-record-intervals record))) #+END_SRC **** to-hash-table :reader:method: