summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2022-10-23 16:28:10 -0400
committerAndrew Cady <d@jerkface.net>2022-10-23 16:28:10 -0400
commite1637fca91750197d93f47614919f60227c61fa4 (patch)
treef7c756ea1c864af0de8808b3c07437765526271a
parent63d0ea047dbdd5bc3f53d3fa853d97886ec74319 (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-xrepgoal.hs22
1 files changed, 18 insertions, 4 deletions
diff --git a/repgoal.hs b/repgoal.hs
index 94982f1..96cc534 100755
--- a/repgoal.hs
+++ b/repgoal.hs
@@ -16,6 +16,9 @@
16{-# language DerivingVia #-} 16{-# language DerivingVia #-}
17import Rebase.Prelude hiding (toList, on, (<+>), Max) 17import Rebase.Prelude hiding (toList, on, (<+>), Max)
18import qualified Rebase.Prelude as Prelude 18import qualified Rebase.Prelude as Prelude
19import qualified Data.Set as Set
20import qualified Data.List.NonEmpty as NonEmpty
21import Data.List.NonEmpty (NonEmpty)
19import Control.Lens hiding ((<|)) 22import Control.Lens hiding ((<|))
20import Data.Foldable (toList) 23import Data.Foldable (toList)
21import Data.Ratio 24import 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
128data St = St { 131data St = St {
129 _lifts :: [LiftRecord], 132 _lifts :: [LiftRecord],
130 _week :: WeekSelection 133 _week :: WeekSelection,
134 _routines :: NonEmpty (Set Text)
131} 135}
132makeLenses ''St 136makeLenses ''St
133 137
@@ -165,9 +169,10 @@ annotatePosition (x:xs) = (FirstInList, x) : annotateRest xs
165drawUI :: St -> [Widget ()] 169drawUI :: St -> [Widget ()]
166drawUI st = [vCenter $ vBox [hCenter oneRepMaxTable, header, withVScrollBarHandles $ withVScrollBars OnRight $ viewport () Vertical $ hCenter lastSetTable]] 170drawUI 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
243pushPress = press * 100 / 75 249pushPress = press * 100 / 75
244jerk = pushPress / 100 * 85 250jerk = pushPress / 100 * 85
245 251
252routine :: NonEmpty (Set Text)
253routine = 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
246main, main' :: IO () 260main, main' :: IO ()
247main' = pPrint initial' 261main' = pPrint initial'
248main = do 262main = 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)