From 6dadca779691ae29c5a2bbfb4f2c2d101ca44911 Mon Sep 17 00:00:00 2001 From: Logan Hunt Date: Sat, 4 Jun 2022 13:09:39 -0700 Subject: Added more CLI options --- database/run.lisp | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) (limited to 'database/run.lisp') diff --git a/database/run.lisp b/database/run.lisp index d474426..3166041 100644 --- a/database/run.lisp +++ b/database/run.lisp @@ -1,6 +1,5 @@ (mito:deftable run () - ((category :col-type category) - (end-date :col-type (or :datetime :null))) + ((category :col-type category)) (:record-timestamps nil) (:conc-name run-)) @@ -13,12 +12,15 @@ (:conc-name run-split-)) - (defun run-splits (run) (mito:select-dao 'run-split (sxql:order-by :category_split_id) (sxql:where (:= :run run)))) +(defun delete-run (run) + (let ((splits (run-splits run))) + (mapcar 'mito:delete-dao (cons run splits)))) + ;; 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) @@ -41,20 +43,20 @@ ,@body))) (defun best-category-run (category) - (query-with-runs-elapsed - (sxql:inner-join :run :on (:= :run_id :run.id)) - (sxql:order-by :elapsed) - (sxql:limit 1) - (sxql:where (:= :category_id (mito:object-id category))))) + (car (query-with-runs-elapsed + (sxql:inner-join :run :on (:= :run_id :run.id)) + (sxql:order-by :elapsed) + (sxql:limit 1) + (sxql:where (:= :category_id (mito:object-id category)))))) (defun best-category-split (category-split) - (query-with-runs-elapsed - (sxql:inner-join :category_split :on (:= :category_split_id :category_split.id)) - (sxql:order-by :elapsed) - (sxql:limit 1) - (sxql:where (:= :category_split_id (mito:object-id category-split))))) + (car (query-with-runs-elapsed + (sxql:inner-join :category_split :on (:= :category_split_id :category_split.id)) + (sxql:order-by :elapsed) + (sxql:limit 1) + (sxql:where (:= :category_split_id (mito:object-id category-split)))))) -(defun list-runs (&key (order-element :end-time) (direction :asc)) +(defun list-runs (&key (order-element :id) (direction :asc)) (query-with-runs-elapsed (sxql:inner-join :run :on (:= :run_id :run.id)) (sxql:inner-join :category :on (:= :category_id :category.id)) @@ -65,3 +67,14 @@ (sxql:inner-join :run :on (:= :run_id :run.id)) (sxql:order-by (list direction order-element)) (sxql:where (:= :category_id (mito:object-id category))))) + + +(defun statistics (category-splits) + `((SPLIT-PBS ,(mapcar (lambda (category) (getf (best-category-split category) :ELAPSED)) csplits)) + (BEST-CATEGORY-RUN-SPLITS ,(or + (mapcar (lambda (split) + (millis-since-internal-timestamp 0 (run-split-elapsed-time split))) + (ignore-errors + (run-splits (mito:find-dao 'run :id (getf (best-category-run category) :RUN-ID))))) + (mapcar (lambda (csplit) nil) csplits))))) + -- cgit v1.2.3-70-g09d2