summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2022-10-20 16:43:22 -0400
committerAndrew Cady <d@jerkface.net>2022-10-20 16:43:22 -0400
commitb375f0160809c2b64e0dac7cc5182874da6fe327 (patch)
treed563652a47423cbea93615507a7e442e505d972d
parentb968ca23a104c34e84d9c1cf50b85ad745803a14 (diff)
week selection; show one week at a time
-rwxr-xr-xrepgoal.hs48
1 files changed, 28 insertions, 20 deletions
diff --git a/repgoal.hs b/repgoal.hs
index 9265c05..dfd7f6e 100755
--- a/repgoal.hs
+++ b/repgoal.hs
@@ -115,11 +115,25 @@ showRational n = printf format $ (realToFrac :: Rational -> Float) $ n
115 where 115 where
116 format = if floor (n * 10) `mod` 10 == (0 :: Integer) then "%.0f" else "%.2f" 116 format = if floor (n * 10) `mod` 10 == (0 :: Integer) then "%.0f" else "%.2f"
117 117
118data WeekSelection = Week1 | Week2 | Week3 deriving (Enum, Bounded, Show, Eq)
119
120-- TODO: State contains chosen repmax formula
121-- TODO: State contains performances
122data St = St {
123 _lifts :: [LiftRecord],
124 _week :: WeekSelection
125}
126makeLenses ''St
127
128-- TODO: Event for inotify on edited text file (as input interface)
129data CustomEvent = CustomEvent
130
118drawUI :: St -> [Widget ()] 131drawUI :: St -> [Widget ()]
119drawUI (St lifts _) = [vCenter $ vBox [hCenter oneRepMaxTable, withVScrollBarHandles $ withVScrollBars OnRight $ viewport () Vertical $ hCenter lastSetTable]] 132drawUI st = [vCenter $ vBox [hCenter oneRepMaxTable, withVScrollBarHandles $ withVScrollBars OnRight $ viewport () Vertical $ hCenter lastSetTable]]
120 where 133 where
121 lastSetTable = renderTable $ table $ map (padLeftRight 1 . str) ["Lift", "Week", "Last Set", "Goal", "Goal+1"] : concatMap toWeekRows lifts 134 -- lastSetTable = renderTable $ table $ map (padLeftRight 1 . str) ["Lift", "Week", "Last Set", "Goal", "Goal+1"] : concatMap toWeekRows (view lifts st)
122 oneRepMaxTable = renderTable $ table $ map (padLeftRight 1 . str) ["Lift", "Achieved Best", "Computed 1RM"] : map toRow lifts 135 lastSetTable = renderTable $ table $ map (padLeftRight 1 . str) ["Lift", "Week", "Last Set", "Goal", "Goal+1"] : map (toWeekRow (view week st)) (view lifts st)
136 oneRepMaxTable = renderTable $ table $ map (padLeftRight 1 . str) ["Lift", "Achieved Best", "Computed 1RM"] : map toRow (view lifts st)
123 toRow LiftRecord{..} = 137 toRow LiftRecord{..} =
124 let best@Achieved{..} = bestPerformance stats 138 let best@Achieved{..} = bestPerformance stats
125 in 139 in
@@ -129,12 +143,12 @@ drawUI (St lifts _) = [vCenter $ vBox [hCenter oneRepMaxTable, withVScrollBarHan
129 str $ printf "%d @ %d" achievedReps achievedWeight, 143 str $ printf "%d @ %d" achievedReps achievedWeight,
130 str $ showRational $ computeOneRepMax best 144 str $ showRational $ computeOneRepMax best
131 ] 145 ]
132 toWeekRows lift = (flip map) [1,2,3::Int] $ \week -> toWeekRow week lift 146 -- toWeekRows lift = (flip map) [1,2,3::Int] $ \week -> toWeekRow week lift
133 toWeekRow :: Int -> LiftRecord -> [Widget n] 147 toWeekRow :: WeekSelection -> LiftRecord -> [Widget n]
134 toWeekRow week LiftRecord{..} = 148 toWeekRow week LiftRecord{..} =
135 let best = bestPerformance stats 149 let best = bestPerformance stats
136 targetReps = case week of 1 -> 5; 2 -> 3; 3 -> 1; _ -> undefined :: Int 150 targetReps = case week of Week1 -> 5; Week2 -> 3; Week3 -> 1 :: Int
137 targetPercentage = case week of 1 -> 85; 2 -> 90; 3 -> 95; _ -> undefined 151 targetPercentage = case week of Week1 -> 85; Week2 -> 90; Week3 -> 95
138 computedTarget = (* (targetPercentage % 100)) $ (* (90 % 100)) $ computeOneRepMax best 152 computedTarget = (* (targetPercentage % 100)) $ (* (90 % 100)) $ computeOneRepMax best
139 targetWeight = ceilingN 5 computedTarget 153 targetWeight = ceilingN 5 computedTarget
140 repGoal = computeRepGoal targetWeight stats 154 repGoal = computeRepGoal targetWeight stats
@@ -143,8 +157,9 @@ drawUI (St lifts _) = [vCenter $ vBox [hCenter oneRepMaxTable, withVScrollBarHan
143 in 157 in
144 map (padLeftRight 2) 158 map (padLeftRight 2)
145 [ 159 [
146 txt $ (if week == 1 then liftName else " "), 160 -- txt $ (if week == 1 then liftName else " "),
147 str $ show week, 161 txt $ liftName,
162 txt $ case week of Week1 -> "1"; Week2 -> "2"; Week3 -> "3",
148 str $ printf "%2d+ @ %d" targetReps targetWeight, 163 str $ printf "%2d+ @ %d" targetReps targetWeight,
149 str $ showGoal repGoal, 164 str $ showGoal repGoal,
150 str $ showGoal (repGoal + 1) 165 str $ showGoal (repGoal + 1)
@@ -153,23 +168,16 @@ drawUI (St lifts _) = [vCenter $ vBox [hCenter oneRepMaxTable, withVScrollBarHan
153ceilingN :: Integer -> Rational -> Integer 168ceilingN :: Integer -> Rational -> Integer
154ceilingN n x = ceiling (x / toRational n) * n 169ceilingN n x = ceiling (x / toRational n) * n
155 170
156-- TODO: State contains chosen repmax formula 171succ' :: (Enum a, Bounded a, Eq a) => a -> a
157-- TODO: State contains performances 172succ' x | x == maxBound = minBound
158data St = St { 173succ' x = succ x
159 lifts :: [LiftRecord],
160 week :: WeekSelection
161}
162
163data WeekSelection = Week1 | Week2 | Week3 deriving Enum
164
165-- TODO: Event for inotify on edited text file (as input interface)
166data CustomEvent = CustomEvent
167 174
168handleEvent :: St -> BrickEvent () CustomEvent -> EventM () (Next St) 175handleEvent :: St -> BrickEvent () CustomEvent -> EventM () (Next St)
169handleEvent st e = case e of 176handleEvent st e = case e of
170 VtyEvent (V.EvKey V.KEsc []) -> halt st 177 VtyEvent (V.EvKey V.KEsc []) -> halt st
171 VtyEvent (V.EvKey V.KDown _) -> M.vScrollBy (M.viewportScroll ()) 5 >> continue st 178 VtyEvent (V.EvKey V.KDown _) -> M.vScrollBy (M.viewportScroll ()) 5 >> continue st
172 VtyEvent (V.EvKey V.KUp _) -> M.vScrollBy (M.viewportScroll ()) (-5) >> continue st 179 VtyEvent (V.EvKey V.KUp _) -> M.vScrollBy (M.viewportScroll ()) (-5) >> continue st
180 VtyEvent (V.EvKey (V.KChar 'w') _) -> continue $ st & week %~ succ'
173 VtyEvent _ -> continue st 181 VtyEvent _ -> continue st
174 AppEvent _ -> continue st 182 AppEvent _ -> continue st
175 _ -> continue st 183 _ -> continue st