{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.CloudSearchDomains.Types.FieldStats
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.CloudSearchDomains.Types.FieldStats where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | The statistics for a field calculated in the request.
--
-- /See:/ 'newFieldStats' smart constructor.
data FieldStats = FieldStats'
  { -- | The number of documents that contain a value in the specified field in
    -- the result set.
    FieldStats -> Maybe Integer
count :: Prelude.Maybe Prelude.Integer,
    -- | The maximum value found in the specified field in the result set.
    --
    -- If the field is numeric (@int@, @int-array@, @double@, or
    -- @double-array@), @max@ is the string representation of a
    -- double-precision 64-bit floating point value. If the field is @date@ or
    -- @date-array@, @max@ is the string representation of a date with the
    -- format specified in <http://tools.ietf.org/html/rfc3339 IETF RFC3339>:
    -- yyyy-mm-ddTHH:mm:ss.SSSZ.
    FieldStats -> Maybe Text
max :: Prelude.Maybe Prelude.Text,
    -- | The average of the values found in the specified field in the result
    -- set.
    --
    -- If the field is numeric (@int@, @int-array@, @double@, or
    -- @double-array@), @mean@ is the string representation of a
    -- double-precision 64-bit floating point value. If the field is @date@ or
    -- @date-array@, @mean@ is the string representation of a date with the
    -- format specified in <http://tools.ietf.org/html/rfc3339 IETF RFC3339>:
    -- yyyy-mm-ddTHH:mm:ss.SSSZ.
    FieldStats -> Maybe Text
mean :: Prelude.Maybe Prelude.Text,
    -- | The minimum value found in the specified field in the result set.
    --
    -- If the field is numeric (@int@, @int-array@, @double@, or
    -- @double-array@), @min@ is the string representation of a
    -- double-precision 64-bit floating point value. If the field is @date@ or
    -- @date-array@, @min@ is the string representation of a date with the
    -- format specified in <http://tools.ietf.org/html/rfc3339 IETF RFC3339>:
    -- yyyy-mm-ddTHH:mm:ss.SSSZ.
    FieldStats -> Maybe Text
min :: Prelude.Maybe Prelude.Text,
    -- | The number of documents that do not contain a value in the specified
    -- field in the result set.
    FieldStats -> Maybe Integer
missing :: Prelude.Maybe Prelude.Integer,
    -- | The standard deviation of the values in the specified field in the
    -- result set.
    FieldStats -> Maybe Double
stddev :: Prelude.Maybe Prelude.Double,
    -- | The sum of the field values across the documents in the result set.
    -- @null@ for date fields.
    FieldStats -> Maybe Double
sum :: Prelude.Maybe Prelude.Double,
    -- | The sum of all field values in the result set squared.
    FieldStats -> Maybe Double
sumOfSquares :: Prelude.Maybe Prelude.Double
  }
  deriving (FieldStats -> FieldStats -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FieldStats -> FieldStats -> Bool
$c/= :: FieldStats -> FieldStats -> Bool
== :: FieldStats -> FieldStats -> Bool
$c== :: FieldStats -> FieldStats -> Bool
Prelude.Eq, ReadPrec [FieldStats]
ReadPrec FieldStats
Int -> ReadS FieldStats
ReadS [FieldStats]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FieldStats]
$creadListPrec :: ReadPrec [FieldStats]
readPrec :: ReadPrec FieldStats
$creadPrec :: ReadPrec FieldStats
readList :: ReadS [FieldStats]
$creadList :: ReadS [FieldStats]
readsPrec :: Int -> ReadS FieldStats
$creadsPrec :: Int -> ReadS FieldStats
Prelude.Read, Int -> FieldStats -> ShowS
[FieldStats] -> ShowS
FieldStats -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FieldStats] -> ShowS
$cshowList :: [FieldStats] -> ShowS
show :: FieldStats -> String
$cshow :: FieldStats -> String
showsPrec :: Int -> FieldStats -> ShowS
$cshowsPrec :: Int -> FieldStats -> ShowS
Prelude.Show, forall x. Rep FieldStats x -> FieldStats
forall x. FieldStats -> Rep FieldStats x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FieldStats x -> FieldStats
$cfrom :: forall x. FieldStats -> Rep FieldStats x
Prelude.Generic)

