summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2022-10-28 21:51:15 -0400
committerAndrew Cady <d@jerkface.net>2022-10-28 21:51:15 -0400
commit2ae1c7299c67be911058692be3a645bb02067934 (patch)
tree5d5d637b9f768fd133ec60258a260f554e304248
parentd1b85bedbc06f258ad23961c4f5b5a4de011d5d8 (diff)
show plate counts; empty fields for date, time, bodyweight
-rwxr-xr-xrepgoal.hs28
1 files changed, 24 insertions, 4 deletions
diff --git a/repgoal.hs b/repgoal.hs
index 0ceaf46..dc5227e 100755
--- a/repgoal.hs
+++ b/repgoal.hs
@@ -106,6 +106,11 @@ bestPerformance = head . sortBy (flip $ comparing computeOneRepMax)
106computeOneRepMax :: Performance -> Rational 106computeOneRepMax :: Performance -> Rational
107computeOneRepMax Achieved{..} = toRational achievedWeight * (realToFrac achievedReps * 0.0333 + 1) 107computeOneRepMax Achieved{..} = toRational achievedWeight * (realToFrac achievedReps * 0.0333 + 1)
108 108
109showRational' :: Rational -> String
110showRational' n = printf format $ (realToFrac :: Rational -> Float) $ n
111 where
112 format = if floor (n * 10) `mod` 10 == (0 :: Integer) then "%.0f" else "%.1f"
113
109showRational :: Rational -> String 114showRational :: Rational -> String
110showRational n = printf format $ (realToFrac :: Rational -> Float) $ n 115showRational n = printf format $ (realToFrac :: Rational -> Float) $ n
111 where 116 where
@@ -157,12 +162,16 @@ lookup' :: Int -> NESeq a -> a
157lookup' i seq = fromJust $ NESeq.lookup (i `mod` NESeq.length seq) seq 162lookup' i seq = fromJust $ NESeq.lookup (i `mod` NESeq.length seq) seq
158 163
159drawUI :: St -> [Widget ()] 164drawUI :: St -> [Widget ()]
160drawUI st = [vCenter $ vBox [hCenter oneRepMaxTable, header, withVScrollBarHandles $ withVScrollBars OnRight $ viewport () Vertical $ hCenter lastSetTable]] 165drawUI st = [vCenter $ vBox [hCenter $ hBox [header, oneRepMaxTable], withVScrollBarHandles $ withVScrollBars OnRight $ viewport () Vertical $ hCenter lastSetTable]]
161 where 166 where
162 lifts' = filter ((flip Set.member $ view sessions st & lookup' (view selectedSession st)) . liftName) (view lifts st) 167 lifts' = filter ((flip Set.member $ view sessions st & lookup' (view selectedSession st)) . liftName) (view lifts st)
163 lastSetTable = renderTable $ table $ map (padLeftRight 1 . str) ["Lift", "Set", "Goal", "Done", "Rest"] : concatMap (toLiftRows (view week st)) lifts' 168 lastSetTable = renderTable $ table $ map (padLeftRight 1 . txt) ["Lift", "Set", "Plates", "Goal", "Done", "Rest"] : concatMap (toLiftRows (view week st)) lifts'
164 header = str $ "Week " ++ case (view week st) of Week1 -> "1"; Week2 -> "2"; Week3 -> "3" 169 header = renderTable $ table $ map (padLeftRight 1 . txt)
165 oneRepMaxTable = renderTable $ table $ map (padLeftRight 1 . str) ["Lift", "Achieved Best", "Computed 1RM"] : map toRow lifts' 170 ["Date", "Time", "Bodyweight", "Week", "Session"]
171 : [ map (padLeftRight 2 . txt) [" ", " ", " ", weekNumber, sessionName] ]
172 weekNumber = case (view week st) of Week1 -> "1"; Week2 -> "2"; Week3 -> "3"
173 sessionName = liftName $ head lifts'
174 oneRepMaxTable = renderTable $ table $ map (padLeftRight 1 . txt) ["Lift", "Achieved Best", "Computed 1RM"] : map toRow lifts'
166 toRow LiftRecord{..} = 175 toRow LiftRecord{..} =
167 let best@Achieved{..} = bestPerformance stats 176 let best@Achieved{..} = bestPerformance stats
168 in 177 in
@@ -188,11 +197,22 @@ drawUI st = [vCenter $ vBox [hCenter oneRepMaxTable, header, withVScrollBarHandl
188 -- txt $ if position == FirstInList then liftName else " ", 197 -- txt $ if position == FirstInList then liftName else " ",
189 txt $ case position of FirstInList -> liftName; NotFirstInList -> if amrap then " \n " else " ", 198 txt $ case position of FirstInList -> liftName; NotFirstInList -> if amrap then " \n " else " ",
190 str $ printf "%2d%s @ %d%s" targetReps (if amrap then "+" else "" :: Text) targetWeight (if amrap then "\n " else "" :: String), 199 str $ printf "%2d%s @ %d%s" targetReps (if amrap then "+" else "" :: Text) targetWeight (if amrap then "\n " else "" :: String),
200 str $ showPlates targetWeight ++ if amrap then "\n " else "",
191 str $ if amrap then showGoal repGoal ++ "\n" ++ showGoal (repGoal + 1) else " ", 201 str $ if amrap then showGoal repGoal ++ "\n" ++ showGoal (repGoal + 1) else " ",
192 txt $ if amrap then " \n " else " ", 202 txt $ if amrap then " \n " else " ",
193 txt $ if amrap then " \n " else " " 203 txt $ if amrap then " \n " else " "
194 ] 204 ]
195 205
206showPlates (fromIntegral -> wt) = fromMaybe "unavailable" $ fmap (ourShow . reverse) $ showPlates' (wt - 45) ourPlates []
207 where
208 ourPlates = [45,45,25,25,10,10,10,5,5,2.5]
209 ourShow :: [Rational] -> String
210 ourShow = concat . intersperse " " . map showRational'
211 showPlates' 0 _ used = Just used
212 showPlates' need (have:avail) used | have * 2 > need = showPlates' need avail used
213 showPlates' need (have:avail) used = showPlates' (need - have * 2) avail (have:used)
214 showPlates' _ _ _ = Nothing
215
196ceilingN :: Integer -> Rational -> Integer 216ceilingN :: Integer -> Rational -> Integer
197ceilingN n x = ceiling (x / toRational n) * n 217ceilingN n x = ceiling (x / toRational n) * n
198 218