-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add inline edit on workout page #84
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
(ns com.spicy.results.transform | ||
(:require | ||
[clojure.string :as string] | ||
[com.biffweb :as biff] | ||
[com.spicy.movements.core :refer [sets-n-reps]] | ||
[com.spicy.results.score :refer [REPS_MULTIPLIER]] | ||
[com.spicy.time :as t])) | ||
|
||
|
||
(defn ->rounds-reps | ||
[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)))) | ||
|
||
|
||
(defn display-score | ||
[{:keys [result-set workout]}] | ||
(case (:workout/scheme workout) | ||
:rounds-reps (->rounds-reps (:workout/reps-per-round workout) (:result-set/score result-set)) | ||
:time (t/->time (:result-set/score result-set)) | ||
(:result-set/score result-set))) | ||
|
||
|
||
(defn merge-set-score-with | ||
[sets f] | ||
(apply (partial merge-with f) (map #(select-keys % [:result-set/score]) sets))) | ||
|
||
|
||
(defn display-summed-score | ||
[{: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 +)})))) | ||
|
||
|
||
(defn normalized-result | ||
[result] | ||
(let [workout (-> result :result/type :result/workout) | ||
movement (-> result :result/type :result/movement) | ||
sets (-> result :result/type :result-set/_parent) | ||
notes (-> result :result/type :result/notes) | ||
scale (-> result :result/type :result/scale) | ||
description (if (seq workout) | ||
(-> workout :workout/description) | ||
(str (sets-n-reps sets))) | ||
score (if (seq workout) | ||
(display-summed-score {:workout workout | ||
:sets sets}) | ||
(let [best-set (first | ||
(sort-by :result-set/weight > | ||
(filter | ||
#(= :pass (:result-set/status %)) sets)))] | ||
(str (:result-set/reps best-set) "x" (:result-set/weight best-set)))) | ||
name (or (some-> movement | ||
:movement/name | ||
string/capitalize | ||
(str " (" (sets-n-reps sets) ")")) | ||
(:workout/name workout)) | ||
href (if (:workout/name workout) | ||
(str "/app/workouts/" (:xt/id workout)) | ||
(str "/app/movements/" (:xt/id movement)))] | ||
{:workout workout | ||
:movement movement | ||
:sets sets | ||
:href href | ||
:name name | ||
:description description | ||
:notes notes | ||
:score score | ||
:scale scale | ||
:date (biff/format-date (:result/date result) "YYYY-MM-dd")})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[clj-kondo] reported by reviewdog 🐶
unused binding ctx