-- |
-- Create a value of 'FieldStats' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'count', 'fieldStats_count' - The number of documents that contain a value in the specified field in
-- the result set.
--
-- 'max', 'fieldStats_max' - The maximum value found in the specified field in the result set.
--
-- If the field is numeric (@int@, @int-array@, @double@, or
-- @double-array@), @max@ is the string representation of a
-- double-precision 64-bit floating point value. If the field is @date@ or
-- @date-array@, @max@ is the string representation of a date with the
-- format specified in <http://tools.ietf.org/html/rfc3339 IETF RFC3339>:
-- yyyy-mm-ddTHH:mm:ss.SSSZ.
--
-- 'mean', 'fieldStats_mean' - The average of the values found in the specified field in the result
-- set.
--
-- If the field is numeric (@int@, @int-array@, @double@, or
-- @double-array@), @mean@ is the string representation of a
-- double-precision 64-bit floating point value. If the field is @date@ or
-- @date-array@, @mean@ is the string representation of a date with the
-- format specified in <http://tools.ietf.org/html/rfc3339 IETF RFC3339>:
-- yyyy-mm-ddTHH:mm:ss.SSSZ.
--
-- 'min', 'fieldStats_min' - The minimum value found in the specified field in the result set.
--
-- If the field is numeric (@int@, @int-array@, @double@, or
-- @double-array@), @min@ is the string representation of a
-- double-precision 64-bit floating point value. If the field is @date@ or
-- @date-array@, @min@ is the string representation of a date with the
-- format specified in <http://tools.ietf.org/html/rfc3339 IETF RFC3339>:
-- yyyy-mm-ddTHH:mm:ss.SSSZ.
--
-- 'missing', 'fieldStats_missing' - The number of documents that do not contain a value in the specified
-- field in the result set.
--
-- 'stddev', 'fieldStats_stddev' - The standard deviation of the values in the specified field in the
-- result set.
--
-- 'sum', 'fieldStats_sum' - The sum of the field values across the documents in the result set.
-- @null@ for date fields.
--
-- 'sumOfSquares', 'fieldStats_sumOfSquares' - The sum of all field values in the result set squared.
newFieldStats ::
  FieldStats
newFieldStats :: FieldStats
newFieldStats =
  FieldStats'
    { $sel:count:FieldStats' :: Maybe Integer
count = forall a. Maybe a
Prelude.Nothing,
      $sel:max:FieldStats' :: Maybe Text
max = forall a. Maybe a
Prelude.Nothing,
      $sel:mean:FieldStats' :: Maybe Text
mean = forall a. Maybe a
Prelude.Nothing,
      $sel:min:FieldStats' :: Maybe Text
min = forall a. Maybe a
Prelude.Nothing,
      $sel:missing:FieldStats' :: Maybe Integer
missing = forall a. Maybe a
Prelude.Nothing,
      $sel:stddev:FieldStats' :: Maybe Double
stddev = forall a. Maybe a
Prelude.Nothing,
      $sel:sum:FieldStats' :: Maybe Double
sum = forall a. Maybe a
Prelude.Nothing,
      $sel:sumOfSquares:FieldStats' :: Maybe Double
sumOfSquares = forall a. Maybe a
Prelude.Nothing
    }

-- | The number of documents that contain a value in the specified field in
-- the result set.
fieldStats_count :: Lens.Lens' FieldStats (Prelude.Maybe Prelude.Integer)
fieldStats_count :: Lens' FieldStats (Maybe Integer)
fieldStats_count = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FieldStats' {Maybe Integer
count :: Maybe Integer
$sel:count:FieldStats' :: FieldStats -> Maybe Integer
count} -> Maybe Integer
count) (\s :: FieldStats
s@FieldStats' {} Maybe Integer
a -> FieldStats
s {$sel:count:FieldStats' :: Maybe Integer
count = Maybe Integer
a} :: FieldStats)

