{-# 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-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.CloudSearchDomains.Types.FieldStats where

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

-- | The statistics for a field calculated in the request.
--
-- /See:/ 'newFieldStats' smart constructor.
data FieldStats = 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 -> 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 number of documents that contain a value in the specified field in
    -- the result set.
    FieldStats -> Maybe Integer
count :: Prelude.Maybe Prelude.Integer,
    -- | 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 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 sum of all field values in the result set squared.
    FieldStats -> Maybe Double
sumOfSquares :: 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
  }
  deriving (FieldStats -> FieldStats -> Bool
(FieldStats -> FieldStats -> Bool)
-> (FieldStats -> FieldStats -> Bool) -> Eq FieldStats
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]
(Int -> ReadS FieldStats)
-> ReadS [FieldStats]
-> ReadPrec FieldStats
-> ReadPrec [FieldStats]
-> Read 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
(Int -> FieldStats -> ShowS)
-> (FieldStats -> String)
-> ([FieldStats] -> ShowS)
-> Show FieldStats
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. FieldStats -> Rep FieldStats x)
-> (forall x. Rep FieldStats x -> FieldStats) -> Generic FieldStats
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:
--
-- '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.
--
-- 'count', 'fieldStats_count' - The number of documents that contain a value in the specified field in
-- the result set.
--
-- '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.
--
-- '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.
--
-- 'sumOfSquares', 'fieldStats_sumOfSquares' - The sum of all field values in the result set squared.
--
-- 'sum', 'fieldStats_sum' - The sum of the field values across the documents in the result set.
-- @null@ for date fields.
newFieldStats ::
  FieldStats
newFieldStats :: FieldStats
newFieldStats =
  FieldStats' :: Maybe Text
-> Maybe Text
-> Maybe Integer
-> Maybe Integer
-> Maybe Double
-> Maybe Text
-> Maybe Double
-> Maybe Double
-> FieldStats
FieldStats'
    { $sel:max:FieldStats' :: Maybe Text
max = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:mean:FieldStats' :: Maybe Text
mean = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:count:FieldStats' :: Maybe Integer
count = Maybe Integer
forall a. Maybe a
Prelude.Nothing,
      $sel:missing:FieldStats' :: Maybe Integer
missing = Maybe Integer
forall a. Maybe a
Prelude.Nothing,
      $sel:stddev:FieldStats' :: Maybe Double
stddev = Maybe Double
forall a. Maybe a
Prelude.Nothing,
      $sel:min:FieldStats' :: Maybe Text
min = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:sumOfSquares:FieldStats' :: Maybe Double
sumOfSquares = Maybe Double
forall a. Maybe a
Prelude.Nothing,
      $sel:sum:FieldStats' :: Maybe Double
sum = Maybe Double
forall a. Maybe a
Prelude.Nothing
    }

-- | 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 :: (Maybe Text -> f (Maybe Text)) -> FieldStats -> f FieldStats
fieldStats_max = (FieldStats -> Maybe Text)
-> (FieldStats -> Maybe Text -> FieldStats)
-> Lens FieldStats FieldStats (Maybe Text) (Maybe Text)
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 :: (Maybe Text -> f (Maybe Text)) -> FieldStats -> f FieldStats
fieldStats_mean = (FieldStats -> Maybe Text)
-> (FieldStats -> Maybe Text -> FieldStats)
-> Lens FieldStats FieldStats (Maybe Text) (Maybe Text)
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 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 :: (Maybe Integer -> f (Maybe Integer)) -> FieldStats -> f FieldStats
fieldStats_count = (FieldStats -> Maybe Integer)
-> (FieldStats -> Maybe Integer -> FieldStats)
-> Lens FieldStats FieldStats (Maybe Integer) (Maybe Integer)
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 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 :: (Maybe Integer -> f (Maybe Integer)) -> FieldStats -> f FieldStats
fieldStats_missing = (FieldStats -> Maybe Integer)
-> (FieldStats -> Maybe Integer -> FieldStats)
-> Lens FieldStats FieldStats (Maybe Integer) (Maybe Integer)
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 :: (Maybe Double -> f (Maybe Double)) -> FieldStats -> f FieldStats
fieldStats_stddev = (FieldStats -> Maybe Double)
-> (FieldStats -> Maybe Double -> FieldStats)
-> Lens FieldStats FieldStats (Maybe Double) (Maybe Double)
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 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 :: (Maybe Text -> f (Maybe Text)) -> FieldStats -> f FieldStats
fieldStats_min = (FieldStats -> Maybe Text)
-> (FieldStats -> Maybe Text -> FieldStats)
-> Lens FieldStats FieldStats (Maybe Text) (Maybe Text)
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 sum of all field values in the result set squared.
fieldStats_sumOfSquares :: Lens.Lens' FieldStats (Prelude.Maybe Prelude.Double)
fieldStats_sumOfSquares :: (Maybe Double -> f (Maybe Double)) -> FieldStats -> f FieldStats
fieldStats_sumOfSquares = (FieldStats -> Maybe Double)
-> (FieldStats -> Maybe Double -> FieldStats)
-> Lens FieldStats FieldStats (Maybe Double) (Maybe Double)
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)

-- | 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 :: (Maybe Double -> f (Maybe Double)) -> FieldStats -> f FieldStats
fieldStats_sum = (FieldStats -> Maybe Double)
-> (FieldStats -> Maybe Double -> FieldStats)
-> Lens FieldStats FieldStats (Maybe Double) (Maybe Double)
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)

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

instance Prelude.Hashable FieldStats

instance Prelude.NFData FieldStats