diff options
author | Andrew Cady <d@jerkface.net> | 2022-10-23 16:28:10 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2022-10-23 16:28:10 -0400 |
commit | e1637fca91750197d93f47614919f60227c61fa4 (patch) | |
tree | f7c756ea1c864af0de8808b3c07437765526271a | |
parent | 63d0ea047dbdd5bc3f53d3fa853d97886ec74319 (diff) |
show separate workout routines
TODO: don't use Set, since we need to preserve order
TODO: support iterating backward
TODO: support a title, display it along with week (e.g., "Week 1, Monday AM")
-rwxr-xr-x | repgoal.hs | 22 |
1 files changed, 18 insertions, 4 deletions
@@ -16,6 +16,9 @@ | |||
16 | {-# language DerivingVia #-} | 16 | {-# language DerivingVia #-} |
17 | import Rebase.Prelude hiding (toList, on, (<+>), Max) | 17 | import Rebase.Prelude hiding (toList, on, (<+>), Max) |
18 | import qualified Rebase.Prelude as Prelude | 18 | import qualified Rebase.Prelude as Prelude |
19 | import qualified Data.Set as Set | ||
20 | import qualified Data.List.NonEmpty as NonEmpty | ||
21 | import Data.List.NonEmpty (NonEmpty) | ||
19 | import Control.Lens hiding ((<|)) | 22 | import Control.Lens hiding ((<|)) |
20 | import Data.Foldable (toList) | 23 | import Data.Foldable (toList) |
21 | import Data.Ratio | 24 | import Data.Ratio |
@@ -127,7 +130,8 @@ data WeekSelection = Week1 | Week2 | Week3 deriving (Enum, Bounded, Show, Eq) | |||
127 | -- TODO: State contains performances | 130 | -- TODO: State contains performances |
128 | data St = St { | 131 | data St = St { |
129 | _lifts :: [LiftRecord], | 132 | _lifts :: [LiftRecord], |
130 | _week :: WeekSelection | 133 | _week :: WeekSelection, |
134 | _routines :: NonEmpty (Set Text) | ||
131 | } | 135 | } |
132 | makeLenses ''St | 136 | makeLenses ''St |
133 | 137 | ||
@@ -165,9 +169,10 @@ annotatePosition (x:xs) = (FirstInList, x) : annotateRest xs | |||
165 | drawUI :: St -> [Widget ()] | 169 | drawUI :: St -> [Widget ()] |
166 | drawUI st = [vCenter $ vBox [hCenter oneRepMaxTable, header, withVScrollBarHandles $ withVScrollBars OnRight $ viewport () Vertical $ hCenter lastSetTable]] | 170 | drawUI st = [vCenter $ vBox [hCenter oneRepMaxTable, header, withVScrollBarHandles $ withVScrollBars OnRight $ viewport () Vertical $ hCenter lastSetTable]] |
167 | where | 171 | where |
168 | lastSetTable = renderTable $ table $ map (padLeftRight 1 . str) ["Lift", "Set", "Goal"] : concatMap (toLiftRows (view week st)) (view lifts st) | 172 | lifts' = filter ((flip Set.member $ view routines st & NonEmpty.head) . liftName) (view lifts st) |
173 | lastSetTable = renderTable $ table $ map (padLeftRight 1 . str) ["Lift", "Set", "Goal"] : concatMap (toLiftRows (view week st)) lifts' | ||
169 | header = str $ "Week " ++ case (view week st) of Week1 -> "1"; Week2 -> "2"; Week3 -> "3" | 174 | header = str $ "Week " ++ case (view week st) of Week1 -> "1"; Week2 -> "2"; Week3 -> "3" |
170 | oneRepMaxTable = renderTable $ table $ map (padLeftRight 1 . str) ["Lift", "Achieved Best", "Computed 1RM"] : map toRow (view lifts st) | 175 | oneRepMaxTable = renderTable $ table $ map (padLeftRight 1 . str) ["Lift", "Achieved Best", "Computed 1RM"] : map toRow lifts' |
171 | toRow LiftRecord{..} = | 176 | toRow LiftRecord{..} = |
172 | let best@Achieved{..} = bestPerformance stats | 177 | let best@Achieved{..} = bestPerformance stats |
173 | in | 178 | in |
@@ -211,6 +216,7 @@ handleEvent st e = case e of | |||
211 | VtyEvent (V.EvKey V.KDown _) -> M.vScrollBy (M.viewportScroll ()) 5 >> continue st | 216 | VtyEvent (V.EvKey V.KDown _) -> M.vScrollBy (M.viewportScroll ()) 5 >> continue st |
212 | VtyEvent (V.EvKey V.KUp _) -> M.vScrollBy (M.viewportScroll ()) (-5) >> continue st | 217 | VtyEvent (V.EvKey V.KUp _) -> M.vScrollBy (M.viewportScroll ()) (-5) >> continue st |
213 | VtyEvent (V.EvKey (V.KChar 'w') _) -> continue $ st & week %~ succ' | 218 | VtyEvent (V.EvKey (V.KChar 'w') _) -> continue $ st & week %~ succ' |
219 | VtyEvent (V.EvKey (V.KChar 'n') _) -> continue $ st & routines %~ (NonEmpty.fromList . NonEmpty.tail) | ||
214 | VtyEvent _ -> continue st | 220 | VtyEvent _ -> continue st |
215 | AppEvent _ -> continue st | 221 | AppEvent _ -> continue st |
216 | _ -> continue st | 222 | _ -> continue st |
@@ -243,6 +249,14 @@ powerClean = clean * 80 / 100 | |||
243 | pushPress = press * 100 / 75 | 249 | pushPress = press * 100 / 75 |
244 | jerk = pushPress / 100 * 85 | 250 | jerk = pushPress / 100 * 85 |
245 | 251 | ||
252 | routine :: NonEmpty (Set Text) | ||
253 | routine = NonEmpty.cycle $ | ||
254 | Set.fromList ["Deadlift", "Press"] :| | ||
255 | [Set.fromList ["Front Squat", "Left-Arm Snatch", "Right-Arm Snatch"] | ||
256 | , Set.fromList ["Squat", "Bench"] | ||
257 | , Set.fromList ["Push Press", "Power Clean"] | ||
258 | ] | ||
259 | |||
246 | main, main' :: IO () | 260 | main, main' :: IO () |
247 | main' = pPrint initial' | 261 | main' = pPrint initial' |
248 | main = do | 262 | main = do |
@@ -251,4 +265,4 @@ main = do | |||
251 | -- liftIO $ setMode (outputIface vty) Mouse True | 265 | -- liftIO $ setMode (outputIface vty) Mouse True |
252 | chan <- newBChan 10 | 266 | chan <- newBChan 10 |
253 | initial <- read <$> readFile "lifts.dat" :: IO [LiftRecord] | 267 | initial <- read <$> readFile "lifts.dat" :: IO [LiftRecord] |
254 | void $ customMain vty buildVty (Just chan) (theApp) (St initial Week1) | 268 | void $ customMain vty buildVty (Just chan) (theApp) (St initial Week1 routine) |