From f2db1f5b5e76b87341786ea78cbaf97245c39b0e Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Wed, 28 Nov 2018 16:38:47 +0100 Subject: [PATCH] =?UTF-8?q?[Timeline]=20Ensure=20empty=20timelines=20don?= =?UTF-8?q?=E2=80=99t=20break=20removal=20of=20short=20entries?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- site-lisp/timeline-tools.el | 55 +++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/site-lisp/timeline-tools.el b/site-lisp/timeline-tools.el index 2658136..83bbf91 100644 --- a/site-lisp/timeline-tools.el +++ b/site-lisp/timeline-tools.el @@ -333,37 +333,38 @@ A slot is short if it is not longer than THRESHOLD seconds. Resulting gaps are distributed evenly among adjacent slots. THRESHOLD defaults to the value of `timeline-tools-short-task-threshold’ if not supplied." - (let ((start (timeline-tools-entry-start-time (-first-item timeline))) - (end (timeline-tools-entry-end-time (-last-item timeline))) - (threshold (or threshold timeline-tools-short-task-threshold)) - new-timeline) + (unless (null timeline) + (let ((start (timeline-tools-entry-start-time (-first-item timeline))) + (end (timeline-tools-entry-end-time (-last-item timeline))) + (threshold (or threshold timeline-tools-short-task-threshold)) + new-timeline) - ;; remove all slots that are too short - (setq new-timeline - (cl-remove-if (lambda (entry) - (<= (- (timeline-tools-entry-end-time entry) - (timeline-tools-entry-start-time entry)) - threshold)) - timeline)) + ;; remove all slots that are too short + (setq new-timeline + (cl-remove-if (lambda (entry) + (<= (- (timeline-tools-entry-end-time entry) + (timeline-tools-entry-start-time entry)) + threshold)) + timeline)) - ;; reset start and end times - (setf (timeline-tools-entry-start-time (-first-item new-timeline)) start) - (setf (timeline-tools-entry-end-time (-last-item new-timeline)) end) + ;; reset start and end times + (setf (timeline-tools-entry-start-time (-first-item new-timeline)) start) + (setf (timeline-tools-entry-end-time (-last-item new-timeline)) end) - ;; distribute gaps evenly among adjacent slots - (cl-do - ((sub-timeline new-timeline (cdr sub-timeline))) - ((null (cdr sub-timeline))) - (let* ((entry-1 (-first-item sub-timeline)) - (entry-2 (-second-item sub-timeline)) - (end-1 (timeline-tools-entry-end-time entry-1)) - (start-2 (timeline-tools-entry-start-time entry-2))) - (when (not (= end-1 start-2)) - (let ((middle (/ (+ end-1 start-2) 2))) - (setf (timeline-tools-entry-end-time entry-1) middle) - (setf (timeline-tools-entry-start-time entry-2) middle))))) + ;; distribute gaps evenly among adjacent slots + (cl-do + ((sub-timeline new-timeline (cdr sub-timeline))) + ((null (cdr sub-timeline))) + (let* ((entry-1 (-first-item sub-timeline)) + (entry-2 (-second-item sub-timeline)) + (end-1 (timeline-tools-entry-end-time entry-1)) + (start-2 (timeline-tools-entry-start-time entry-2))) + (when (not (= end-1 start-2)) + (let ((middle (/ (+ end-1 start-2) 2))) + (setf (timeline-tools-entry-end-time entry-1) middle) + (setf (timeline-tools-entry-start-time entry-2) middle))))) - new-timeline)) + new-timeline))) (defun timeline-tools-transform-timeline (timeline) "Return timeline from files, after application of