diff options
Diffstat (limited to 'repgoal.hs')
-rwxr-xr-x | repgoal.hs | 28 |
1 files changed, 24 insertions, 4 deletions
@@ -106,6 +106,11 @@ bestPerformance = head . sortBy (flip $ comparing computeOneRepMax) | |||
106 | computeOneRepMax :: Performance -> Rational | 106 | computeOneRepMax :: Performance -> Rational |
107 | computeOneRepMax Achieved{..} = toRational achievedWeight * (realToFrac achievedReps * 0.0333 + 1) | 107 | computeOneRepMax Achieved{..} = toRational achievedWeight * (realToFrac achievedReps * 0.0333 + 1) |
108 | 108 | ||
109 | showRational' :: Rational -> String | ||
110 | showRational' n = printf format $ (realToFrac :: Rational -> Float) $ n | ||
111 | where | ||
112 | format = if floor (n * 10) `mod` 10 == (0 :: Integer) then "%.0f" else "%.1f" | ||
113 | |||
109 | showRational :: Rational -> String | 114 | showRational :: Rational -> String |
110 | showRational n = printf format $ (realToFrac :: Rational -> Float) $ n | 115 | showRational n = printf format $ (realToFrac :: Rational -> Float) $ n |
111 | where | 116 | where |
@@ -157,12 +162,16 @@ lookup' :: Int -> NESeq a -> a | |||
157 | lookup' i seq = fromJust $ NESeq.lookup (i `mod` NESeq.length seq) seq | 162 | lookup' i seq = fromJust $ NESeq.lookup (i `mod` NESeq.length seq) seq |
158 | 163 | ||
159 | drawUI :: St -> [Widget ()] | 164 | drawUI :: St -> [Widget ()] |
160 | drawUI st = [vCenter $ vBox [hCenter oneRepMaxTable, header, withVScrollBarHandles $ withVScrollBars OnRight $ viewport () Vertical $ hCenter lastSetTable]] | 165 | drawUI 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 | ||
206 | showPlates (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 | |||
196 | ceilingN :: Integer -> Rational -> Integer | 216 | ceilingN :: Integer -> Rational -> Integer |
197 | ceilingN n x = ceiling (x / toRational n) * n | 217 | ceilingN n x = ceiling (x / toRational n) * n |
198 | 218 | ||