Skip to content

Commit

Permalink
🔪 reps-per-round (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
theianjones committed Nov 9, 2023
1 parent 94650f9 commit 02ba68e
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 77 deletions.
2 changes: 0 additions & 2 deletions resources/workouts.edn
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
:workout/created-at :db/now
:workout/description "As many rounds as possible in 20 minutes: 5 pull-ups 10 push-ups 15 squats"
:workout/scheme :rounds-reps
:workout/reps-per-round 30
:db/doc-type :workout}
{:xt/id :db.id/diane
:workout/name "Diane"
Expand Down Expand Up @@ -94,7 +93,6 @@
:workout/created-at :db/now
:workout/description "As many rounds as possible in 20 minutes: 5 handstand push-ups 10 one-legged squats 15 pull-ups"
:workout/scheme :rounds-reps
:workout/reps-per-round 30
:db/doc-type :workout}
{:xt/id :db.id/nancy
:workout/name "Nancy"
Expand Down
3 changes: 1 addition & 2 deletions src/com/spicy/repl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@
(biff/submit-tx (get-context)
[{:xt/id cindy
:db/doc-type :workout
:db/op :update
:workout/reps-per-round 30}])
:db/op :update}])


(let [{:keys [biff/db]} (get-context)]
Expand Down
9 changes: 3 additions & 6 deletions src/com/spicy/results/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
conj
(->scores
(merge params
{:reps-per-round (:workout/reps-per-round workout)
:scheme (:workout/scheme workout)
{:scheme (:workout/scheme workout)
:rounds-to-score (:workout/rounds-to-score workout)})))]
(biff/submit-tx ctx
(concat
Expand Down Expand Up @@ -239,8 +238,7 @@
[{:keys [biff/db session params] :as ctx}]
(let [workout-id (parse-uuid (:workout params))
{:workout/keys
[reps-per-round
scheme
[scheme
rounds-to-score] :as _workout} (xt/entity db workout-id)
result-tx [{:db/op :create
:db/doc-type :wod-result
Expand All @@ -258,8 +256,7 @@
conj
(->scores
(merge params
{:reps-per-round reps-per-round
:scheme scheme
{:scheme scheme
:rounds-to-score rounds-to-score})))]

(biff/submit-tx ctx (concat result-tx wod-sets-tx)))
Expand Down
34 changes: 15 additions & 19 deletions src/com/spicy/results/score.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@
(or (n/safe-parse-int reps) 0))


(def ^:const REPS_MULTIPLIER 10000)


(defn rounds-reps->score
[{:keys [rounds reps-per-round] :as params}]
(+ (reps->score params)
(* reps-per-round (n/parse-int rounds))))
[{:keys [rounds] :as params}]
(+ (/ (float (reps->score params)) REPS_MULTIPLIER) (n/parse-int rounds)))


(defn params->score
[{:keys [minutes seconds rounds reps] :as params}]
(cond
(or (some? minutes) (some? seconds)) (time->score params)
(and (some? rounds) (some? reps)) (rounds-reps->score params)
(some? rounds) (n/parse-int rounds)
(some? reps) (n/parse-int reps)
:else nil))

Expand Down Expand Up @@ -63,16 +66,13 @@


(defn ->scores
[{:keys [rounds-to-score reps-per-round scheme]
[{:keys [rounds-to-score]
:as params}]
(->> (range 0 (or rounds-to-score 1))
(mapcat #(->score (assoc params :n %)))
(group-by :index)
vals
(map #(apply merge %))
(mapv #(if (= scheme :rounds-reps)
(assoc % :reps-per-round reps-per-round)
%))))
(map #(apply merge %))))


(defn scores->tx
Expand All @@ -95,12 +95,14 @@
;; => 45
(params->score {:minutes "3" :seconds "45"})
;; => 225
(params->score {:rounds "20" :rounds-multiplier 30})
;; => nil
(params->score {:rounds "20"})
;; => 20

(params->score {:rounds "20" :reps "5"})
;; => 20.005

(params->score {:rounds "20" :reps "5" :rounds-multiplier 30})
;; => 605
(params->score {:reps "42"})
;; => 42

(def p
{:date "2023-07-14",
Expand All @@ -124,7 +126,6 @@

(def p-2
{:rounds-to-score 3
:reps-per-round 100
:date "2023-07-14",
:notes-1 "fell off my pace",
:scale "rx",
Expand Down Expand Up @@ -178,9 +179,4 @@
"idW9AN+yI4rPRh40QkJ+Mz0duX5CxJforNpmO/UzS7khGITLpRVx0/ePsk7PD5bUM46u2V5NwQnyYjWO",
:notes-0 ""})

(->scores p-3)
;; => ({:minutes "16", :index "0", :seconds "33", :notes ""}
;; {:minutes "102", :index "1", :seconds "2", :notes "fell off my pace"}
;; {:minutes "96", :index "2", :seconds "1", :notes "couldnt think anymore"})
;;
(transduce (scores->tx {:op :create :parent :db.id/wod-result}) conj (->scores x)))
(->scores p-3))
22 changes: 10 additions & 12 deletions src/com/spicy/results/score_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

(def params-with-rounds-reps
{:rounds-to-score 3
:reps-per-round 100
:date "2023-07-14"
:notes-1 "fell off my pace"
:scale "rx"
Expand Down Expand Up @@ -58,31 +57,30 @@

(deftest ->scores
(testing "takes params with reps and outputs formated score"
(is (= [{:reps "116" :index 0 :notes ""}
{:reps "102" :index 1 :notes "fell off my pace"}
{:reps "96" :index 2 :notes "couldnt think anymore"}]
(is (= [{:reps "116" :index 0 :notes "" :id nil}
{:reps "102" :index 1 :notes "fell off my pace" :id nil}
{:reps "96" :index 2 :notes "couldnt think anymore" :id nil}]
(sut/->scores params-with-reps))))
(testing "defaults rounds to score to 1"
(is (= [{:reps "116" :index 0 :notes ""}]
(is (= [{:reps "116" :index 0 :notes "" :id nil}]
(sut/->scores (dissoc params-with-reps :rounds-to-score)))))
(testing "takes params with rounds and reps"
(is (= [{:rounds "3" :index 0 :reps "116" :notes "" :reps-per-round 100}
(is (= [{:rounds "3" :index 0 :reps "116" :notes "" :id nil}
{:rounds "2"
:index 1
:reps "102"
:notes "fell off my pace"
:reps-per-round 100}
:id nil}
{:rounds "1"
:index 2
:reps "96"
:notes "couldnt think anymore"
:reps-per-round 100}]
:notes "couldnt think anymore" :id nil}]
(sut/->scores params-with-rounds-reps))))
(testing "takes params with minutes seconds"
(is (= [{:minutes "16" :index 0 :seconds "33" :notes ""}
{:minutes "102" :index 1 :seconds "2" :notes "fell off my pace"}
(is (= [{:minutes "16" :index 0 :seconds "33" :notes "" :id nil}
{:minutes "102" :index 1 :seconds "2" :notes "fell off my pace" :id nil}
{:minutes "96"
:index 2
:seconds "1"
:notes "couldnt think anymore"}]
:notes "couldnt think anymore" :id nil}]
(sut/->scores params-with-minutes-seconds)))))
1 change: 1 addition & 0 deletions src/com/spicy/results/ui.clj
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
:placeholder "Reps"
:value reps
:min 0
:max 9999
:required true}]])
[:input.w-full.pink-input.teal-focus {:type "number"
:name (str "reps-" identifier)
Expand Down
3 changes: 2 additions & 1 deletion src/com/spicy/schema.clj
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
(def WodSet
[:map
[:xt/id :wod-set/id]
[:result-set/score :int]
[:result-set/score float?]
[:result-set/number :int]
[:result-set/parent :wod-result/id]])

Expand Down Expand Up @@ -99,6 +99,7 @@
[:workout/reps-per-round {:optional true} :int]
[:workout/rounds-to-score {:optional true} :int]
[:workout/user {:optional true} :user/id]
[:workout/sugar-id {:optional true} :string]
[:workout/tiebreak-scheme {:optional true} [:enum :time :reps]]
[:workout/secondary-scheme {:optional true} (into [] (filter #(not (= :time-with-cap %)) workout-types))]]
:strength-set/id :uuid
Expand Down
17 changes: 0 additions & 17 deletions src/com/spicy/workouts/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,6 @@
:workout/name (:name params)
:workout/scheme (keyword (:scheme params))
:workout/description (:description params)}
(when
(:reps-per-round params)
{:workout/reps-per-round
(n/safe-parse-int (:reps-per-round params))})
(when
(:rounds params)
{:workout/rounds-to-score
Expand Down Expand Up @@ -214,10 +210,6 @@
:workout/scheme (keyword (:scheme params))
:workout/created-at :db/now
:workout/description (:description params)}
(when
(:reps-per-round params)
{:workout/reps-per-round
(n/safe-parse-int (:reps-per-round params))})
(when
(:rounds params)
{:workout/rounds-to-score
Expand Down Expand Up @@ -337,14 +329,6 @@
:hx-target "#selected-movements"} name]) results)]))


(defn get-scheme-inputs
[{:keys [params] :as _ctx}]
(case (:scheme params)
"rounds-reps" [:div#scheme-inputs [:input.w-full.pink-input.p-2.teal-focus#reps-per-round
{:placeholder "Reps per round" :name "reps-per-round" :required true}]]
[:div.hidden#scheme-inputs]))


(defn get-score-separately
[{:keys [params] :as _ctx}]
(if (= "on" (:score-separately params))
Expand All @@ -371,7 +355,6 @@
["/new/selected" {:get show-selected-movement
:post set-selected-movement
:delete remove-selected-movement}]
["/new/scheme-inputs" {:get get-scheme-inputs}]
["/new/score-separately" {:get get-score-separately}]])


Expand Down
31 changes: 13 additions & 18 deletions src/com/spicy/workouts/ui.clj
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
(ns com.spicy.workouts.ui
(:require
[com.biffweb :as biff :refer [q]]
[com.biffweb :as biff]
[com.spicy.results.score :refer [REPS_MULTIPLIER]]
[com.spicy.time :as t]
[com.spicy.ui :as ui]))


(defn ->rounds-reps
[reps-per-round reps]
(if (> 0 reps)
"0+0"
(str (quot reps reps-per-round)
"+"
(rem reps reps-per-round))))
[reps-per-round score]
(if (int? score)
(if (> 0 score)
"0+0"
(str (quot score reps-per-round)
"+"
(rem score reps-per-round)))
(let [rounds (.intValue score)
reps (.intValue (* REPS_MULTIPLIER (- (bigdec score) rounds)))]
(str rounds "+" reps))))


(comment
Expand All @@ -37,7 +42,7 @@


(defn display-summed-score
[{:keys [workout sets] :as a}]
[{:keys [workout sets] :as _a}]
(when (and (not-empty workout)
(not-empty sets))
(display-score (merge {:workout workout} {:result-set (merge-set-score-with sets +)}))))
Expand Down Expand Up @@ -124,9 +129,6 @@
[:select.pink-input.teal-focus#scheme
{:name "scheme"
:required true
:hx-get "/app/workouts/new/scheme-inputs"
:hx-target "#scheme-inputs"
:hx-swap "outerHTML"
:value (when (not (nil? workout)) (name (:workout/scheme workout)))}
[:option {:value "" :label "--Select a Workout Scheme--"}]
[:option {:value "time"
Expand All @@ -147,13 +149,6 @@
:label "feet"}]
[:option {:value "points"
:label "points"}]]]
(if (= :rounds-reps (:workout/scheme workout))
[:div#scheme-inputs
[:div.flex.flex-col.w-full
[:label {:for :reps-per-round} "Reps per round"]
[:input.w-full.pink-input.p-2.teal-focus#reps-per-round
{:placeholder "Reps per round" :name "reps-per-round" :required true}]]]
[:div.hidden#scheme-inputs])
[:div.flex.gap-3.items-center
[:label "Score rounds separately?"]
[:input#score-separately
Expand Down

0 comments on commit 02ba68e

Please sign in to comment.