my-count-clocks in the following Elisp section defines a function that counts clocks in the current org-mode section. It does not descent into sub-sections. You can easily modify
my-count-clocks to fit your special needs, e.g., work recursive on sub-sections.
That function has a predicate function as argument. The predicate gets a timestamp as argument and should return non-nil if that timestamp is to be counted.
An example for such a timestamp is given as
my-pred is non-nil for timestamps that tick at least 4 hours and shorter than 5 hours.
The other functions in the Elisp code are just helpers.
(defun org-element-parse-headline (&optional granularity visible-only)
"Parse current headline.
GRANULARITY and VISIBLE-ONLY are like the args of `org-element-parse-buffer'."
(let ((level (org-current-level)))
(org-element-parse-buffer granularity visible-only)
(eq (org-element-property :level el) ,level)
(<= (org-element-property :begin el) (point))
(<= (point) (org-element-property :end el))
nil 'first-match 'no-recursion)))
(defun my-count-clocks (pred)
"Counting clocks fulfilling PRED in current subsection."
(interactive "a Predicate:")
(let* ((headline (org-element-parse-headline))
(clocks (org-element-map section 'clock (lambda (clock) (org-element-property :value clock))))
(num (cl-count-if pred clocks)))
(when (called-interactively-p 'any)
(message "Number of clocks: %d" num))
`(defun decode-time-subtract (a b)
"Decode time difference between A and B."
(decode-time (time-subtract a b))
',(butlast (decode-time '(0 0)) 3))))
(defun my-pred (timestamp)
Non-nil for timestamp that clicks at least 4 hours and less than 5 hours."
(let ((b (org-timestamp--to-internal-time timestamp))
(e (org-timestamp--to-internal-time timestamp t)))
(cl-multiple-value-bind (sec minute hour day month year) (decode-time-subtract e b)
;; Put the condition of your choice here:
(and (eq year 0) (eq month 0) (eq day 0)
(>= hour 4)
(< hour 5))