summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2022-10-20 15:54:43 -0400
committerAndrew Cady <d@jerkface.net>2022-10-20 15:54:43 -0400
commit23120dee0f5b89ff171bd3db10ddf636fd34d5c7 (patch)
tree0e02e99e8f466399b750ab89d903b328c03cfcd6
parent8113a5ffca4bcb76a2d07c5ebf92abb586cbae0a (diff)
Revert "remove field names from type Performance"
This reverts commit b11c71b520d03c5c4fed2610a07a13a091440305.
-rwxr-xr-xrepgoal.hs20
1 files changed, 7 insertions, 13 deletions
diff --git a/repgoal.hs b/repgoal.hs
index 8be74b0..86fba80 100755
--- a/repgoal.hs
+++ b/repgoal.hs
@@ -64,16 +64,10 @@ import Brick.Util (fg, bg, on, clamp)
64import Brick.Widgets.Core 64import Brick.Widgets.Core
65import Brick.Widgets.Table 65import Brick.Widgets.Table
66 66
67-- data Performance = Achieved { 67data Performance = Achieved {
68-- achievedReps :: Integer, 68 achievedReps :: Integer,
69-- achievedWeight :: Rational 69 achievedWeight :: Rational
70-- } 70}
71
72data Performance = Achieved Integer Rational
73achievedReps :: Performance -> Integer
74achievedWeight :: Performance -> Rational
75achievedReps (Achieved r _) = r
76achievedWeight (Achieved _ w) = w
77 71
78data LiftRecord = LiftRecord { 72data 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.
109computeOneRepMax :: Performance -> Rational 103computeOneRepMax :: Performance -> Rational
110computeOneRepMax a = achievedWeight a * (realToFrac (achievedReps a) * 0.0333 + 1) 104computeOneRepMax Achieved{..} = achievedWeight * (realToFrac achievedReps * 0.0333 + 1)
111 105
112showRational :: Rational -> String 106showRational :: Rational -> String
113showRational n = printf format $ (realToFrac :: Rational -> Float) $ n 107showRational 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