[Timeline] Ensure empty timelines don’t break removal of short entries

This commit is contained in:
Daniel Borchmann 2018-11-28 16:38:47 +01:00
parent a4febc68d1
commit f2db1f5b5e
Signed by: exot
GPG Key ID: 4F63DB96D45AA9C6

View File

@ -333,37 +333,38 @@ A slot is short if it is not longer than THRESHOLD seconds.
Resulting gaps are distributed evenly among adjacent slots. Resulting gaps are distributed evenly among adjacent slots.
THRESHOLD defaults to the value of THRESHOLD defaults to the value of
`timeline-tools-short-task-threshold if not supplied." `timeline-tools-short-task-threshold if not supplied."
(let ((start (timeline-tools-entry-start-time (-first-item timeline))) (unless (null timeline)
(end (timeline-tools-entry-end-time (-last-item timeline))) (let ((start (timeline-tools-entry-start-time (-first-item timeline)))
(threshold (or threshold timeline-tools-short-task-threshold)) (end (timeline-tools-entry-end-time (-last-item timeline)))
new-timeline) (threshold (or threshold timeline-tools-short-task-threshold))
new-timeline)
;; remove all slots that are too short ;; remove all slots that are too short
(setq new-timeline (setq new-timeline
(cl-remove-if (lambda (entry) (cl-remove-if (lambda (entry)
(<= (- (timeline-tools-entry-end-time entry) (<= (- (timeline-tools-entry-end-time entry)
(timeline-tools-entry-start-time entry)) (timeline-tools-entry-start-time entry))
threshold)) threshold))
timeline)) timeline))
;; reset start and end times ;; reset start and end times
(setf (timeline-tools-entry-start-time (-first-item new-timeline)) start) (setf (timeline-tools-entry-start-time (-first-item new-timeline)) start)
(setf (timeline-tools-entry-end-time (-last-item new-timeline)) end) (setf (timeline-tools-entry-end-time (-last-item new-timeline)) end)
;; distribute gaps evenly among adjacent slots ;; distribute gaps evenly among adjacent slots
(cl-do (cl-do
((sub-timeline new-timeline (cdr sub-timeline))) ((sub-timeline new-timeline (cdr sub-timeline)))
((null (cdr sub-timeline))) ((null (cdr sub-timeline)))
(let* ((entry-1 (-first-item sub-timeline)) (let* ((entry-1 (-first-item sub-timeline))
(entry-2 (-second-item sub-timeline)) (entry-2 (-second-item sub-timeline))
(end-1 (timeline-tools-entry-end-time entry-1)) (end-1 (timeline-tools-entry-end-time entry-1))
(start-2 (timeline-tools-entry-start-time entry-2))) (start-2 (timeline-tools-entry-start-time entry-2)))
(when (not (= end-1 start-2)) (when (not (= end-1 start-2))
(let ((middle (/ (+ end-1 start-2) 2))) (let ((middle (/ (+ end-1 start-2) 2)))
(setf (timeline-tools-entry-end-time entry-1) middle) (setf (timeline-tools-entry-end-time entry-1) middle)
(setf (timeline-tools-entry-start-time entry-2) middle))))) (setf (timeline-tools-entry-start-time entry-2) middle)))))
new-timeline)) new-timeline)))
(defun timeline-tools-transform-timeline (timeline) (defun timeline-tools-transform-timeline (timeline)
"Return timeline from files, after application of "Return timeline from files, after application of