~pepe/neil

ref: a372855fb2a6c85e46f9e3cdebff92895f318135 neil/neil/watch/stats/utils.janet -rw-r--r-- 1.4 KiB
a372855f — Josef Pospíšil Use flatten 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
(import /templates/stats/line)
(import /templates/work-intervals/csv-line)
(use /neil/watch/utils)

(defmacro loop-tasks [coll redseqcond clients projects]
  ~(do
     (def ot (os/time))
     (loop [{:uuid i :name n :project pi
             :work-intervals wi :state st} :in ,coll
            :let [{:name pn :client pc} (,projects pi)
                  {:name cn} (,clients pc)
                  iwi (seq [w :in wi :when ,redseqcond] w)
                  dur (format-interval
                        (reduce (fn [a w] (+ a (- (or (w :end) ot) (w :start)))) 0 iwi))
                  cnt (length iwi)]]
       (,line/render :client-name cn :client-id pc
          :project-id pi :project-name pn
          :uuid i :name n :state st :duration dur
          :intervals-count cnt
          :one-go (and (= (length wi) 1) (= st "completed"))))))

(defmacro loop-interval-tasks [& epochs]
  (def redseqcond (case (length epochs)
                    1 ~(>= (w :start) ,(first epochs))
                    2 ~(and
                         (>= (w :start) ,(first epochs))
                         (<= (w :end) ,(last epochs)))))
  ~(loop-tasks (,worked-tasks brush project state ,;epochs)
               ,redseqcond
               clients projects))

(defmacro loop-tasks-csv [coll redseqcond]
  ~(loop [{:uuid i :name n
           :work-intervals wi} :in ,coll
          :let [iwi (seq [w :in wi :when ,redseqcond] w)]]
     (,csv-line/render :name n :work-intervals iwi)))