diff options
author | Andrew Cady <d@jerkface.net> | 2022-10-20 15:54:43 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2022-10-20 15:54:43 -0400 |
commit | 23120dee0f5b89ff171bd3db10ddf636fd34d5c7 (patch) | |
tree | 0e02e99e8f466399b750ab89d903b328c03cfcd6 | |
parent | 8113a5ffca4bcb76a2d07c5ebf92abb586cbae0a (diff) |
Revert "remove field names from type Performance"
This reverts commit b11c71b520d03c5c4fed2610a07a13a091440305.
-rwxr-xr-x | repgoal.hs | 20 |
1 files changed, 7 insertions, 13 deletions
@@ -64,16 +64,10 @@ import Brick.Util (fg, bg, on, clamp) | |||
64 | import Brick.Widgets.Core | 64 | import Brick.Widgets.Core |
65 | import Brick.Widgets.Table | 65 | import Brick.Widgets.Table |
66 | 66 | ||
67 | -- data Performance = Achieved { | 67 | data Performance = Achieved { |
68 | -- achievedReps :: Integer, | 68 | achievedReps :: Integer, |
69 | -- achievedWeight :: Rational | 69 | achievedWeight :: Rational |
70 | -- } | 70 | } |
71 | |||
72 | data Performance = Achieved Integer Rational | ||
73 | achievedReps :: Performance -> Integer | ||
74 | achievedWeight :: Performance -> Rational | ||
75 | achievedReps (Achieved r _) = r | ||
76 | achievedWeight (Achieved _ w) = w | ||
77 | 71 | ||
78 | data LiftRecord = LiftRecord { | 72 | data LiftRecord = LiftRecord { |
79 | liftName :: Text, | 73 | liftName :: Text, |
@@ -107,7 +101,7 @@ bestPerformance = head . sortBy (flip $ comparing computeOneRepMax) | |||
107 | -- The formula from Jim Wendler's 5-3-1: | 101 | -- The formula from Jim Wendler's 5-3-1: |
108 | -- 1RM = Weight x Reps x 0.0333 + Weight. | 102 | -- 1RM = Weight x Reps x 0.0333 + Weight. |
109 | computeOneRepMax :: Performance -> Rational | 103 | computeOneRepMax :: Performance -> Rational |
110 | computeOneRepMax a = achievedWeight a * (realToFrac (achievedReps a) * 0.0333 + 1) | 104 | computeOneRepMax Achieved{..} = achievedWeight * (realToFrac achievedReps * 0.0333 + 1) |
111 | 105 | ||
112 | showRational :: Rational -> String | 106 | showRational :: Rational -> String |
113 | showRational n = printf format $ (realToFrac :: Rational -> Float) $ n | 107 | showRational n = printf format $ (realToFrac :: Rational -> Float) $ n |
@@ -120,12 +114,12 @@ drawUI (St lifts _) = [vCenter $ vBox [hCenter oneRepMaxTable, withVScrollBarHan | |||
120 | lastSetTable = renderTable $ table $ map (padLeftRight 1 . str) ["Lift", "Week", "Last Set", "Goal", "Goal+1"] : concatMap toWeekRows lifts | 114 | lastSetTable = renderTable $ table $ map (padLeftRight 1 . str) ["Lift", "Week", "Last Set", "Goal", "Goal+1"] : concatMap toWeekRows lifts |
121 | oneRepMaxTable = renderTable $ table $ map (padLeftRight 1 . str) ["Lift", "Achieved Best", "Computed 1RM"] : map toRow lifts | 115 | oneRepMaxTable = renderTable $ table $ map (padLeftRight 1 . str) ["Lift", "Achieved Best", "Computed 1RM"] : map toRow lifts |
122 | toRow LiftRecord{..} = | 116 | toRow LiftRecord{..} = |
123 | let best = bestPerformance stats | 117 | let best@Achieved{..} = bestPerformance stats |
124 | in | 118 | in |
125 | map (padLeftRight 2) | 119 | map (padLeftRight 2) |
126 | [ | 120 | [ |
127 | txt $ liftName, | 121 | txt $ liftName, |
128 | str $ printf "%d @ %s" (achievedReps best) (showRational $ achievedWeight best), | 122 | str $ printf "%d @ %s" achievedReps (showRational achievedWeight), |
129 | str $ showRational $ computeOneRepMax best | 123 | str $ showRational $ computeOneRepMax best |
130 | ] | 124 | ] |
131 | toWeekRows lift = (flip map) [1,2,3::Int] $ \week -> toWeekRow week lift | 125 | toWeekRows lift = (flip map) [1,2,3::Int] $ \week -> toWeekRow week lift |