Add chronometrist: to method names
This commit is contained in:
parent
0831ae82d5
commit
38e4997269
|
@ -427,10 +427,12 @@ Use =org-babel= (=org-babel-tangle= / =org-babel-tangle-file=), /not/ =literate-
|
|||
:view-backend :edit-backend
|
||||
:backend-empty-p :backend-modified-p
|
||||
:create-file :latest-date-records
|
||||
:backend-run-assertions
|
||||
:insert :remove-last :replace-last
|
||||
:on-change :on-add :on-modify :on-remove
|
||||
:latest-record :task-records-for-date
|
||||
:to-file :to-hash :to-list :list-tasks
|
||||
:active-days
|
||||
:to-file :to-hash-table :to-list :list-tasks
|
||||
:active-days :count-records
|
||||
:file-backend-mixin :elisp-sexp-backend
|
||||
;; helpers
|
||||
:make-hash-table-1 :split-plist :iso-to-date :plist-key-values
|
||||
|
@ -1316,7 +1318,7 @@ based on `*user-data-file*' and the BACKEND extension slot."
|
|||
|
||||
**** create-file :writer:method:
|
||||
#+BEGIN_SRC lisp
|
||||
(defmethod create-file ((backend elisp-sexp-backend) &optional file)
|
||||
(defmethod chronometrist:create-file ((backend elisp-sexp-backend) &optional file)
|
||||
(let ((file (or file (chronometrist:backend-file backend))))
|
||||
(unless (file-exists-p file)
|
||||
(with-current-buffer (find-file-noselect file)
|
||||
|
@ -1713,7 +1715,7 @@ Concerns specific to the plist group backend -
|
|||
|
||||
**** run-assertions :reader:method:
|
||||
#+BEGIN_SRC lisp
|
||||
(defmethod backend-run-assertions ((backend file-backend-mixin))
|
||||
(defmethod chronometrist:backend-run-assertions ((backend file-backend-mixin))
|
||||
(with-slots (file) backend
|
||||
(unless (file-exists-p file)
|
||||
(error "Backend file %S does not exist" file))))
|
||||
|
@ -1721,7 +1723,7 @@ Concerns specific to the plist group backend -
|
|||
|
||||
**** latest-date-records :reader:method:
|
||||
#+BEGIN_SRC lisp
|
||||
(defmethod latest-date-records ((backend plist-group-backend))
|
||||
(defmethod chronometrist:latest-date-records ((backend plist-group-backend))
|
||||
(backend-run-assertions backend)
|
||||
(sexp-in-file (chronometrist:backend-file backend)
|
||||
(goto-char (point-max))
|
||||
|
@ -1870,7 +1872,7 @@ Return value is either a list in the form
|
|||
|
||||
**** remove-last :writer:method:
|
||||
#+BEGIN_SRC lisp
|
||||
(defmethod remove-last ((backend plist-group-backend) &key (save t) &allow-other-keys)
|
||||
(defmethod chronometrist:remove-last ((backend plist-group-backend) &key (save t) &allow-other-keys)
|
||||
(with-slots (file) backend
|
||||
(sexp-in-file
|
||||
file
|
||||
|
@ -1900,7 +1902,7 @@ Return value is either a list in the form
|
|||
|
||||
**** to-list :reader:method:
|
||||
#+BEGIN_SRC lisp
|
||||
(defmethod to-list ((backend plist-group-backend))
|
||||
(defmethod chronometrist:to-list ((backend plist-group-backend))
|
||||
(backend-run-assertions backend)
|
||||
(loop-sexp-file for expr in (chronometrist:backend-file backend)
|
||||
append (reverse (rest expr))))
|
||||
|
@ -1908,7 +1910,7 @@ Return value is either a list in the form
|
|||
|
||||
**** to-hash-table :reader:method:
|
||||
#+BEGIN_SRC lisp
|
||||
(defmethod to-hash-table ((backend plist-group-backend))
|
||||
(defmethod chronometrist:to-hash-table ((backend plist-group-backend))
|
||||
(let ((file (chronometrist:backend-file backend)))
|
||||
;; (format t "file: ~a" file)
|
||||
(with-open-file (in file)
|
||||
|
@ -1926,7 +1928,7 @@ Return value is either a list in the form
|
|||
|
||||
**** to-file :writer:method:
|
||||
#+BEGIN_SRC lisp
|
||||
(defmethod to-file (hash-table (backend plist-group-backend) file)
|
||||
(defmethod chronometrist:to-file (hash-table (backend plist-group-backend) file)
|
||||
(check-type hash-table hash-table)
|
||||
(delete-file file)
|
||||
(create-file backend file)
|
||||
|
@ -1942,7 +1944,7 @@ Return value is either a list in the form
|
|||
|
||||
**** on-add :writer:method:
|
||||
#+BEGIN_SRC lisp
|
||||
(defmethod on-add ((backend plist-group-backend))
|
||||
(defmethod chronometrist:on-add ((backend plist-group-backend))
|
||||
"Function run when a new plist-group is added at the end of a
|
||||
`plist-group-backend' file."
|
||||
(with-slots (hash-table) backend
|
||||
|
@ -1953,7 +1955,7 @@ Return value is either a list in the form
|
|||
|
||||
**** on-modify :writer:method:
|
||||
#+BEGIN_SRC lisp
|
||||
(defmethod on-modify ((backend plist-group-backend))
|
||||
(defmethod chronometrist:on-modify ((backend plist-group-backend))
|
||||
"Function run when the newest plist-group in a
|
||||
`plist-group-backend' file is modified."
|
||||
(with-slots (hash-table) backend
|
||||
|
@ -1969,7 +1971,7 @@ Return value is either a list in the form
|
|||
|
||||
**** on-remove :writer:method:
|
||||
#+BEGIN_SRC lisp
|
||||
(defmethod on-remove ((backend plist-group-backend))
|
||||
(defmethod chronometrist:on-remove ((backend plist-group-backend))
|
||||
"Function run when the newest plist-group in a
|
||||
`plist-group-backend' file is deleted."
|
||||
(with-slots (hash-table) backend
|
||||
|
@ -1982,7 +1984,7 @@ Return value is either a list in the form
|
|||
|
||||
**** verify :reader:method:
|
||||
#+BEGIN_SRC lisp :load no :tangle no
|
||||
(defmethod verify ((backend plist-group-backend))
|
||||
(defmethod chronometrist:verify ((backend plist-group-backend))
|
||||
(with-slots (file hash-table) backend
|
||||
;; incorrectly ordered groups check
|
||||
(loop-sexp-file for group in file
|
||||
|
@ -2004,7 +2006,7 @@ Return value is either a list in the form
|
|||
**** extended protocol
|
||||
***** list-tasks :method:
|
||||
#+BEGIN_SRC lisp
|
||||
(defmethod list-tasks ((backend backend))
|
||||
(defmethod chronometrist:list-tasks ((backend backend))
|
||||
(loop for plist in (to-list backend)
|
||||
collect (getf plist :name) into names
|
||||
finally (return
|
||||
|
@ -2014,7 +2016,7 @@ Return value is either a list in the form
|
|||
|
||||
***** latest-record :reader:method:
|
||||
#+BEGIN_SRC lisp
|
||||
(defmethod latest-record ((backend plist-group-backend))
|
||||
(defmethod chronometrist:latest-record ((backend plist-group-backend))
|
||||
(with-slots (file) backend
|
||||
(if (last-two-split-p file)
|
||||
(apply #'plist-unify (last-two-split-p (chronometrist:backend-file (active-backend))))
|
||||
|
@ -2023,16 +2025,15 @@ Return value is either a list in the form
|
|||
|
||||
***** task-records-for-date :reader:method:
|
||||
#+BEGIN_SRC lisp
|
||||
(defmethod task-records-for-date ((backend plist-group-backend)
|
||||
task date-ts
|
||||
&key &allow-other-keys)
|
||||
(defmethod chronometrist:task-records-for-date
|
||||
((backend plist-group-backend) task date-ts &key &allow-other-keys)
|
||||
(check-type task string)
|
||||
(check-type date-ts ts)
|
||||
(backend-run-assertions backend)
|
||||
(loop for plist in (gethash (date-iso date-ts)
|
||||
(backend-hash-table backend))
|
||||
when (equal task (getf plist :name))
|
||||
collect plist))
|
||||
(backend-hash-table backend))
|
||||
when (equal task (getf plist :name))
|
||||
collect plist))
|
||||
#+END_SRC
|
||||
|
||||
***** TODO active-days :reader:method:noexport:
|
||||
|
@ -2048,7 +2049,8 @@ Return value is either a list in the form
|
|||
We apply the same hack as in the [[hack-note-plist-group-insert][insert]] method, removing and inserting the plist group instead of just the specific plist, to avoid having to update the pretty printer.
|
||||
|
||||
#+BEGIN_SRC lisp
|
||||
(defmethod replace-last ((backend plist-group-backend) plist &key &allow-other-keys)
|
||||
(defmethod chronometrist:replace-last
|
||||
((backend plist-group-backend) plist &key &allow-other-keys)
|
||||
(check-type plist plist)
|
||||
(when (backend-empty-p backend)
|
||||
(error "No record to replace in %s" (eieio-object-class-name backend)))
|
||||
|
@ -2062,7 +2064,7 @@ We apply the same hack as in the [[hack-note-plist-group-insert][insert]] method
|
|||
|
||||
***** count-records :reader:method:noexport:
|
||||
#+BEGIN_SRC lisp :tangle no
|
||||
(defmethod count-records ((backend plist-group-backend)))
|
||||
(defmethod chronometrist:count-records ((backend plist-group-backend)))
|
||||
#+END_SRC
|
||||
|
||||
*** sqlite backend
|
||||
|
@ -2074,16 +2076,15 @@ We apply the same hack as in the [[hack-note-plist-group-insert][insert]] method
|
|||
(:import-from :alexandria :hash-table-keys)
|
||||
(:import-from :local-time :parse-timestring :timestamp-to-unix)
|
||||
(:import-from :sqlite
|
||||
:connect :execute-non-query :execute-single :execute-to-list)
|
||||
:connect :disconnect
|
||||
:execute-non-query :execute-single :execute-to-list)
|
||||
(:import-from :sxql
|
||||
:yield
|
||||
:create-table :foreign-key :unique-key
|
||||
:insert-into
|
||||
:select := :set= :from :order-by)
|
||||
(:import-from :alexandria :flatten)
|
||||
(:export
|
||||
:sqlite-backend
|
||||
:create-file :to-file :to-list :list-tasks :insert
|
||||
(:export :sqlite-backend
|
||||
;; customizable variables
|
||||
))
|
||||
(in-package :chronometrist.sqlite)
|
||||
|
@ -2209,14 +2210,14 @@ ORDER BY interval_id DESC;")
|
|||
(delete-file file)
|
||||
(disconnect connection)
|
||||
(setf connection nil)
|
||||
(create-file backend file)
|
||||
(chronometrist:create-file backend file)
|
||||
(loop for date in (sort (hash-table-keys hash-table) #'string-lessp) do
|
||||
;; insert date if it does not exist
|
||||
(execute-non-query connection
|
||||
"INSERT OR IGNORE INTO dates (date) VALUES (?);"
|
||||
(iso-to-unix date))
|
||||
(loop for plist in (gethash date hash-table) do
|
||||
(insert backend plist)))))
|
||||
(chronometrist:insert backend plist)))))
|
||||
#+END_SRC
|
||||
|
||||
**** to-list :reader:method:
|
||||
|
@ -2280,15 +2281,16 @@ s-expressions in a text column.")
|
|||
|
||||
**** insert :writer:method:
|
||||
#+BEGIN_SRC lisp
|
||||
(defmethod chronometrist:insert ((backend sqlite-backend) plist &key &allow-other-keys)
|
||||
(let-match (((or (list plist-1 plist-2) nil) (split-plist plist))
|
||||
(defmethod chronometrist:insert
|
||||
((backend sqlite-backend) plist &key &allow-other-keys)
|
||||
(let-match (((or (list plist-1 plist-2) nil) (chronometrist:split-plist plist))
|
||||
(connection (backend-connection backend)))
|
||||
(loop
|
||||
for plist in (if (and plist-1 plist-2)
|
||||
(list plist-1 plist-2)
|
||||
(list plist))
|
||||
do (let-match* (((plist :name name :start start :stop stop) plist)
|
||||
(date-unix (iso-to-unix (iso-to-date start)))
|
||||
(date-unix (iso-to-unix (chronometrist:iso-to-date start)))
|
||||
(start-unix (iso-to-unix start))
|
||||
(stop-unix (and stop (iso-to-unix stop)))
|
||||
;; insert interval properties if they do not exist
|
||||
|
@ -2358,8 +2360,8 @@ 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))
|
||||
(defmethod chronometrist:task-records-for-date
|
||||
((backend sqlite-backend) task date-ts &key &allow-other-keys))
|
||||
#+END_SRC
|
||||
|
||||
**** active-days
|
||||
|
|
Reference in New Issue