{-# 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.LookoutVision.Types.DetectAnomalyResult
-- 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.LookoutVision.Types.DetectAnomalyResult where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.LookoutVision.Types.Anomaly
import Amazonka.LookoutVision.Types.ImageSource
import qualified Amazonka.Prelude as Prelude

-- | The prediction results from a call to DetectAnomalies.
-- @DetectAnomalyResult@ includes classification information for the
-- prediction (@IsAnomalous@ and @Confidence@). If the model you use is an
-- image segementation model, @DetectAnomalyResult@ also includes
-- segmentation information (@Anomalies@ and @AnomalyMask@). Classification
-- information is calculated separately from segmentation information and
-- you shouldn\'t assume a relationship between them.
--
-- /See:/ 'newDetectAnomalyResult' smart constructor.
data DetectAnomalyResult = DetectAnomalyResult'
  { -- | If the model is an image segmentation model, @Anomalies@ contains a list
    -- of anomaly types found in the image. There is one entry for each type of
    -- anomaly found (even if multiple instances of an anomaly type exist on
    -- the image). The first element in the list is always an anomaly type
    -- representing the image background (\'background\') and shouldn\'t be
    -- considered an anomaly. Amazon Lookout for Vision automatically add the
    -- background anomaly type to the response, and you don\'t need to declare
    -- a background anomaly type in your dataset.
    --
    -- If the list has one entry (\'background\'), no anomalies were found on
    -- the image.
    --
    -- An image classification model doesn\'t return an @Anomalies@ list.
    DetectAnomalyResult -> Maybe [Anomaly]
anomalies :: Prelude.Maybe [Anomaly],
    -- | If the model is an image segmentation model, @AnomalyMask@ contains
    -- pixel masks that covers all anomaly types found on the image. Each
    -- anomaly type has a different mask color. To map a color to an anomaly
    -- type, see the @color@ field of the PixelAnomaly object.
    --
    -- An image classification model doesn\'t return an @Anomalies@ list.
    DetectAnomalyResult -> Maybe Base64
anomalyMask :: Prelude.Maybe Data.Base64,
    -- | The confidence that Lookout for Vision has in the accuracy of the
    -- classification in @IsAnomalous@.
    DetectAnomalyResult -> Maybe Double
confidence :: Prelude.Maybe Prelude.Double,
    -- | True if Amazon Lookout for Vision classifies the image as containing an
    -- anomaly, otherwise false.
    DetectAnomalyResult -> Maybe Bool
isAnomalous :: Prelude.Maybe Prelude.Bool,
    -- | The source of the image that was analyzed. @direct@ means that the
    -- images was supplied from the local computer. No other values are
    -- supported.
    DetectAnomalyResult -> Maybe ImageSource
source :: Prelude.Maybe ImageSource
  }
  deriving (DetectAnomalyResult -> DetectAnomalyResult -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DetectAnomalyResult -> DetectAnomalyResult -> Bool
$c/= :: DetectAnomalyResult -> DetectAnomalyResult -> Bool
== :: DetectAnomalyResult -> DetectAnomalyResult -> Bool
$c== :: DetectAnomalyResult -> DetectAnomalyResult -> Bool
Prelude.Eq, ReadPrec [DetectAnomalyResult]
ReadPrec DetectAnomalyResult
Int -> ReadS DetectAnomalyResult
ReadS [DetectAnomalyResult]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DetectAnomalyResult]
$creadListPrec :: ReadPrec [DetectAnomalyResult]
readPrec :: ReadPrec DetectAnomalyResult
$creadPrec :: ReadPrec DetectAnomalyResult
readList :: ReadS [DetectAnomalyResult]
$creadList :: ReadS [DetectAnomalyResult]
readsPrec :: Int -> ReadS DetectAnomalyResult
$creadsPrec :: Int -> ReadS DetectAnomalyResult
Prelude.Read, Int -> DetectAnomalyResult -> ShowS
[DetectAnomalyResult] -> ShowS
DetectAnomalyResult -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DetectAnomalyResult] -> ShowS
$cshowList :: [DetectAnomalyResult] -> ShowS
show :: DetectAnomalyResult -> String
$cshow :: DetectAnomalyResult -> String
showsPrec :: Int -> DetectAnomalyResult -> ShowS
$cshowsPrec :: Int -> DetectAnomalyResult -> ShowS
Prelude.Show, forall x. Rep DetectAnomalyResult x -> DetectAnomalyResult
forall x. DetectAnomalyResult -> Rep DetectAnomalyResult x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DetectAnomalyResult x -> DetectAnomalyResult
$cfrom :: forall x. DetectAnomalyResult -> Rep DetectAnomalyResult x
Prelude.Generic)

-- |
-- Create a value of 'DetectAnomalyResult' 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:
--
-- 'anomalies', 'detectAnomalyResult_anomalies' - If the model is an image segmentation model, @Anomalies@ contains a list
-- of anomaly types found in the image. There is one entry for each type of
-- anomaly found (even if multiple instances of an anomaly type exist on
-- the image). The first element in the list is always an anomaly type
-- representing the image background (\'background\') and shouldn\'t be
-- considered an anomaly. Amazon Lookout for Vision automatically add the
-- background anomaly type to the response, and you don\'t need to declare
-- a background anomaly type in your dataset.
--
-- If the list has one entry (\'background\'), no anomalies were found on
-- the image.
--
-- An image classification model doesn\'t return an @Anomalies@ list.
--
-- 'anomalyMask', 'detectAnomalyResult_anomalyMask' - If the model is an image segmentation model, @AnomalyMask@ contains
-- pixel masks that covers all anomaly types found on the image. Each
-- anomaly type has a different mask color. To map a color to an anomaly
-- type, see the @color@ field of the PixelAnomaly object.
--
-- An image classification model doesn\'t return an @Anomalies@ list.--
-- -- /Note:/ This 'Lens' automatically encodes and decodes Base64 data.
-- -- The underlying isomorphism will encode to Base64 representation during
-- -- serialisation, and decode from Base64 representation during deserialisation.
-- -- This 'Lens' accepts and returns only raw unencoded data.
--
-- 'confidence', 'detectAnomalyResult_confidence' - The confidence that Lookout for Vision has in the accuracy of the
-- classification in @IsAnomalous@.
--
-- 'isAnomalous', 'detectAnomalyResult_isAnomalous' - True if Amazon Lookout for Vision classifies the image as containing an
-- anomaly, otherwise false.
--
-- 'source', 'detectAnomalyResult_source' - The source of the image that was analyzed. @direct@ means that the
-- images was supplied from the local computer. No other values are
-- supported.
newDetectAnomalyResult ::
  DetectAnomalyResult
newDetectAnomalyResult :: DetectAnomalyResult
newDetectAnomalyResult =
  DetectAnomalyResult'
    { $sel:anomalies:DetectAnomalyResult' :: Maybe [Anomaly]
anomalies = forall a. Maybe a
Prelude.Nothing,
      $sel:anomalyMask:DetectAnomalyResult' :: Maybe Base64
anomalyMask = forall a. Maybe a
Prelude.Nothing,
      $sel:confidence:DetectAnomalyResult' :: Maybe Double
confidence = forall a. Maybe a
Prelude.Nothing,
      $sel:isAnomalous:DetectAnomalyResult' :: Maybe Bool
isAnomalous = forall a. Maybe a
Prelude.Nothing,
      $sel:source:DetectAnomalyResult' :: Maybe ImageSource
source = forall a. Maybe a
Prelude.Nothing
    }

-- | If the model is an image segmentation model, @Anomalies@ contains a list
-- of anomaly types found in the image. There is one entry for each type of
-- anomaly found (even if multiple instances of an anomaly type exist on
-- the image). The first element in the list is always an anomaly type
-- representing the image background (\'background\') and shouldn\'t be
-- considered an anomaly. Amazon Lookout for Vision automatically add the
-- background anomaly type to the response, and you don\'t need to declare
-- a background anomaly type in your dataset.
--
-- If the list has one entry (\'background\'), no anomalies were found on
-- the image.
--
-- An image classification model doesn\'t return an @Anomalies@ list.
detectAnomalyResult_anomalies :: Lens.Lens' DetectAnomalyResult (Prelude.Maybe [Anomaly])
detectAnomalyResult_anomalies :: Lens' DetectAnomalyResult (Maybe [Anomaly])
detectAnomalyResult_anomalies = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetectAnomalyResult' {Maybe [Anomaly]
anomalies :: Maybe [Anomaly]
$sel:anomalies:DetectAnomalyResult' :: DetectAnomalyResult -> Maybe [Anomaly]
anomalies} -> Maybe [Anomaly]
anomalies) (\s :: DetectAnomalyResult
s@DetectAnomalyResult' {} Maybe [Anomaly]
a -> DetectAnomalyResult
s {$sel:anomalies:DetectAnomalyResult' :: Maybe [Anomaly]
anomalies = Maybe [Anomaly]
a} :: DetectAnomalyResult) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | If the model is an image segmentation model, @AnomalyMask@ contains
-- pixel masks that covers all anomaly types found on the image. Each
-- anomaly type has a different mask color. To map a color to an anomaly
-- type, see the @color@ field of the PixelAnomaly object.
--
-- An image classification model doesn\'t return an @Anomalies@ list.--
-- -- /Note:/ This 'Lens' automatically encodes and decodes Base64 data.
-- -- The underlying isomorphism will encode to Base64 representation during
-- -- serialisation, and decode from Base64 representation during deserialisation.
-- -- This 'Lens' accepts and returns only raw unencoded data.
detectAnomalyResult_anomalyMask :: Lens.Lens' DetectAnomalyResult (Prelude.Maybe Prelude.ByteString)
detectAnomalyResult_anomalyMask :: Lens' DetectAnomalyResult (Maybe ByteString)
detectAnomalyResult_anomalyMask = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetectAnomalyResult' {Maybe Base64
anomalyMask :: Maybe Base64
$sel:anomalyMask:DetectAnomalyResult' :: DetectAnomalyResult -> Maybe Base64
anomalyMask} -> Maybe Base64
anomalyMask) (\s :: DetectAnomalyResult
s@DetectAnomalyResult' {} Maybe Base64
a -> DetectAnomalyResult
s {$sel:anomalyMask:DetectAnomalyResult' :: Maybe Base64
anomalyMask = Maybe Base64
a} :: DetectAnomalyResult) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping Iso' Base64 ByteString
Data._Base64

-- | The confidence that Lookout for Vision has in the accuracy of the
-- classification in @IsAnomalous@.
detectAnomalyResult_confidence :: Lens.Lens' DetectAnomalyResult (Prelude.Maybe Prelude.Double)
detectAnomalyResult_confidence :: Lens' DetectAnomalyResult (Maybe Double)
detectAnomalyResult_confidence = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetectAnomalyResult' {Maybe Double
confidence :: Maybe Double
$sel:confidence:DetectAnomalyResult' :: DetectAnomalyResult -> Maybe Double
confidence} -> Maybe Double
confidence) (\s :: DetectAnomalyResult
s@DetectAnomalyResult' {} Maybe Double
a -> DetectAnomalyResult
s {$sel:confidence:DetectAnomalyResult' :: Maybe Double
confidence = Maybe Double
a} :: DetectAnomalyResult)

