diff options
author | Andrew Cady <d@jerkface.net> | 2022-10-14 16:51:25 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2022-10-14 16:51:25 -0400 |
commit | 3631e79b5ad9ebbc72aef5a52ec1e2047af4798e (patch) | |
tree | ebd08065dc12414fee905465dd8edefe1bb0dc93 /repgoal.hs | |
parent | fc01200eddc019b2eb3af48cb2c1a23e0be88560 (diff) |
eliminate redundant "targetWeight" field
Diffstat (limited to 'repgoal.hs')
-rwxr-xr-x | repgoal.hs | 44 |
1 files changed, 17 insertions, 27 deletions
@@ -68,23 +68,22 @@ data Performance = Achieved { | |||
68 | achievedWeight :: Rational | 68 | achievedWeight :: Rational |
69 | } | 69 | } |
70 | 70 | ||
71 | data LiftTarget = LiftTarget { | 71 | data LiftRecord = LiftRecord { |
72 | liftName :: Text, | 72 | liftName :: Text, |
73 | targetWeight :: Rational, | ||
74 | stats :: [Performance] | 73 | stats :: [Performance] |
75 | } | 74 | } |
76 | 75 | ||
77 | initial :: [LiftTarget] | 76 | initial :: [LiftRecord] |
78 | initial = | 77 | initial = |
79 | [ | 78 | [ |
80 | LiftTarget "Squat" 255 [Achieved 6 270, Achieved 8 255, Achieved 5 285, Achieved 10 255], | 79 | LiftRecord "Squat" [Achieved 6 270, Achieved 8 255, Achieved 5 285, Achieved 10 255], |
81 | LiftTarget "Bench" 180 [Achieved 7 190, Achieved 9 180, Achieved 4 205, Achieved 11 180], | 80 | LiftRecord "Bench" [Achieved 7 190, Achieved 9 180, Achieved 4 205, Achieved 11 180], |
82 | LiftTarget "Deadlift" 340 [Achieved 5 360, Achieved 9 315, Achieved 8 345, Achieved 7 360], | 81 | LiftRecord "Deadlift" [Achieved 5 360, Achieved 9 315, Achieved 8 345, Achieved 7 360], |
83 | LiftTarget "Press" 120 [Achieved 6 130, Achieved 9 120, Achieved 4 135] | 82 | LiftRecord "Press" [Achieved 6 130, Achieved 9 120, Achieved 4 135] |
84 | ] | 83 | ] |
85 | 84 | ||
86 | computeRepGoal :: LiftTarget -> (Integer) | 85 | computeRepGoal :: Rational -> [Performance] -> (Integer) |
87 | computeRepGoal LiftTarget{..} = head $ filter isPR [2..] | 86 | computeRepGoal targetWeight stats = head $ filter isPR [2..] |
88 | where | 87 | where |
89 | isPR n = computeOneRepMax (Achieved n targetWeight) > computeOneRepMax (bestPerformance stats) | 88 | isPR n = computeOneRepMax (Achieved n targetWeight) > computeOneRepMax (bestPerformance stats) |
90 | 89 | ||
@@ -106,7 +105,7 @@ drawUI (St lifts) = [vCenter $ vBox [hCenter oneRepMaxTable, hCenter lastSetTabl | |||
106 | where | 105 | where |
107 | lastSetTable = renderTable $ table $ map (padLeftRight 1 . str) ["Lift", "Week", "Last Set", "Goal", "Goal+1"] : concatMap toWeekRows lifts | 106 | lastSetTable = renderTable $ table $ map (padLeftRight 1 . str) ["Lift", "Week", "Last Set", "Goal", "Goal+1"] : concatMap toWeekRows lifts |
108 | oneRepMaxTable = renderTable $ table $ map (padLeftRight 1 . str) ["Lift", "Achieved Best", "Computed 1RM"] : map toRow lifts | 107 | oneRepMaxTable = renderTable $ table $ map (padLeftRight 1 . str) ["Lift", "Achieved Best", "Computed 1RM"] : map toRow lifts |
109 | toRow LiftTarget{..} = | 108 | toRow LiftRecord{..} = |
110 | let best@Achieved{..} = bestPerformance stats | 109 | let best@Achieved{..} = bestPerformance stats |
111 | in | 110 | in |
112 | map (padLeftRight 2) | 111 | map (padLeftRight 2) |
@@ -116,11 +115,13 @@ drawUI (St lifts) = [vCenter $ vBox [hCenter oneRepMaxTable, hCenter lastSetTabl | |||
116 | str $ showRational $ computeOneRepMax best | 115 | str $ showRational $ computeOneRepMax best |
117 | ] | 116 | ] |
118 | toWeekRows lift = (flip map) [1,2,3::Int] $ \week -> toWeekRow week lift | 117 | toWeekRows lift = (flip map) [1,2,3::Int] $ \week -> toWeekRow week lift |
119 | toWeekRow :: Int -> LiftTarget -> [Widget n] | 118 | toWeekRow :: Int -> LiftRecord -> [Widget n] |
120 | toWeekRow week target@LiftTarget{..} = | 119 | toWeekRow week LiftRecord{..} = |
121 | let best = bestPerformance stats | 120 | let best = bestPerformance stats |
122 | programWeight = (* (percentage week)) $ (* (90 % 100)) $ computeOneRepMax best | 121 | targetReps = case week of 1 -> 5; 2 -> 3; 3 -> 1; _ -> undefined :: Int |
123 | repGoal = computeRepGoal target | 122 | targetPercentage = case week of 1 -> 85; 2 -> 90; 3 -> 95; _ -> undefined |
123 | targetWeight = (* (targetPercentage % 100)) $ (* (90 % 100)) $ computeOneRepMax best | ||
124 | repGoal = computeRepGoal targetWeight stats | ||
124 | goalTo1RM g = computeOneRepMax $ Achieved g targetWeight | 125 | goalTo1RM g = computeOneRepMax $ Achieved g targetWeight |
125 | showGoal g = printf "%d @ %s ≈ 1 @ %s" g (showRational targetWeight) (showRational (goalTo1RM g)) | 126 | showGoal g = printf "%d @ %s ≈ 1 @ %s" g (showRational targetWeight) (showRational (goalTo1RM g)) |
126 | in | 127 | in |
@@ -128,30 +129,19 @@ drawUI (St lifts) = [vCenter $ vBox [hCenter oneRepMaxTable, hCenter lastSetTabl | |||
128 | [ | 129 | [ |
129 | txt $ (if week == 1 then liftName else " "), | 130 | txt $ (if week == 1 then liftName else " "), |
130 | str $ show week, | 131 | str $ show week, |
131 | str $ printf "%d @ %d" (targetReps week) (ceilingN 5 programWeight), | 132 | str $ printf "%d @ %d" targetReps (ceilingN 5 targetWeight), |
132 | -- str $ showRational $ (* (percentage week)) $ (* (90 % 100)) $ computeOneRepMax best, | 133 | -- str $ showRational $ (* (percentage week)) $ (* (90 % 100)) $ computeOneRepMax best, |
133 | str $ showGoal repGoal, | 134 | str $ showGoal repGoal, |
134 | str $ showGoal (repGoal + 1) | 135 | str $ showGoal (repGoal + 1) |
135 | ] | 136 | ] |
136 | 137 | ||
137 | targetReps :: Int -> Int | ||
138 | targetReps 1 = 5 | ||
139 | targetReps 2 = 3 | ||
140 | targetReps 3 = 1 | ||
141 | targetReps _ = undefined | ||
142 | |||
143 | percentage 1 = 85 % 100 | ||
144 | percentage 2 = 90 % 100 | ||
145 | percentage 3 = 95 % 100 | ||
146 | percentage _ = undefined | ||
147 | |||
148 | ceilingN :: Integer -> Rational -> Integer | 138 | ceilingN :: Integer -> Rational -> Integer |
149 | ceilingN n x = ceiling (x / toRational n) * n | 139 | ceilingN n x = ceiling (x / toRational n) * n |
150 | 140 | ||
151 | -- TODO: State contains chosen repmax formula | 141 | -- TODO: State contains chosen repmax formula |
152 | -- TODO: State contains performances | 142 | -- TODO: State contains performances |
153 | data St = St { | 143 | data St = St { |
154 | lifts :: [LiftTarget] | 144 | lifts :: [LiftRecord] |
155 | } | 145 | } |
156 | 146 | ||
157 | -- TODO: Event for inotify on edited text file (as input interface) | 147 | -- TODO: Event for inotify on edited text file (as input interface) |