Skip to content

Commit 5d6983d

Browse files
Russoulmgmeier
authored andcommitted
cardano-recon: address review comments (formatting, camelCase JSON keys)
- Use Text.unlines in prettyRelevanceArray and forHuman ContextDump - Rename JSON keys eventsPerSecond and catchUpRatio to camelCase - Simplify printArray to build a single Text value - Use maybe [] Map.toList instead of Map.toList . fromMaybe Map.empty
1 parent 9ef39fc commit 5d6983d

2 files changed

Lines changed: 8 additions & 16 deletions

File tree

bench/cardano-recon-framework/app/Cardano/ReCon/TraceMessage.hs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ prettyTemporalEvent (TemporalEvent _ msgs) ns =
6666

6767
prettyRelevanceArray :: Relevance TemporalEvent Text -> Text
6868
prettyRelevanceArray rel =
69-
"[\n"
70-
<> Text.intercalate "\n,\n" (fmap (uncurry prettyTemporalEvent) (Set.toList rel))
71-
<> "\n]"
69+
Text.unlines $ "[" : fmap (uncurry prettyTemporalEvent) (Set.toList rel) ++ ["]"]
7270

7371
prettySatisfactionResult :: Formula TemporalEvent Text -> SatisfactionResult TemporalEvent Text -> Text
7472
prettySatisfactionResult initial Satisfied = prettyFormula initial Prec.Universe <> " " <> green "(✔)"
@@ -84,8 +82,8 @@ instance LogFormatting TraceMessage where
8482
]
8583
forMachine _ FormulaProgressDump{..} = mconcat
8684
[
87-
"events_per_second" .= (fromIntegral eventsPerSecond :: Int),
88-
"catch_up_ratio" .= (realToFrac catchupRatio :: Double),
85+
"eventsPerSecond" .= (fromIntegral eventsPerSecond :: Int),
86+
"catchUpRatio" .= (realToFrac catchupRatio :: Double),
8987
"index" .= index
9088
]
9189
forMachine _ FormulaPositiveOutcome{..} = mconcat
@@ -119,7 +117,7 @@ instance LogFormatting TraceMessage where
119117
forHuman FormulaNegativeOutcome{..} =
120118
prettySatisfactionResult formula (Unsatisfied relevance)
121119
forHuman ContextDump{..} =
122-
"Context:\n" <> Text.unlines (fmap (\(k, v) -> " " <> k <> " = " <> v) context)
120+
Text.unlines $ "Context:" : map (\(k, v) -> " " <> k <> " = " <> v) context
123121

124122
asMetrics FormulaStartCheck{} = []
125123
asMetrics (FormulaProgressDump {catchupRatio, index}) = [DoubleM ("catchup_ratio_" <> showT index) catchupRatio]

bench/cardano-recon-framework/app/Cardano/ReConGrep.hs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Cardano.ReCon.Trace.Event ()
1010
import Cardano.ReCon.Trace.Feed (TemporalEvent (..))
1111

1212
import Control.Arrow ((>>>))
13-
import Control.Monad (forM_, (>=>))
13+
import Control.Monad ((>=>))
1414
import Control.Monad.Reader (runReader)
1515
import Data.Aeson (decodeStrict')
1616
import Data.Aeson.Encode.Pretty (encodePrettyToTextBuilder)
@@ -21,7 +21,6 @@ import Data.Text.Lazy (toStrict)
2121
import Data.Text.Lazy.Builder (toLazyText)
2222
import Data.Char (toLower)
2323
import qualified Data.Map.Strict as Map
24-
import Data.Maybe (fromMaybe)
2524
import Data.Time.Clock.POSIX (utcTimeToPOSIXSeconds)
2625
import Data.Text (Text)
2726
import qualified Data.Text as Text
@@ -78,19 +77,14 @@ prettyMsg = toStrict . toLazyText . encodePrettyToTextBuilder
7877

7978
printArray :: [TraceMessage] -> IO ()
8079
printArray [] = TIO.putStrLn "[]"
81-
printArray (x : xs) = do
82-
TIO.putStrLn "["
83-
TIO.putStr (prettyMsg x)
84-
forM_ xs $ \m -> do
85-
TIO.putStr "\n,"
86-
TIO.putStr (prettyMsg m)
87-
TIO.putStrLn "\n]"
80+
printArray msgs =
81+
TIO.putStr $ Text.unlines $ "[" : map prettyMsg msgs ++ ["]"]
8882

8983
main :: IO ()
9084
main = do
9185
setLocaleEncoding utf8
9286
options <- execParser opts
93-
ctx <- Map.toList . fromMaybe Map.empty <$>
87+
ctx <- maybe [] Map.toList <$>
9488
for options.context (readPropValues >=> dieOnYamlError)
9589
rawFormulas <- readFormulas options.formulas
9690
(Context { interpDomain = ctx, varKinds = Map.empty })

0 commit comments

Comments
 (0)