<commit_before>{-# LANGUAGE EmptyDataDecls        #-}

module Halytics.Metric where

import Data.List
import Data.List.Split           (chunksOf)
import Data.Proxy
import GHC.TypeLits
import Halytics.Monitor.Internal

data All :: *

instance Storable All where
  type S All = [Double]
  u' _ = flip (:)

instance Default All where
  g _ = []

instance Resultable All [Double] where
  r _ xs = xs

data Max

instance Storable Max where
  type S Max = Maybe Double
  u' _ (Just x) x' = Just $ max x x'
  u' _ Nothing x' = Just x'

instance Default Max where
  g _ = Nothing

instance Resultable Max (Maybe Double) where
  r _ x = x

instance Resultable Max String where
  r _  xs = maybe naught (\x -> "Max: " ++ show x) res
    where
      naught = "No maximum found"
      res = r (Proxy :: Proxy Max) xs :: Maybe Double

data Min

instance Storable Min where
  type S Min = Maybe Double
  u' _ (Just x) x' = Just $ min x x'
  u' _ Nothing x' = Just x'

instance Default Min where
  g _ = Nothing

instance Resultable Min (Maybe Double) where
  r _ x = x

instance Resultable Min String where<commit_msg>Make current max strict<commit_after>{-# LANGUAGE EmptyDataDecls        #-}
{-# LANGUAGE BangPatterns #-}

module Halytics.Metric where

import Data.List
import Data.List.Split           (chunksOf)
import Data.Proxy
import GHC.TypeLits
import Halytics.Monitor.Internal

data All :: *

instance Storable All where
  type S All = [Double]
  u' _ = flip (:)

instance Default All where
  g _ = []

instance Resultable All [Double] where
  r _ xs = xs

data Max

instance Storable Max where
  type S Max = Maybe Double
  u' _ (Just !x) x' = Just $ max x x'
  u' _ Nothing x' = Just x'

instance Default Max where
  g _ = Nothing

instance Resultable Max (Maybe Double) where
  r _ x = x

instance Resultable Max String where
  r _  xs = maybe naught (\x -> "Max: " ++ show x) res
    where
      naught = "No maximum found"
      res = r (Proxy :: Proxy Max) xs :: Maybe Double

data Min

instance Storable Min where
  type S Min = Maybe Double
  u' _ (Just !x) x' = Just $ min x x'
  u' _ Nothing x' = Just x'

instance Default Min where
  g _ = Nothing

instance Resultable Min (Maybe Double) where
  r _ x = x

instance Resultable Min String where
{'fraction_non_alphanumeric': 0.08266666666666667, 'fraction_numerical': 0.0, 'mean_word_length': 2.894463667820069, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6575681', 'n_tokens_mistral': 741, 'n_tokens_neox': 726, 'n_words': 308}