From b11c71b520d03c5c4fed2610a07a13a091440305 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Thu, 20 Oct 2022 14:03:36 -0400 Subject: remove field names from type Performance --- repgoal.hs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/repgoal.hs b/repgoal.hs index 9fb2b18..20c367f 100755 --- a/repgoal.hs +++ b/repgoal.hs @@ -63,10 +63,16 @@ 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 { +-- achievedReps :: Integer, +-- achievedWeight :: Rational +-- } + +data Performance = Achieved Integer Rational +achievedReps :: Performance -> Integer +achievedWeight :: Performance -> Rational +achievedReps (Achieved r _) = r +achievedWeight (Achieved _ w) = w data LiftRecord = LiftRecord { liftName :: Text, @@ -94,7 +100,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 Achieved{..} = achievedWeight * (realToFrac achievedReps * 0.0333 + 1) +computeOneRepMax a = achievedWeight a * (realToFrac (achievedReps a) * 0.0333 + 1) showRational :: Rational -> String showRational n = printf format $ (realToFrac :: Rational -> Float) $ n @@ -107,12 +113,12 @@ drawUI (St lifts) = [vCenter $ vBox [hCenter oneRepMaxTable, hCenter lastSetTabl 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@Achieved{..} = bestPerformance stats + let best = bestPerformance stats in map (padLeftRight 2) [ txt $ liftName, - str $ printf "%d @ %s" achievedReps (showRational achievedWeight), + str $ printf "%d @ %s" (achievedReps best) (showRational $ achievedWeight best), str $ showRational $ computeOneRepMax best ] toWeekRows lift = (flip map) [1,2,3::Int] $ \week -> toWeekRow week lift -- cgit v1.2.3