[Timeline] Extract gap-filling into separate function
This commit is contained in:
parent
f2db1f5b5e
commit
62ac9a887b
|
@ -44,7 +44,7 @@
|
||||||
:group 'applications)
|
:group 'applications)
|
||||||
|
|
||||||
(defcustom timeline-tools-filter-functions
|
(defcustom timeline-tools-filter-functions
|
||||||
(list #'timeline-tools-remove-short-entries
|
(list #'timeline-tools-fill-gaps
|
||||||
#'timeline-tools-cluster-same-entries)
|
#'timeline-tools-cluster-same-entries)
|
||||||
"List of functions to apply when formatting timelines.
|
"List of functions to apply when formatting timelines.
|
||||||
Filter are applied in the order they are given in this list."
|
Filter are applied in the order they are given in this list."
|
||||||
|
@ -332,39 +332,48 @@ function will throw an error."
|
||||||
A slot is short if it is not longer than THRESHOLD seconds.
|
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.
|
||||||
|
|
||||||
|
This function destructively modifies its first argument."
|
||||||
(unless (null timeline)
|
(unless (null timeline)
|
||||||
(let ((start (timeline-tools-entry-start-time (-first-item timeline)))
|
(let ((start (timeline-tools-entry-start-time (-first-item timeline)))
|
||||||
(end (timeline-tools-entry-end-time (-last-item timeline)))
|
(end (timeline-tools-entry-end-time (-last-item timeline)))
|
||||||
(threshold (or threshold timeline-tools-short-task-threshold))
|
(threshold (or threshold timeline-tools-short-task-threshold))
|
||||||
new-timeline)
|
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
|
(timeline-tools-fill-gaps new-timeline))))
|
||||||
((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)))
|
(defun timeline-tools-fill-gaps (timeline)
|
||||||
|
"Fill gaps in TIMELINE evenly.
|
||||||
|
|
||||||
|
This is achieved by extending the start time and the end time of
|
||||||
|
the surrounding entries equally.
|
||||||
|
|
||||||
|
This function destructively modifies its first argument."
|
||||||
|
(cl-do
|
||||||
|
((sub-timeline timeline (cdr sub-timeline)))
|
||||||
|
((null (cdr sub-timeline)) 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))))))
|
||||||
|
|
||||||
(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
|
||||||
|
|
Loading…
Reference in New Issue