-- | The maximum value found in the specified field in the result set.
--
-- If the field is numeric (@int@, @int-array@, @double@, or
-- @double-array@), @max@ is the string representation of a
-- double-precision 64-bit floating point value. If the field is @date@ or
-- @date-array@, @max@ is the string representation of a date with the
-- format specified in <http://tools.ietf.org/html/rfc3339 IETF RFC3339>:
-- yyyy-mm-ddTHH:mm:ss.SSSZ.
fieldStats_max :: Lens.Lens' FieldStats (Prelude.Maybe Prelude.Text)
fieldStats_max :: Lens' FieldStats (Maybe Text)
fieldStats_max = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FieldStats' {Maybe Text
max :: Maybe Text
$sel:max:FieldStats' :: FieldStats -> Maybe Text
max} -> Maybe Text
max) (\s :: FieldStats
s@FieldStats' {} Maybe Text
a -> FieldStats
s {$sel:max:FieldStats' :: Maybe Text
max = Maybe Text
a} :: FieldStats)

-- | The average of the values found in the specified field in the result
-- set.
--
-- If the field is numeric (@int@, @int-array@, @double@, or
-- @double-array@), @mean@ is the string representation of a
-- double-precision 64-bit floating point value. If the field is @date@ or
-- @date-array@, @mean@ is the string representation of a date with the
-- format specified in <http://tools.ietf.org/html/rfc3339 IETF RFC3339>:
-- yyyy-mm-ddTHH:mm:ss.SSSZ.
fieldStats_mean :: Lens.Lens' FieldStats (Prelude.Maybe Prelude.Text)
fieldStats_mean :: Lens' FieldStats (Maybe Text)
fieldStats_mean = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FieldStats' {Maybe Text
mean :: Maybe Text
$sel:mean:FieldStats' :: FieldStats -> Maybe Text
mean} -> Maybe Text
mean) (\s :: FieldStats
s@FieldStats' {} Maybe Text
a -> FieldStats
s {$sel:mean:FieldStats' :: Maybe Text
mean = Maybe Text
a} :: FieldStats)

-- | The minimum value found in the specified field in the result set.
--
-- If the field is numeric (@int@, @int-array@, @double@, or
-- @double-array@), @min@ is the string representation of a
-- double-precision 64-bit floating point value. If the field is @date@ or
-- @date-array@, @min@ is the string representation of a date with the
-- format specified in <http://tools.ietf.org/html/rfc3339 IETF RFC3339>:
-- yyyy-mm-ddTHH:mm:ss.SSSZ.
fieldStats_min :: Lens.Lens' FieldStats (Prelude.Maybe Prelude.Text)
fieldStats_min :: Lens' FieldStats (Maybe Text)
fieldStats_min = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FieldStats' {Maybe Text
min :: Maybe Text
$sel:min:FieldStats' :: FieldStats -> Maybe Text
min} -> Maybe Text
min) (\s :: FieldStats
s@FieldStats' {} Maybe Text
a -> FieldStats
s {$sel:min:FieldStats' :: Maybe Text
min = Maybe Text
a} :: FieldStats)

-- | The number of documents that do not contain a value in the specified
-- field in the result set.
fieldStats_missing :: Lens.Lens' FieldStats (Prelude.Maybe Prelude.Integer)
fieldStats_missing :: Lens' FieldStats (Maybe Integer)
fieldStats_missing = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FieldStats' {Maybe Integer
missing :: Maybe Integer
$sel:missing:FieldStats' :: FieldStats -> Maybe Integer
missing} -> Maybe Integer
missing) (\s :: FieldStats
s@FieldStats' {} Maybe Integer
a -> FieldStats
s {$sel:missing:FieldStats' :: Maybe Integer
missing = Maybe Integer
a} :: FieldStats)

-- | The standard deviation of the values in the specified field in the
-- result set.
fieldStats_stddev :: Lens.Lens' FieldStats (Prelude.Maybe Prelude.Double)
fieldStats_stddev :: Lens' FieldStats (Maybe Double)
fieldStats_stddev = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FieldStats' {Maybe Double
stddev :: Maybe Double
$sel:stddev:FieldStats' :: FieldStats -> Maybe Double
stddev} -> Maybe Double
stddev) (\s :: FieldStats
s@FieldStats' {} Maybe Double
a -> FieldStats
s {$sel:stddev:FieldStats' :: Maybe Double
stddev = Maybe Double
a} :: FieldStats)

