diff --git a/cl/chronometrist.org b/cl/chronometrist.org index c1edc24..d2ee75b 100644 --- a/cl/chronometrist.org +++ b/cl/chronometrist.org @@ -410,8 +410,10 @@ Use =org-babel= (=org-babel-tangle= / =org-babel-tangle-file=), /not/ =literate- :*sexp-pretty-print-function* :*task-list* :*sqlite-properties-function* ;; classes - :backend :day :interval :event - :properties :date :intervals :events + :backend + :day :date :intervals :events :properties + :interval :name :interval-start :interval-stop + :event :event-time ;; protocol :*backends-alist* :active-backend :register-backend :backend-file @@ -678,13 +680,13 @@ treated as though their time is 00:00:00." *** task-time-one-day :reader: #+BEGIN_SRC lisp (defun task-time-one-day (task &optional - (date (date-ts)) + (date (today)) (backend (chronometrist-active-backend))) - "Return total time spent on TASK today or on DATE, an ISO-8601 date. + "Return total time spent on TASK today or on DATE. The return value is seconds, as an integer." - (let ((task-events (chronometrist-task-records-for-date backend task date))) - (if task-events - (->> (plists-to-durations task-events) + (let ((task-intervals (task-records-for-date backend task date))) + (if task-intervals + (->> (plists-to-durations task-intervals) (-reduce #'+) (truncate)) ;; no events for this task on DATE, i.e. no time spent @@ -980,12 +982,12 @@ return a list of tasks from the active backend." :type string :documentation "The name of the task executed during this interval.") (start :initarg :start - :accessor start + :accessor interval-start :type integer :documentation "The time at which this interval started, as an integer representing the UNIX epoch time.") (stop :initarg :stop - :accessor stop + :accessor interval-stop :type integer :documentation "The time at which this interval ended, as an integer representing the UNIX epoch time.")) @@ -2500,7 +2502,21 @@ s-expressions in a text column.") **** task-records-for-date #+BEGIN_SRC lisp (defmethod chronometrist:task-records-for-date - ((backend sqlite-backend) task date-ts &key &allow-other-keys)) + ((backend sqlite-backend) task date &key &allow-other-keys) + (execute-sxql #'execute-to-list + (select (:name :start_time :stop_time :properties) + (from :intervals) + (left-join :interval_names :using (:name_id)) + (left-join :properties :using (:prop_id)) + (where (:and + (:in :interval_id + (select (:interval_id) + (from :date_intervals) + (where (:= :date_id + (select (:date_id) + (from :dates) + (where (:= :date date))))))) + (:= :name task)))))) #+END_SRC **** active-days @@ -2570,7 +2586,7 @@ s-expressions in a text column.") (defun table-function (table-specification) (loop ;; for col-spec in *table-specification* ;; for (sym str) in *table-specification* - with date = () + with date = (today) for task in (chronometrist:task-list) for index from 1 collect (list index task)))