-- | True if Amazon Lookout for Vision classifies the image as containing an
-- anomaly, otherwise false.
detectAnomalyResult_isAnomalous :: Lens.Lens' DetectAnomalyResult (Prelude.Maybe Prelude.Bool)
detectAnomalyResult_isAnomalous :: Lens' DetectAnomalyResult (Maybe Bool)
detectAnomalyResult_isAnomalous = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetectAnomalyResult' {Maybe Bool
isAnomalous :: Maybe Bool
$sel:isAnomalous:DetectAnomalyResult' :: DetectAnomalyResult -> Maybe Bool
isAnomalous} -> Maybe Bool
isAnomalous) (\s :: DetectAnomalyResult
s@DetectAnomalyResult' {} Maybe Bool
a -> DetectAnomalyResult
s {$sel:isAnomalous:DetectAnomalyResult' :: Maybe Bool
isAnomalous = Maybe Bool
a} :: DetectAnomalyResult)

-- | The source of the image that was analyzed. @direct@ means that the
-- images was supplied from the local computer. No other values are
-- supported.
detectAnomalyResult_source :: Lens.Lens' DetectAnomalyResult (Prelude.Maybe ImageSource)
detectAnomalyResult_source :: Lens' DetectAnomalyResult (Maybe ImageSource)
detectAnomalyResult_source = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetectAnomalyResult' {Maybe ImageSource
source :: Maybe ImageSource
$sel:source:DetectAnomalyResult' :: DetectAnomalyResult -> Maybe ImageSource
source} -> Maybe ImageSource
source) (\s :: DetectAnomalyResult
s@DetectAnomalyResult' {} Maybe ImageSource
a -> DetectAnomalyResult
s {$sel:source:DetectAnomalyResult' :: Maybe ImageSource
source = Maybe ImageSource
a} :: DetectAnomalyResult)

