From bdf07ba3adf599ac5027fd741923de7dfc41c851 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 9 Jan 2024 10:37:10 +0200 Subject: Add gnosis-past-or-present-p Seperate the comparing of dates, emacsql is way too buggy for comparing lists directly --- gnosis.el | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gnosis.el b/gnosis.el index e37e9aa..966609f 100644 --- a/gnosis.el +++ b/gnosis.el @@ -710,6 +710,15 @@ if DUE is t, return only due notes" when (not (gnosis-suspended-p note)) collect note))) +(defun gnosis-past-or-present-p (date) + "Compare the input DATE with the current date. +Return t if DATE is today or in the past, nil if it's in the future. +DATE is a list of the form (year month day)." + (let* ((now (gnosis-algorithm-date)) + (time-now (encode-time 0 0 0 (nth 2 now) (nth 1 now) (nth 0 now))) + (time-date (encode-time 0 0 0 (nth 2 date) (nth 1 date) (nth 0 date)))) + (not (time-less-p time-now time-date)))) + (defun gnosis-due-tags () "Return a list of due note tags." (let ((due-notes (gnosis-review-get-due-notes))) -- cgit v1.2.3 From 689398a7711b548cdec2f31e3ac4ae5174d992bc Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 9 Jan 2024 10:38:01 +0200 Subject: Rewrite gnosis-review-is-due-p --- gnosis.el | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/gnosis.el b/gnosis.el index 966609f..9c8ea40 100644 --- a/gnosis.el +++ b/gnosis.el @@ -749,6 +749,14 @@ Returns a list of unique tags." ;; Review ;;;;;;;;;; +(defun gnosis-review-is-due-p (note-id) + "Check if note with value of NOTE-ID for id is due for review. + +Check if it's suspended, and if it's due today." + (if (and (not (gnosis-suspended-p note-id)) + (gnosis-review-is-due-today-p note-id)) + t + nil)) (defun gnosis-review--algorithm (id success) "Return next review date & ef for note with value of id ID. @@ -761,11 +769,6 @@ Returns a list of the form ((yyyy mm dd) ef)." (gnosis-get 'n 'review-log `(= id ,id)) ef success ff c-success))) -(defun gnosis-review-is-due-p (note-id) - "Return t if unsuspended note with NOTE-ID is due today." - (emacsql gnosis-db `[:select [id] :from review-log :where (and (<= next-rev ',(gnosis-algorithm-date)) - (= suspend 0) - (= id ,note-id))])) (defun gnosis-review-get-due-notes () "Return a list due notes id for current date. -- cgit v1.2.3 From 542d6ad2cf21e6afde421c58999c8e68701301a1 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 9 Jan 2024 10:39:01 +0200 Subject: Add gnosis-review-is-due-today-p --- gnosis.el | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gnosis.el b/gnosis.el index 9c8ea40..b9e7d04 100644 --- a/gnosis.el +++ b/gnosis.el @@ -757,6 +757,15 @@ Check if it's suspended, and if it's due today." (gnosis-review-is-due-today-p note-id)) t nil)) + +(defun gnosis-review-is-due-today-p (id) + "Return t if note with ID is due today. + +This function ignores if note is suspended. Refer to +`gnosis-review-is-due-p' if you need to check for suspended value as +well." + (let ((next-rev (gnosis-get 'next-rev 'review-log `(= id ,id)))) + (gnosis-past-or-present-p next-rev))) (defun gnosis-review--algorithm (id success) "Return next review date & ef for note with value of id ID. -- cgit v1.2.3 From 8d06a7b303e46a5409516f87ea5ba3b7657b42fd Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 9 Jan 2024 10:39:15 +0200 Subject: Rewrite gnosis-review-get-due-notes --- gnosis.el | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/gnosis.el b/gnosis.el index b9e7d04..d587dee 100644 --- a/gnosis.el +++ b/gnosis.el @@ -392,6 +392,7 @@ NOTE: If a gnosis--insert-into fails, the whole transaction will be constraint." (condition-case nil (progn + ;; Refer to `gnosis-db-schema-SCHEMA' e.g `gnosis-db-schema-review-log' (gnosis--insert-into 'notes `([nil ,type ,main ,options ,answer ,tags ,(gnosis--get-deck-id deck)])) (gnosis--insert-into 'review `([nil ,gnosis-algorithm-ef ,gnosis-algorithm-ff ,gnosis-algorithm-interval])) (gnosis--insert-into 'review-log `([nil ,(gnosis-algorithm-date) ,(gnosis-algorithm-date) 0 0 0 0 ,suspend 0])) @@ -766,6 +767,14 @@ This function ignores if note is suspended. Refer to well." (let ((next-rev (gnosis-get 'next-rev 'review-log `(= id ,id)))) (gnosis-past-or-present-p next-rev))) + +(defun gnosis-review-get-due-notes () + "Return a list due notes id for current date." + (let ((notes (gnosis-select 'id 'notes))) + (cl-loop for note in (apply #'append notes) + when (gnosis-review-is-due-p note) + collect note))) + (defun gnosis-review--algorithm (id success) "Return next review date & ef for note with value of id ID. @@ -778,17 +787,6 @@ Returns a list of the form ((yyyy mm dd) ef)." (gnosis-get 'n 'review-log `(= id ,id)) ef success ff c-success))) - -(defun gnosis-review-get-due-notes () - "Return a list due notes id for current date. - -Select notes where: - - Next review date <= current date - - Not suspended." - (apply #'append - (emacsql gnosis-db `[:select [id] :from review-log :where (and (<= next-rev ',(gnosis-algorithm-date)) - (= suspend 0))]))) - (defun gnosis-review-due-notes--with-tags () "Return a list of due note tags." (let ((due-notes (gnosis-review-get-due-notes))) -- cgit v1.2.3