~pepe/neil

e0f9ffdd1eebb466bcb9768597af1a667656bbf9 — Josef Pospíšil a month ago ab6fc14
Tune stats
3 files changed, 37 insertions(+), 38 deletions(-)

M neil/watch/stats/init.janet
M neil/watch/stats/utils.janet
M templates/stats/time-tables.temple
M neil/watch/stats/init.janet => neil/watch/stats/init.janet +32 -33
@@ 15,49 15,48 @@

(defn interval [brush]
  (fn [{:params {:interval i :project project :state state}}]
    (def [clients projects] [(:soak brush :clients)
                             (retrieve brush all-projects-table)])
    (def [projects clients] (retrieve brush [:clients (collect) (in-all :projects) merged]))
    (capout
      (case i
        "today"
        (utils/loop-tasks-stats (worked-tasks brush project state (:epoch (today)))
                          (>= (w :start) (:epoch (today)))
                          clients projects)
        (utils/loop-tasks (worked-tasks brush project state (:epoch (today)))
                                (>= (w :start) (:epoch (today)))
                                clients projects)
        "yesterday"
        (utils/loop-tasks-stats (worked-tasks brush project state (:epoch (yesterday)) (:epoch (today)))
                          (and
                            (>= (w :start) (:epoch (yesterday)))
                            (<= (w :end) (:epoch (today))))
                          clients projects)
        (utils/loop-tasks (worked-tasks brush project state (:epoch (yesterday)) (:epoch (today)))
                                (and
                                  (>= (w :start) (:epoch (yesterday)))
                                  (<= (w :end) (:epoch (today))))
                                clients projects)
        "current-week"
        (utils/loop-tasks-stats (worked-tasks brush project state (:epoch (current-week-start)))
                          (>= (w :start) (:epoch (current-week-start)))
                          clients projects)
        (utils/loop-tasks (worked-tasks brush project state (:epoch (current-week-start)))
                                (>= (w :start) (:epoch (current-week-start)))
                                clients projects)
        "last-week"
        (utils/loop-tasks-stats (worked-tasks brush project state (:epoch (last-week-start)) (:epoch (current-week-start)))
                          (and
                            (>= (w :start) (:epoch (last-week-start)))
                            (<= (w :end) (:epoch (current-week-start))))
                          clients projects)
        (utils/loop-tasks (worked-tasks brush project state (:epoch (last-week-start)) (:epoch (current-week-start)))
                                (and
                                  (>= (w :start) (:epoch (last-week-start)))
                                  (<= (w :end) (:epoch (current-week-start))))
                                clients projects)
        "current-month"
        (utils/loop-tasks-stats (worked-tasks brush project state (:epoch (current-month-start)))
                          (>= (w :start) (:epoch (current-month-start)))
                          clients projects)
        (utils/loop-tasks (worked-tasks brush project state (:epoch (current-month-start)))
                                (>= (w :start) (:epoch (current-month-start)))
                                clients projects)
        "last-month"
        (utils/loop-tasks-stats (worked-tasks brush project state (:epoch (last-month-start)) (:epoch (current-month-start)))
                          (and
                            (>= (w :start) (:epoch (last-month-start)))
                            (<= (w :end) (:epoch (current-month-start))))
                          clients projects)
        (utils/loop-tasks (worked-tasks brush project state (:epoch (last-month-start)) (:epoch (current-month-start)))
                                (and
                                  (>= (w :start) (:epoch (last-month-start)))
                                  (<= (w :end) (:epoch (current-month-start))))
                                clients projects)
        "current-year"
        (utils/loop-tasks-stats (worked-tasks brush project state (:epoch (current-year-start)))
                          (>= (w :start) (:epoch (current-year-start)))
                          clients projects)
        (utils/loop-tasks (worked-tasks brush project state (:epoch (current-year-start)))
                                (>= (w :start) (:epoch (current-year-start)))
                                clients projects)
        "last-year"
        (utils/loop-tasks-stats (worked-tasks brush project state (:epoch (start-of-year 1)) (:epoch (current-year-start)))
                          (and (>= (w :start) (:epoch (start-of-year 1)))
                               (<= (w :end) (:epoch (current-year-start))))
                          clients projects)))))
        (utils/loop-tasks (worked-tasks brush project state (:epoch (start-of-year 1)) (:epoch (current-year-start)))
                                (and (>= (w :start) (:epoch (start-of-year 1)))
                                     (<= (w :end) (:epoch (current-year-start))))
                                clients projects)))))

(defn filter [brush]
  (fn [{:body body}]

M neil/watch/stats/utils.janet => neil/watch/stats/utils.janet +1 -1
@@ 1,7 1,7 @@
(import /templates/stats/line)
(import /templates/work-intervals/csv-line)

(defmacro loop-tasks-stats [coll redseqcond clients projects]
(defmacro loop-tasks [coll redseqcond clients projects]
  ~(do
     (def ot (os/time))
     (loop [{:uuid i :name n :project pi

M templates/stats/time-tables.temple => templates/stats/time-tables.temple +4 -4
@@ 28,10 28,10 @@ $}
  <h3>total {{ (format-interval wis) }}</h3>
  <table>
    <tbody>
        {% (utils/loop-tasks-stats (args :worked-tasks)
                                   (and (>= (w :start) (get-in args [:interval :start]))
                                        (<= (w :end) (or (get-in args [:interval :end]) (os/time))))
                                   (args :clients) (args :projects)) %}
        {% (utils/loop-tasks (args :worked-tasks)
                             (and (>= (w :start) (get-in args [:interval :start]))
                                  (<= (w :end) (or (get-in args [:interval :end]) (os/time))))
                             (args :clients) (args :projects)) %}
    </tbody>
  </table>
</vstack>