summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2022-10-20 14:03:36 -0400
committerAndrew Cady <d@jerkface.net>2022-10-20 14:03:36 -0400
commitb11c71b520d03c5c4fed2610a07a13a091440305 (patch)
tree3d0c3b848dc4eaf6ee2484f6c4025fa3e3b05cf4
parent5ffd7ef978213c79eddfd02328622ff8512972ea (diff)
remove field names from type Performance
-rwxr-xr-xrepgoal.hs20
1 files 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)
63import Brick.Widgets.Core 63import Brick.Widgets.Core
64import Brick.Widgets.Table 64import Brick.Widgets.Table
65 65
66data Performance = Achieved { 66-- data Performance = Achieved {
67 achievedReps :: Integer, 67-- achievedReps :: Integer,
68 achievedWeight :: Rational 68-- achievedWeight :: Rational
69} 69-- }
70
71data Performance = Achieved Integer Rational
72achievedReps :: Performance -> Integer
73achievedWeight :: Performance -> Rational
74achievedReps (Achieved r _) = r
75achievedWeight (Achieved _ w) = w
70 76
71data LiftRecord = LiftRecord { 77data 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.
96computeOneRepMax :: Performance -> Rational 102computeOneRepMax :: Performance -> Rational
97computeOneRepMax Achieved{..} = achievedWeight * (realToFrac achievedReps * 0.0333 + 1) 103computeOneRepMax a = achievedWeight a * (realToFrac (achievedReps a) * 0.0333 + 1)
98 104
99showRational :: Rational -> String 105showRational :: Rational -> String
100showRational n = printf format $ (realToFrac :: Rational -> Float) $ n 106showRational 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