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