{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE UndecidableInstances #-}
module Charon.Data.Metadata
( Metadata (..),
empty,
)
where
import Charon.Prelude
import Charon.Utils qualified as U
import Data.Bytes (SomeSize)
import Numeric.Algebra (AMonoid (zero))
data Metadata = MkMetadata
{
Metadata -> Natural
numEntries :: Natural,
Metadata -> Natural
numFiles :: Natural,
Metadata -> SomeSize Double
logSize :: SomeSize Double,
Metadata -> SomeSize Double
size :: SomeSize Double
}
deriving stock (Metadata -> Metadata -> Bool
(Metadata -> Metadata -> Bool)
-> (Metadata -> Metadata -> Bool) -> Eq Metadata
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Metadata -> Metadata -> Bool
== :: Metadata -> Metadata -> Bool
$c/= :: Metadata -> Metadata -> Bool
/= :: Metadata -> Metadata -> Bool
Eq, (forall x. Metadata -> Rep Metadata x)
-> (forall x. Rep Metadata x -> Metadata) -> Generic Metadata
forall x. Rep Metadata x -> Metadata
forall x. Metadata -> Rep Metadata x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Metadata -> Rep Metadata x
from :: forall x. Metadata -> Rep Metadata x
$cto :: forall x. Rep Metadata x -> Metadata
to :: forall x. Rep Metadata x -> Metadata
Generic, Int -> Metadata -> ShowS
[Metadata] -> ShowS
Metadata -> String
(Int -> Metadata -> ShowS)
-> (Metadata -> String) -> ([Metadata] -> ShowS) -> Show Metadata
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Metadata -> ShowS
showsPrec :: Int -> Metadata -> ShowS
$cshow :: Metadata -> String
show :: Metadata -> String
$cshowList :: [Metadata] -> ShowS
showList :: [Metadata] -> ShowS
Show)
deriving anyclass (Metadata -> ()
(Metadata -> ()) -> NFData Metadata
forall a. (a -> ()) -> NFData a
$crnf :: Metadata -> ()
rnf :: Metadata -> ()
NFData)
makeFieldLabelsNoPrefix ''Metadata
empty :: Metadata
empty :: Metadata
empty = Natural
-> Natural -> SomeSize Double -> SomeSize Double -> Metadata
MkMetadata Natural
0 Natural
0 SomeSize Double
forall m. AMonoid m => m
zero SomeSize Double
forall m. AMonoid m => m
zero
instance Pretty Metadata where
pretty :: forall ann. Metadata -> Doc ann
pretty Metadata
stats = [Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
vsep [Doc ann]
strs Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Doc ann
forall ann. Doc ann
line
where
strs :: [Doc ann]
strs =
[ Doc ann
"Entries: " Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Natural -> Doc ann
forall ann. Natural -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty (Metadata
stats Metadata -> Optic' A_Lens NoIx Metadata Natural -> Natural
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Metadata Natural
#numEntries),
Doc ann
"Total Files: " Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Natural -> Doc ann
forall ann. Natural -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty (Metadata
stats Metadata -> Optic' A_Lens NoIx Metadata Natural -> Natural
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Metadata Natural
#numFiles),
Doc ann
"Log size: " Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Text -> Doc ann
forall ann. Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty (SomeSize Double -> Text
forall a.
(BaseFormatter (Unwrapped a) ~ FloatingFormatter,
PrintfArg (Unwrapped a), Sized a, Unwrapper a) =>
a -> Text
U.formatBytes (SomeSize Double -> Text) -> SomeSize Double -> Text
forall a b. (a -> b) -> a -> b
$ Metadata
stats Metadata
-> Optic' A_Lens NoIx Metadata (SomeSize Double) -> SomeSize Double
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Metadata (SomeSize Double)
#logSize),
Doc ann
"Size: " Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Text -> Doc ann
forall ann. Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty (SomeSize Double -> Text
forall a.
(BaseFormatter (Unwrapped a) ~ FloatingFormatter,
PrintfArg (Unwrapped a), Sized a, Unwrapper a) =>
a -> Text
U.formatBytes (SomeSize Double -> Text) -> SomeSize Double -> Text
forall a b. (a -> b) -> a -> b
$ Metadata
stats Metadata
-> Optic' A_Lens NoIx Metadata (SomeSize Double) -> SomeSize Double
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Metadata (SomeSize Double)
#size)
]