File tree Expand file tree Collapse file tree 4 files changed +40
-12
lines changed Expand file tree Collapse file tree 4 files changed +40
-12
lines changed Original file line number Diff line number Diff line change 137
137
[?emoji :emoji/url ?url]]
138
138
db)))
139
139
140
- (defn message-stats -between-days [db from-date to-date ]
141
- (d/q '[:find ?msg ?day
142
- :in $ ?from-date ?to-date
140
+ (defn unique-users -between-days [db from-day to-day ]
141
+ (d/q '[:find ( count ?user)
142
+ :in $ ?from-day ?to-day
143
143
:where
144
+ [?msg :message/user ?user]
144
145
[?msg :message/day ?day]
145
- [(> ?day ?from-date )]
146
- [(< ?day ?to-date )]]
146
+ [(> ?day ?from-day )]
147
+ [(< ?day ?to-day )]]
147
148
db
148
- from-date
149
- to-date))
149
+ from-day
150
+ to-day))
151
+
152
+ (defn message-stats-between-days [from-day to-day]
153
+ (letfn [(day-chan-cnt [] (:day-chan-cnt @!indexes))
154
+ (day-total [day] (apply + (vals (get (day-chan-cnt ) day))))
155
+ (days-total [days] (transduce (map day-total) + 0 days))]
156
+ (mapv #(hash-map :day % :msg-count (day-total %)) (time-util/range-of-days from-day to-day))))
150
157
151
158
#_
152
159
(doseq [v [#'clojurians-log.db.queries/user-names
Original file line number Diff line number Diff line change 145
145
response/xml-render)))
146
146
147
147
(defn message-stats-route [{:keys [endpoint] :as request}]
148
- (let [config @(get-in endpoint [:config :value ])
149
- db (db-from-endpoint endpoint)
148
+ (let [config @(get-in endpoint [:config :value ])
150
149
{:keys [from-date to-date]} (:path-params request)]
151
150
(-> request
152
151
make-context
153
- (assoc :data/message-stats (queries/message-stats-between-days db from-date to-date))
152
+ (assoc :data/message-stats (queries/message-stats-between-days from-date to-date))
154
153
views/message-stats-page
155
154
response/render)))
156
155
Original file line number Diff line number Diff line change 2
2
(:require [java-time :as jt]
3
3
[java-time.local :as jt.l]
4
4
[clojure.string :as str])
5
- (:import [java.time Instant]
5
+ (:import [java.time Instant LocalDate ]
6
6
[java.time.format DateTimeFormatter]))
7
7
8
8
(defn ts->inst
81
81
ret# ~expr]
82
82
(prn (str ~label " : " (/ (double (- (. System (nanoTime )) start#)) 1000000.0 ) " msecs" ))
83
83
ret#))
84
+
85
+ (defn range-of-local-dates [^LocalDate ld1 ^LocalDate ld2]
86
+ (when (.isBefore ld1 (.plusDays ld2 1 ))
87
+ (cons ld1 (lazy-seq (range-of-local-dates (.plusDays ld1 1 ) ld2)))))
88
+
89
+ (defn range-of-days
90
+ " Takes 2 day values as a strings and returns range of all days between them inclusive of both"
91
+ [from-day to-day]
92
+ (let [ld1 (java.time.LocalDate/parse from-day)
93
+ ld2 (java.time.LocalDate/parse to-day)]
94
+ (map str (range-of-local-dates ld1 ld2))))
Original file line number Diff line number Diff line change 288
288
289
289
(defn- message-stats-page-html [{:data/keys [message-stats] :as context}]
290
290
[:div
291
- (for [[a b] message-stats] [:p a b])])
291
+ [:h3 (str " Showing message stats between "
292
+ (:day (first message-stats))
293
+ " to "
294
+ (:day (last message-stats)))]
295
+ [:table
296
+ [:thead
297
+ [:tr
298
+ [:th " Day" ]
299
+ [:th " Message count" ]]]
300
+ [:tbody
301
+ (for [day-stat message-stats] [:tr [:td (:day day-stat)] [:td (:msg-count day-stat)]])]]
302
+ [:h4 " Total message count: " (reduce #(+ %1 (:msg-count %2 )) 0 message-stats)]])
292
303
293
304
(defn log-page [context]
294
305
(assoc context :response/html (log-page-html context)))
You can’t perform that action at this time.
0 commit comments