-- | The sum of the field values across the documents in the result set.
-- @null@ for date fields.
fieldStats_sum :: Lens.Lens' FieldStats (Prelude.Maybe Prelude.Double)
fieldStats_sum :: Lens' FieldStats (Maybe Double)
fieldStats_sum = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FieldStats' {Maybe Double
sum :: Maybe Double
$sel:sum:FieldStats' :: FieldStats -> Maybe Double
sum} -> Maybe Double
sum) (\s :: FieldStats
s@FieldStats' {} Maybe Double
a -> FieldStats
s {$sel:sum:FieldStats' :: Maybe Double
sum = Maybe Double
a} :: FieldStats)

-- | The sum of all field values in the result set squared.
fieldStats_sumOfSquares :: Lens.Lens' FieldStats (Prelude.Maybe Prelude.Double)
fieldStats_sumOfSquares :: Lens' FieldStats (Maybe Double)
fieldStats_sumOfSquares = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FieldStats' {Maybe Double
sumOfSquares :: Maybe Double
$sel:sumOfSquares:FieldStats' :: FieldStats -> Maybe Double
sumOfSquares} -> Maybe Double
sumOfSquares) (\s :: FieldStats
s@FieldStats' {} Maybe Double
a -> FieldStats
s {$sel:sumOfSquares:FieldStats' :: Maybe Double
sumOfSquares = Maybe Double
a} :: FieldStats)

instance Data.FromJSON FieldStats where
  parseJSON :: Value -> Parser FieldStats
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"FieldStats"
      ( \Object
x ->
          Maybe Integer
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Integer
-> Maybe Double
-> Maybe Double
-> Maybe Double
-> FieldStats
FieldStats'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"count")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"max")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"mean")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"min")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"missing")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"stddev")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"sum")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"sumOfSquares")
      )

instance Prelude.Hashable FieldStats where
  hashWithSalt :: Int -> FieldStats -> Int
hashWithSalt Int
_salt FieldStats' {Maybe Double
Maybe Integer
Maybe Text
sumOfSquares :: Maybe Double
sum :: Maybe Double
stddev :: Maybe Double
missing :: Maybe Integer
min :: Maybe Text
mean :: Maybe Text
max :: Maybe Text
count :: Maybe Integer
$sel:sumOfSquares:FieldStats' :: FieldStats -> Maybe Double
$sel:sum:FieldStats' :: FieldStats -> Maybe Double
$sel:stddev:FieldStats' :: FieldStats -> Maybe Double
$sel:missing:FieldStats' :: FieldStats -> Maybe Integer
$sel:min:FieldStats' :: FieldStats -> Maybe Text
$sel:mean:FieldStats' :: FieldStats -> Maybe Text
$sel:max:FieldStats' :: FieldStats -> Maybe Text
$sel:count:FieldStats' :: FieldStats -> Maybe Integer
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Integer
count
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
max
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
mean
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
min
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Integer
missing
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Double
stddev
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Double
sum
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Double
sumOfSquares

instance Prelude.NFData FieldStats where
  rnf :: FieldStats -> ()
rnf FieldStats' {Maybe Double
Maybe Integer
Maybe Text
sumOfSquares :: Maybe Double
sum :: Maybe Double
stddev :: Maybe Double
missing :: Maybe Integer
min :: Maybe Text
mean :: Maybe Text
max :: Maybe Text
count :: Maybe Integer
$sel:sumOfSquares:FieldStats' :: FieldStats -> Maybe Double
$sel:sum:FieldStats' :: FieldStats -> Maybe Double
$sel:stddev:FieldStats' :: FieldStats -> Maybe Double
$sel:missing:FieldStats' :: FieldStats -> Maybe Integer
$sel:min:FieldStats' :: FieldStats -> Maybe Text
$sel:mean:FieldStats' :: FieldStats -> Maybe Text
$sel:max:FieldStats' :: FieldStats -> Maybe Text
$sel:count:FieldStats' :: FieldStats -> Maybe Integer
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Integer
count
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
max
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
mean
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
min
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Integer
missing
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Double
stddev
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Double
sum
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Double
sumOfSquares