From 23120dee0f5b89ff171bd3db10ddf636fd34d5c7 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Thu, 20 Oct 2022 15:54:43 -0400 Subject: Revert "remove field names from type Performance" This reverts commit b11c71b520d03c5c4fed2610a07a13a091440305. --- repgoal.hs | 20 +++++++------------- 1 file 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) import Brick.Widgets.Core import Brick.Widgets.Table --- data Performance = Achieved { --- achievedReps :: Integer, --- achievedWeight :: Rational --- } - -data Performance = Achieved Integer Rational -achievedReps :: Performance -> Integer -achievedWeight :: Performance -> Rational -achievedReps (Achieved r _) = r -achievedWeight (Achieved _ w) = w +data Performance = Achieved { + achievedReps :: Integer, + achievedWeight :: Rational +} data LiftRecord = LiftRecord { liftName :: Text, @@ -107,7 +101,7 @@ bestPerformance = head . sortBy (flip $ comparing computeOneRepMax) -- The formula from Jim Wendler's 5-3-1: -- 1RM = Weight x Reps x 0.0333 + Weight. computeOneRepMax :: Performance -> Rational -computeOneRepMax a = achievedWeight a * (realToFrac (achievedReps a) * 0.0333 + 1) +computeOneRepMax Achieved{..} = achievedWeight * (realToFrac achievedReps * 0.0333 + 1) showRational :: Rational -> String showRational n = printf format $ (realToFrac :: Rational -> Float) $ n @@ -120,12 +114,12 @@ drawUI (St lifts _) = [vCenter $ vBox [hCenter oneRepMaxTable, withVScrollBarHan lastSetTable = renderTable $ table $ map (padLeftRight 1 . str) ["Lift", "Week", "Last Set", "Goal", "Goal+1"] : concatMap toWeekRows lifts oneRepMaxTable = renderTable $ table $ map (padLeftRight 1 . str) ["Lift", "Achieved Best", "Computed 1RM"] : map toRow lifts toRow LiftRecord{..} = - let best = bestPerformance stats + let best@Achieved{..} = bestPerformance stats in map (padLeftRight 2) [ txt $ liftName, - str $ printf "%d @ %s" (achievedReps best) (showRational $ achievedWeight best), + str $ printf "%d @ %s" achievedReps (showRational achievedWeight), str $ showRational $ computeOneRepMax best ] toWeekRows lift = (flip map) [1,2,3::Int] $ \week -> toWeekRow week lift -- cgit v1.2.3