emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Giving priority to overdue habits that repeat more frequently
@ 2013-10-26 14:06 Thomas Morgan
  0 siblings, 0 replies; only message in thread
From: Thomas Morgan @ 2013-10-26 14:06 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 397 bytes --]

Dear Org mode hackers,

Here is a patch to give priority to overdue habits that repeat more
frequently.  The number of times a habit would have been done if it
had always been on time is made a factor in its urgency score.  I'm
not sure if this is true for everyone but my more frequently repeating
habits are generally the ones I give priority to, so this behavior seems
to fit.

Thanks,
Thomas


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Give-priority-to-overdue-habits-that-repeat-more-fre.patch --]
[-- Type: text/x-diff, Size: 2190 bytes --]

From cc25d929f6eafeda89c75364068572d0aed3502d Mon Sep 17 00:00:00 2001
From: Thomas Morgan <tlm@ziiuu.com>
Date: Sun, 28 Jul 2013 17:43:19 +0200
Subject: [PATCH] Give priority to overdue habits that repeat more frequently.

lisp/org-habit.el (org-habit-get-priority): Take into account the
frequency of overdue habits.  Weight those that repeat often higher
than those that repeat infrequently.
---
 lisp/org-habit.el |   18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/lisp/org-habit.el b/lisp/org-habit.el
index eba9037..23713cf 100644
--- a/lisp/org-habit.el
+++ b/lisp/org-habit.el
@@ -230,20 +230,30 @@ This must take into account not just urgency, but consistency as well."
   (let ((pri 1000)
 	(now (if moment (time-to-days moment) (org-today)))
 	(scheduled (org-habit-scheduled habit))
-	(deadline (org-habit-deadline habit)))
+	(deadline (org-habit-deadline habit))
+	(s-repeat (org-habit-scheduled-repeat habit))
+	(d-repeat (org-habit-deadline-repeat habit)))
     ;; add 10 for every day past the scheduled date, and subtract for every
     ;; day before it
     (setq pri (+ pri (* (- now scheduled) 10)))
+    ;; if overdue, add 20 for every time it would have been done if
+    ;; consistently performed on scheduled date
+    (when (< scheduled now)
+      (setq pri (+ pri (* (/ (- now scheduled) s-repeat) 20))))
     ;; add 50 if the deadline is today
     (if (and (/= scheduled deadline)
 	     (= now deadline))
 	(setq pri (+ pri 50)))
-    ;; add 100 for every day beyond the deadline date, and subtract 10 for
-    ;; every day before it
     (let ((slip (- now (1- deadline))))
+      ;; add 100 for every day beyond the deadline date, and subtract 10 for
+      ;; every day before it
       (if (> slip 0)
 	  (setq pri (+ pri (* slip 100)))
-	(setq pri (+ pri (* slip 10)))))
+	(setq pri (+ pri (* slip 10))))
+      ;; if overdue, add 200 for every time it would have been done if
+      ;; consistently performed the day before deadline
+      (when (> slip 0)
+      	(setq pri (+ pri (* (/ slip d-repeat) 200)))))
     pri))
 
 (defun org-habit-get-faces (habit &optional now-days scheduled-days donep)
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2013-10-26 15:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-26 14:06 Giving priority to overdue habits that repeat more frequently Thomas Morgan

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).