<commit_before>module Pusher.Util
  ( failExpectObj
  , getIntPOSIXTime
  ) where

import Control.Applicative ((<$>))
import Control.Monad.IO.Class (MonadIO, liftIO)
import Data.Time.Clock.POSIX (getPOSIXTime)
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as A

failExpectObj :: A.Value -> A.Parser a
failExpectObj = fail . ("Expected JSON object, got " ++) . show

getIntPOSIXTime :: MonadIO m => m Int
getIntPOSIXTime =  liftIO $ round <$> getPOSIXTime<commit_msg>Document Pusher.Util<commit_after>{-|
Module      : Pusher.Util
Description : Various utilty functions
Copyright   : (c) <NAME>, 2015
Licence     : MIT
Maintainer  : <EMAIL>
Stability   : experimental
-}
module Pusher.Util
  ( failExpectObj
  , getIntPOSIXTime
  ) where

import Control.Applicative ((<$>))
import Control.Monad.IO.Class (MonadIO, liftIO)
import Data.Time.Clock.POSIX (getPOSIXTime)
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as A

-- |When decoding Aeson values, this can be used to return a failing parser
-- when an object was expected, but it was a different type of data.
failExpectObj :: A.Value -> A.Parser a
failExpectObj = fail . ("Expected JSON object, got " ++) . show

-- | Wrapper around getPOSIXTime that rounds the time to an Int.
getIntPOSIXTime :: MonadIO m => m Int
getIntPOSIXTime =  liftIO $ round <$> getPOSIXTime
{'fraction_non_alphanumeric': 0.10286554004408523, 'fraction_numerical': 0.0029390154298310064, 'mean_word_length': 4.198473282442748, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4182538', 'n_tokens_mistral': 461, 'n_tokens_neox': 443, 'n_words': 141}