-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathsupertag-view-priority-matrix.el
More file actions
232 lines (210 loc) · 9.42 KB
/
Copy pathsupertag-view-priority-matrix.el
File metadata and controls
232 lines (210 loc) · 9.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
;;; supertag-view-priority-matrix.el --- Priority matrix view -*- lexical-binding: t; -*-
;;; Commentary:
;; Displays tasks in a 2x2 priority matrix (Eisenhower Matrix):
;; - X-axis: Urgency (Low -> High)
;; - Y-axis: Importance (Low -> High)
;;
;; Quadrants:
;; 1. Important & Urgent (DO) - Crisis, deadlines
;; 2. Important & Not Urgent (PLAN) - Strategy, planning
;; 3. Not Important & Urgent (DELEGATE) - Interruptions
;; 4. Not Important & Not Urgent (DELETE) - Time wasters
;;
;; Usage:
;; M-x supertag-view-schema
;; Navigate to #task
;; Press v v
;; Select "Priority Matrix"
;;
;; Requirements:
;; - 'priority' or 'urgency' and 'importance' fields
;; - Or uses todo state and custom fields
;;; Code:
(require 'supertag-view-framework)
(require 'supertag-core-scan)
;; ============================================================================
;; Priority Calculation
;; ============================================================================
(defun supertag-view-priority--get-urgency (node-data)
"Extract urgency from NODE-DATA (0-10 scale)."
(or (plist-get node-data :urgency)
(plist-get node-data :Urgency)
;; Infer from deadline
(let ((deadline (plist-get node-data :deadline)))
(if deadline
(let* ((deadline-time (org-time-string-to-time deadline))
(days-diff (/ (float-time (time-subtract deadline-time (current-time))) 86400)))
(cond
((< days-diff 2) 9) ; Very urgent
((< days-diff 7) 7) ; Urgent
((< days-diff 14) 5) ; Moderate
(t 3))) ; Not urgent
5)) ; Default
5)) ; Fallback
(defun supertag-view-priority--get-importance (node-data)
"Extract importance from NODE-DATA (0-10 scale)."
(or (plist-get node-data :importance)
(plist-get node-data :Importance)
;; Infer from priority tag or field
(let ((priority (plist-get node-data :priority)))
(pcase priority
('"A" 9)
('"B" 6)
('"C" 3)
(_ 5)))
5))
(defun supertag-view-priority--classify (node-data)
"Classify NODE-DATA into quadrant.
Returns one of: do, plan, delegate, delete"
(let ((urgency (supertag-view-priority--get-urgency node-data))
(importance (supertag-view-priority--get-importance node-data)))
(cond
((and (>= importance 6) (>= urgency 6)) 'do)
((and (>= importance 6) (< urgency 6)) 'plan)
((and (< importance 6) (>= urgency 6)) 'delegate)
(t 'delete))))
;; ============================================================================
;; Matrix Building
;; ============================================================================
(defun supertag-view-priority--build-matrix (tag-name)
"Build priority matrix for TAG-NAME.
Returns an alist of (quadrant . tasks)."
(let ((nodes (supertag-find-nodes-by-tag tag-name))
(matrix (list (cons 'do nil)
(cons 'plan nil)
(cons 'delegate nil)
(cons 'delete nil))))
(dolist (node-pair nodes)
(let* ((node-id (car node-pair))
(node-data (cdr node-pair))
(quadrant (supertag-view-priority--classify node-data))
(task-data (list :id node-id
:title (or (plist-get node-data :title) "Untitled")
:urgency (supertag-view-priority--get-urgency node-data)
:importance (supertag-view-priority--get-importance node-data))))
(push task-data (cdr (assoc quadrant matrix)))))
;; Sort each quadrant by urgency * importance score
(dolist (entry matrix)
(setcdr entry (sort (cdr entry)
(lambda (a b)
(> (+ (* (plist-get a :urgency) (plist-get a :importance)))
(+ (* (plist-get b :urgency) (plist-get b :importance))))))))
matrix))
;; ============================================================================
;; Display
;; ============================================================================
(defun supertag-view-priority--quadrant-title (quadrant)
"Get title for QUADRANT."
(pcase quadrant
('do "DO (Do First)")
('plan "PLAN (Schedule)")
('delegate "DELEGATE (Assign)")
('delete "DELETE (Eliminate)")
(_ "Unknown")))
(defun supertag-view-priority--quadrant-color (quadrant)
"Get color for QUADRANT."
(pcase quadrant
('do '(:foreground "red" :weight bold))
('plan '(:foreground "blue"))
('delegate '(:foreground "orange"))
('delete '(:foreground "gray"))
(_ 'default)))
(defun supertag-view-priority--format-task (task max-title-len)
"Format TASK for display.
MAX-TITLE-LEN is the maximum title length."
(let ((title (plist-get task :title))
(urgency (plist-get task :urgency))
(importance (plist-get task :importance)))
;; Truncate title if needed
(when (> (length title) max-title-len)
(setq title (concat (substring title 0 (- max-title-len 3)) "...")))
(format " %-30s U:%d I:%d" title urgency importance)))
;; ============================================================================
;; Main View Definition
;; ============================================================================
(defun supertag-view-priority--widgets (context)
"Return priority matrix widgets for CONTEXT."
(let* ((tag (plist-get context :tag))
(matrix (supertag-view-priority--build-matrix tag))
(do-tasks (cdr (assoc 'do matrix)))
(plan-tasks (cdr (assoc 'plan matrix)))
(delegate-tasks (cdr (assoc 'delegate matrix)))
(delete-tasks (cdr (assoc 'delete matrix)))
(total-tasks (+ (length do-tasks) (length plan-tasks)
(length delegate-tasks) (length delete-tasks))))
(append
(list
(list :type :header :text (format "Priority Matrix - #%s" tag))
(list :type :text
:content "Eisenhower Matrix: Urgency × Importance")
(list :type :stats-row
:stats `(("Total Tasks" . ,total-tasks)
("DO (Urgent+Important)" . ,(length do-tasks))
("PLAN (Important)" . ,(length plan-tasks))
("DELEGATE (Urgent)" . ,(length delegate-tasks))
("DELETE (Neither)" . ,(length delete-tasks))))
(list :type :subheader :text "The Matrix"))
(mapcar
(lambda (quadrant)
(let* ((tasks (cdr (assoc quadrant matrix)))
(visible (cl-subseq tasks 0 (min 10 (length tasks))))
(content
(if tasks
(concat
(mapconcat
(lambda (task)
(supertag-view-priority--format-task task 25))
visible "\n")
(when (> (length tasks) 10)
(format "\n ... and %d more"
(- (length tasks) 10))))
" (no tasks)")))
(list :type :section
:key quadrant
:title (supertag-view-priority--quadrant-title quadrant)
:face (supertag-view-priority--quadrant-color quadrant)
:children (list (list :type :text :content content)))))
'(do plan delegate delete))
(list
(list :type :separator)
(list :type :text
:content
(concat
"How to use:\n"
" 1. DO: Do these tasks immediately\n"
" 2. PLAN: Schedule time for these\n"
" 3. DELEGATE: Assign to someone else\n"
" 4. DELETE: Consider eliminating these\n\n"
"Set 'urgency' and 'importance' fields (0-10) on nodes "
"for accurate classification."))))))
(supertag-view-define-from-config
(list :id 'priority-matrix
:name "Priority Matrix"
:persist nil
:widgets #'supertag-view-priority--widgets))
;; ============================================================================
;; Demo
;; ============================================================================
(defun supertag-view-priority-matrix-demo ()
"Demonstrate the priority matrix with mock data."
(interactive)
(cl-letf (((symbol-function 'supertag-find-nodes-by-tag)
(lambda (_tag)
(list
;; DO: High urgency, high importance
(cons "task-1" (list :title "Fix critical bug" :urgency 9 :importance 10))
(cons "task-2" (list :title "Client deadline today" :urgency 10 :importance 8))
;; PLAN: Low urgency, high importance
(cons "task-3" (list :title "Q4 planning" :urgency 3 :importance 9))
(cons "task-4" (list :title "Refactor codebase" :urgency 2 :importance 8))
;; DELEGATE: High urgency, low importance
(cons "task-5" (list :title "Answer email" :urgency 7 :importance 2))
(cons "task-6" (list :title "Schedule meeting" :urgency 6 :importance 3))
;; DELETE: Low urgency, low importance
(cons "task-7" (list :title "Check social media" :urgency 1 :importance 1))
(cons "task-8" (list :title "Organize desktop" :urgency 2 :importance 2))))))
(supertag-view-open 'priority-matrix
(list :tag "task"
:nodes nil))))
(provide 'supertag-view-priority-matrix)
;;; supertag-view-priority-matrix.el ends here