From 816ba3e427ce31fd3c6c4b1925f3b8b7da8ba964 Mon Sep 17 00:00:00 2001 From: Logan Hunt Date: Thu, 2 Jun 2022 22:38:43 -0700 Subject: Went back to milliseconds to benefit accuracy over formatting ease. Start and end timestamps for run splits are now based on internal timestamps as well. --- database/run.lisp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'database/run.lisp') diff --git a/database/run.lisp b/database/run.lisp index eba8b81..d474426 100644 --- a/database/run.lisp +++ b/database/run.lisp @@ -1,13 +1,14 @@ (mito:deftable run () - ((category :col-type category)) + ((category :col-type category) + (end-date :col-type (or :datetime :null))) (:record-timestamps nil) (:conc-name run-)) (mito:deftable run-split () ((run :col-type run) (category-split :col-type category-split) - (start-time :col-type (or :datetime :null)) - (end-time :col-type (or :datetime :null))) + (start-timestamp :col-type (or :bigint :null)) + (end-timestamp :col-type (or :bigint :null))) (:record-timestamps nil) (:conc-name run-split-)) @@ -21,22 +22,20 @@ ;; Returns the elapsed time in milliseconds since split started to either ;; current time or the split's end time (defun run-split-elapsed-time (run-split) - (let ((start (ignore-errors (run-split-start-time run-split))) - (end (or (ignore-errors (run-split-end-time run-split)) (local-time:now)))) + (let ((start (ignore-errors (run-split-start-timestamp run-split))) + (end (or (ignore-errors (run-split-end-timestamp run-split)) (get-internal-real-time)))) (if start - (floor (* 100 (local-time:timestamp-difference end start)))))) + (- end start)))) (defun run-split-format-elapsed-time (run-split) (let ((elapsed (run-split-elapsed-time run-split))) (if elapsed - (format-time (make-time-alist elapsed)) + (format-time (make-time-alist (millis-since-internal-timestamp 0 elapsed))) "-"))) - - (defmacro query-with-runs-elapsed (&rest body) `(mito:retrieve-by-sql - (sxql:select (:* (:as (:raw "sum(julianday(end_time) - julianday(start_time))*24*60*60") :elapsed)) + (sxql:select (:* (:as (:sum (:* (:/ (:raw "end_timestamp - CAST(start_timestamp AS REAL)") ,internal-time-units-per-second) 1000)) :elapsed)) (sxql:from :run_split) (sxql:group-by :run_id) ,@body))) -- cgit v1.2.3-70-g09d2