module Data.ZoomCache.Pretty (
prettyGlobal
, prettyTrackSpec
, prettyTimeStamp
, prettySummary
) where
import qualified Data.ByteString.Char8 as C
import Data.Ratio
import Text.Printf
import Data.ZoomCache.Common
import Data.ZoomCache.Types
prettyGlobal :: Global -> String
prettyGlobal Global{..} = unlines
[ "Version:\t\t" ++ show vMaj ++ "." ++ show vMin
, "No. tracks:\t\t" ++ show noTracks
, "Presentation-time:\t" ++ ratShow presentationTime
, "Base-time:\t\t" ++ ratShow baseTime
, "UTC baseTime:\t\t" ++ maybe "undefined" show baseUTC
]
where
Version vMaj vMin = version
prettyTrackSpec :: TrackNo -> TrackSpec -> String
prettyTrackSpec trackNo TrackSpec{..} = unlines
[ "Track " ++ show trackNo ++ ":"
, "\tName:\t" ++ C.unpack specName
, "\tType:\t" ++ show specType
, "\tEnc:\t" ++ unwords [encoding, compression]
, "\tRate:\t" ++ show specDRType ++ " " ++ ratShow specRate
]
where
encoding | specDeltaEncode = "Delta"
| otherwise = "Raw"
compression | specZlibCompress = "Zlib"
| otherwise = "Uncompressed"
prettyTimeStamp :: Rational -> TimeStamp -> String
prettyTimeStamp r (TS t)
| d == 0 = "00:00:00.000"
| otherwise = printf "%02d:%02d:%02d.%03d" hrs minN secN msN
where
d = denominator r
n = numerator r
msN = quot (1000 * framesN) n
(secT, framesN) = quotRem (fromIntegral t*d) n
(minT, secN) = quotRem secT 60
(hrs, minN) = quotRem minT 60
prettySummary :: ZoomReadable a => Rational -> Summary a -> String
prettySummary r s = concat
[ prettySummaryTimes r s
, prettySummaryLevel s
, prettySummaryData (summaryData s)
]
prettySummaryTimes :: Rational -> Summary a -> String
prettySummaryTimes r s = concat
[ "[", (prettyTimeStamp r $ summaryEntryTime s)
, "-", (prettyTimeStamp r $ summaryExitTime s), "] "
]
prettySummaryLevel :: Summary a -> String
prettySummaryLevel s = printf "lvl: %d" (summaryLevel s)
ratShow :: Rational -> String
ratShow r
| d == 0 = "0"
| d == 1 = show n
| otherwise = show n ++ "/" ++ show d
where
n = numerator r
d = denominator r