From 186c118566bca45bf23996424c910042c2c5dd7b Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Fri, 25 Nov 2022 23:34:33 -0500 Subject: show accessory lift weights --- repgoal.hs | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/repgoal.hs b/repgoal.hs index c512a94..cb9cee3 100755 --- a/repgoal.hs +++ b/repgoal.hs @@ -106,18 +106,16 @@ bestPerformance = head . sortBy (flip $ comparing computeOneRepMax) computeOneRepMax :: Performance -> Rational computeOneRepMax Achieved{..} = toRational achievedWeight * (realToFrac achievedReps * 0.0333 + 1) -showRational' :: Rational -> String -showRational' n = printf format $ (realToFrac :: Rational -> Float) $ n - where - format = if floor (n * 10) `mod` 10 == (0 :: Integer) then "%.0f" else "%.1f" +showRealFrac' :: (RealFrac n, PrintfArg n ) => n -> String +showRealFrac' n = printf "%.0f" n -showFloatConcise :: Float -> String -showFloatConcise n = printf format n +showRealFrac :: (RealFrac n, PrintfArg n ) => n -> String +showRealFrac n = printf format n where format = if floor (n * 10) `mod` 10 == (0 :: Integer) then "%.0f" else "%.2f" showRational :: Rational -> String -showRational = showFloatConcise . realToFrac +showRational = (showRealFrac :: Float -> String) . fromRational data WeekSelection = Week1 | Week2 | Week3 | Week4 deriving (Enum, Bounded, Show, Eq) @@ -180,21 +178,25 @@ lookup' i seq = fromJust $ NESeq.lookup (i `mod` NESeq.length seq) seq liftRows :: WeekSelection -> (Lift, Maybe LiftRecord) -> [[Widget n]] liftRows week (Lift _name Wendler, Just liftRecord) = (flip map) (annotatePosition $ liftScheme Fresher week) $ wendlerLiftRow liftRecord -liftRows _ (Lift name (Accessory sets reps), _) = - (flip map) (annotatePosition $ take sets $ repeat reps) $ accessoryLiftRow name reps -liftRows _ (Lift name Unspecified, _) = - [unspecifiedLiftRow name] - -accessoryLiftRow :: Text -> Int -> (ListPosition, Int) -> [Widget n] -accessoryLiftRow name targetReps (position, _) = map (padLeftRight 2) [ - txt $ case position of FirstInList -> name; NotFirstInList -> " ", - str $ printf "%2d @ %5s" targetReps (" " :: String), - txt " ", - txt " ", - txt " ", - txt " ", - txt " " +liftRows _ (Lift name (Accessory sets reps), liftRecords) = + (flip map) (annotatePosition $ take sets $ repeat reps) $ accessoryLiftRow liftRecords name reps +liftRows _ (Lift name Unspecified, _) = [unspecifiedLiftRow name] + +accessoryLiftRow :: Maybe LiftRecord -> Text -> Int -> (ListPosition, Int) -> [Widget n] +accessoryLiftRow liftRecords name targetReps (position, _) = + map (padLeftRight 2) + [ txt $ case position of FirstInList -> name; NotFirstInList -> " " + , str $ printf "%2d @ %3s" targetReps $ fromMaybe (" " :: String) (show <$> targetWeight) + , txt " " + , txt " " + , txt " " + , txt " " + , txt " " ] + where + targetWeight :: Maybe Integer + targetWeight = join $ fmap achievedWeight . find ((== targetReps) . fromIntegral . achievedReps) . stats <$> liftRecords + unspecifiedLiftRow :: Text -> [Widget n] unspecifiedLiftRow name = map (padLeftRight 2) [ txt name, @@ -222,7 +224,7 @@ wendlerLiftRow LiftRecord{..} (position, (SetScheme targetRatio targetReps amrap pad $ txt $ case position of FirstInList -> liftRecordName; NotFirstInList -> " ", pad $ str $ printf "%2d%s @ %d" targetReps (if amrap then "+" else "" :: Text) targetWeight, pad $ str $ showPlates targetWeight, - pad $ str $ showFloatConcise actualIntensity ++ "%", + pad $ str $ showRealFrac' actualIntensity ++ "%", str $ if amrap then showGoal repGoal ++ "\n" ++ showGoal (repGoal + 1) else " ", pad $ txt " ", pad $ txt " " @@ -262,7 +264,7 @@ showPlates (fromIntegral -> wt) = fromMaybe " " $ fmap (ourShow . reverse) $ sho where ourPlates = [45,45,25,25,10,10,10,5,5,2.5] ourShow :: [Rational] -> String - ourShow = concat . intersperse " " . map showRational' + ourShow = concat . intersperse " " . map showRational showPlates' 0 _ [] = Nothing showPlates' 0 _ used = Just used showPlates' need (have:avail) used | have * 2 > need = showPlates' need avail used -- cgit v1.2.3