instance Data.FromJSON DetectAnomalyResult where
  parseJSON :: Value -> Parser DetectAnomalyResult
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"DetectAnomalyResult"
      ( \Object
x ->
          Maybe [Anomaly]
-> Maybe Base64
-> Maybe Double
-> Maybe Bool
-> Maybe ImageSource
-> DetectAnomalyResult
DetectAnomalyResult'
            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
"Anomalies" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            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
"AnomalyMask")
            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
"Confidence")
            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
"IsAnomalous")
            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
"Source")
      )

instance Prelude.Hashable DetectAnomalyResult where
  hashWithSalt :: Int -> DetectAnomalyResult -> Int
hashWithSalt Int
_salt DetectAnomalyResult' {Maybe Bool
Maybe Double
Maybe [Anomaly]
Maybe Base64
Maybe ImageSource
source :: Maybe ImageSource
isAnomalous :: Maybe Bool
confidence :: Maybe Double
anomalyMask :: Maybe Base64
anomalies :: Maybe [Anomaly]
$sel:source:DetectAnomalyResult' :: DetectAnomalyResult -> Maybe ImageSource
$sel:isAnomalous:DetectAnomalyResult' :: DetectAnomalyResult -> Maybe Bool
$sel:confidence:DetectAnomalyResult' :: DetectAnomalyResult -> Maybe Double
$sel:anomalyMask:DetectAnomalyResult' :: DetectAnomalyResult -> Maybe Base64
$sel:anomalies:DetectAnomalyResult' :: DetectAnomalyResult -> Maybe [Anomaly]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Anomaly]
anomalies
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Base64
anomalyMask
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Double
confidence
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
isAnomalous
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ImageSource
source

instance Prelude.NFData DetectAnomalyResult where
  rnf :: DetectAnomalyResult -> ()
rnf DetectAnomalyResult' {Maybe Bool
Maybe Double
Maybe [Anomaly]
Maybe Base64
Maybe ImageSource
source :: Maybe ImageSource
isAnomalous :: Maybe Bool
confidence :: Maybe Double
anomalyMask :: Maybe Base64
anomalies :: Maybe [Anomaly]
$sel:source:DetectAnomalyResult' :: DetectAnomalyResult -> Maybe ImageSource
$sel:isAnomalous:DetectAnomalyResult' :: DetectAnomalyResult -> Maybe Bool
$sel:confidence:DetectAnomalyResult' :: DetectAnomalyResult -> Maybe Double
$sel:anomalyMask:DetectAnomalyResult' :: DetectAnomalyResult -> Maybe Base64
$sel:anomalies:DetectAnomalyResult' :: DetectAnomalyResult -> Maybe [Anomaly]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Anomaly]
anomalies
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Base64
anomalyMask
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Double
confidence
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
isAnomalous
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe ImageSource
source