REF split parent classifier into separate function

This commit is contained in:
Nathan Dwarshuis 2022-03-07 19:53:55 -05:00
parent 849783c5c0
commit 48ff734880
1 changed files with 46 additions and 43 deletions

View File

@ -1391,54 +1391,57 @@ removed from, added to, or edited within the DAG respectively."
(dag-edit-nodes to-remove to-insert dag)))) (dag-edit-nodes to-remove to-insert dag))))
(plist-put org-x-dag :dag dag*))) (plist-put org-x-dag :dag dag*)))
;; TODO this will also include broken links, which isn't totally wrong but these
;; should be filtered out as including them is suboptimal (note: I figureed out (defun org-x-dag-id->parent-class (id parent)
;; they were here because the broken links dag code is wrong) (-let* (((cfile cgroup) (org-x-dag-id->file-group id))
(defun org-x-dag-filter-links (relations)
(cl-flet
((classify-edge
(edge)
(-let* (((child parent) edge)
((cfile cgroup) (org-x-dag-id->file-group child))
((pfile pgroup) (org-x-dag-id->file-group parent))) ((pfile pgroup) (org-x-dag-id->file-group parent)))
(cl-case cgroup (cl-case cgroup
;; the only allowed links are local ;; the only allowed links are local
((:lifetime :survival) ((:lifetime :survival)
(unless (equal cfile pfile) (unless (equal cfile pfile)
:foreign)) :ill-foreign))
;; should only link locally or a lifetime goal ;; should only link locally or a lifetime goal
(:endpoint (:endpoint
(unless (or (equal cfile pfile) (eq pgroup :lifetime)) (unless (or (equal cfile pfile) (eq pgroup :lifetime))
:foreign)) :ill-foreign))
;; should only link to an endpoint or lifetime goal ;; should only link to an endpoint or lifetime goal
(:quarterly (:quarterly
(cond (cond
((memq pgroup '(:endpoint :lifetime)) nil) ((memq pgroup '(:endpoint :lifetime)) nil)
((equal pfile cfile) :local) ((equal pfile cfile) :ill-local)
(t :foreign))) (t :ill-foreign)))
;; should only link to a quarterly plan ;; should only link to a quarterly plan
(:weekly (:weekly
(cond (cond
((eq pgroup :quarterly) nil) ((eq pgroup :quarterly) nil)
((equal pfile cfile) :local) ((equal pfile cfile) :ill-local)
(t :foreign))) (t :ill-foreign)))
;; should only link to a weekly plan or an action ;; should only link to a weekly plan or an action
(:daily (:daily
(cond (cond
((memq pgroup '(nil :weekly)) nil) ((memq pgroup '(nil :weekly)) nil)
((equal pfile cfile) :local) ((equal pfile cfile) :ill-local)
(t :foreign))) (t :ill-foreign)))
;; actions can only be linked to goal files, and nothing else ;; actions can only be linked to goal files, and nothing else
(t (t
(cond (cond
((memq pgroup '(:lifetime :endpoint :survival)) nil) ((memq pgroup '(:lifetime :endpoint :survival)) nil)
((equal pfile cfile) :local) ((equal pfile cfile) :ill-local)
(t :foreign))))))) (t :ill-foreign))))))
(-let (((&alist :foreign :local) (->> relations
(--mapcat (-let (((c . ps) it)) ;; TODO this will also include broken links, which isn't totally wrong but these
(--map (list c it) ps))) ;; should be filtered out as including them is suboptimal (note: I figureed out
(-group-by #'classify-edge)))) ;; they were here because the broken links dag code is wrong)
(list foreign local)))) (defun org-x-dag-filter-links (relations)
(cl-flet
((flatten-relation
(rel)
(-let (((c . ps) rel))
(--map (list c it) ps))))
(-let (((&alist :ill-foreign :ill-local)
(->> (-mapcat #'flatten-relation relations)
(--group-by (apply #'org-x-dag-id->parent-class it)))))
(list ill-foreign ill-local))))
;; TODO there is a HUGE DIFFERENCE between a 'key' (the things in the hash table ;; TODO there is a HUGE DIFFERENCE between a 'key' (the things in the hash table
;; the look things up) and a 'node' (which is a cons cell, the car of which is a ;; the look things up) and a 'node' (which is a cons cell, the car of which is a