{-# 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.Forecast.Types.FeaturizationConfig
-- 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.Forecast.Types.FeaturizationConfig where

import qualified Amazonka.Core as Core
import Amazonka.Forecast.Types.Featurization
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | In a CreatePredictor operation, the specified algorithm trains a model
-- using the specified dataset group. You can optionally tell the operation
-- to modify data fields prior to training a model. These modifications are
-- referred to as /featurization/.
--
-- You define featurization using the @FeaturizationConfig@ object. You
-- specify an array of transformations, one for each field that you want to
-- featurize. You then include the @FeaturizationConfig@ object in your
-- @CreatePredictor@ request. Amazon Forecast applies the featurization to
-- the @TARGET_TIME_SERIES@ and @RELATED_TIME_SERIES@ datasets before model
-- training.
--
-- You can create multiple featurization configurations. For example, you
-- might call the @CreatePredictor@ operation twice by specifying different
-- featurization configurations.
--
-- /See:/ 'newFeaturizationConfig' smart constructor.
data FeaturizationConfig = FeaturizationConfig'
  { -- | An array of featurization (transformation) information for the fields of
    -- a dataset.
    FeaturizationConfig -> Maybe (NonEmpty Featurization)
featurizations :: Prelude.Maybe (Prelude.NonEmpty Featurization),
    -- | An array of dimension (field) names that specify how to group the
    -- generated forecast.
    --
    -- For example, suppose that you are generating a forecast for item sales
    -- across all of your stores, and your dataset contains a @store_id@ field.
    -- If you want the sales forecast for each item by store, you would specify
    -- @store_id@ as the dimension.
    --
    -- All forecast dimensions specified in the @TARGET_TIME_SERIES@ dataset
    -- don\'t need to be specified in the @CreatePredictor@ request. All
    -- forecast dimensions specified in the @RELATED_TIME_SERIES@ dataset must
    -- be specified in the @CreatePredictor@ request.
    FeaturizationConfig -> Maybe (NonEmpty Text)
forecastDimensions :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text),
    -- | The frequency of predictions in a forecast.
    --
    -- Valid intervals are Y (Year), M (Month), W (Week), D (Day), H (Hour),
    -- 30min (30 minutes), 15min (15 minutes), 10min (10 minutes), 5min (5
    -- minutes), and 1min (1 minute). For example, \"Y\" indicates every year
    -- and \"5min\" indicates every five minutes.
    --
    -- The frequency must be greater than or equal to the TARGET_TIME_SERIES
    -- dataset frequency.
    --
    -- When a RELATED_TIME_SERIES dataset is provided, the frequency must be
    -- equal to the RELATED_TIME_SERIES dataset frequency.
    FeaturizationConfig -> Text
forecastFrequency :: Prelude.Text
  }
  deriving (FeaturizationConfig -> FeaturizationConfig -> Bool
(FeaturizationConfig -> FeaturizationConfig -> Bool)
-> (FeaturizationConfig -> FeaturizationConfig -> Bool)
-> Eq FeaturizationConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FeaturizationConfig -> FeaturizationConfig -> Bool
$c/= :: FeaturizationConfig -> FeaturizationConfig -> Bool
== :: FeaturizationConfig -> FeaturizationConfig -> Bool
$c== :: FeaturizationConfig -> FeaturizationConfig -> Bool
Prelude.Eq, ReadPrec [FeaturizationConfig]
ReadPrec FeaturizationConfig
Int -> ReadS FeaturizationConfig
ReadS [FeaturizationConfig]
(Int -> ReadS FeaturizationConfig)
-> ReadS [FeaturizationConfig]
-> ReadPrec FeaturizationConfig
-> ReadPrec [FeaturizationConfig]
-> Read FeaturizationConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FeaturizationConfig]
$creadListPrec :: ReadPrec [FeaturizationConfig]
readPrec :: ReadPrec FeaturizationConfig
$creadPrec :: ReadPrec FeaturizationConfig
readList :: ReadS [FeaturizationConfig]
$creadList :: ReadS [FeaturizationConfig]
readsPrec :: Int -> ReadS FeaturizationConfig
$creadsPrec :: Int -> ReadS FeaturizationConfig
Prelude.Read, Int -> FeaturizationConfig -> ShowS
[FeaturizationConfig] -> ShowS
FeaturizationConfig -> String
(Int -> FeaturizationConfig -> ShowS)
-> (FeaturizationConfig -> String)
-> ([FeaturizationConfig] -> ShowS)
-> Show FeaturizationConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FeaturizationConfig] -> ShowS
$cshowList :: [FeaturizationConfig] -> ShowS
show :: FeaturizationConfig -> String
$cshow :: FeaturizationConfig -> String
showsPrec :: Int -> FeaturizationConfig -> ShowS
$cshowsPrec :: Int -> FeaturizationConfig -> ShowS
Prelude.Show, (forall x. FeaturizationConfig -> Rep FeaturizationConfig x)
-> (forall x. Rep FeaturizationConfig x -> FeaturizationConfig)
-> Generic FeaturizationConfig
forall x. Rep FeaturizationConfig x -> FeaturizationConfig
forall x. FeaturizationConfig -> Rep FeaturizationConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FeaturizationConfig x -> FeaturizationConfig
$cfrom :: forall x. FeaturizationConfig -> Rep FeaturizationConfig x
Prelude.Generic)

-- |
-- Create a value of 'FeaturizationConfig' 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:
--
-- 'featurizations', 'featurizationConfig_featurizations' - An array of featurization (transformation) information for the fields of
-- a dataset.
--
-- 'forecastDimensions', 'featurizationConfig_forecastDimensions' - An array of dimension (field) names that specify how to group the
-- generated forecast.
--
-- For example, suppose that you are generating a forecast for item sales
-- across all of your stores, and your dataset contains a @store_id@ field.
-- If you want the sales forecast for each item by store, you would specify
-- @store_id@ as the dimension.
--
-- All forecast dimensions specified in the @TARGET_TIME_SERIES@ dataset
-- don\'t need to be specified in the @CreatePredictor@ request. All
-- forecast dimensions specified in the @RELATED_TIME_SERIES@ dataset must
-- be specified in the @CreatePredictor@ request.
--
-- 'forecastFrequency', 'featurizationConfig_forecastFrequency' - The frequency of predictions in a forecast.
--
-- Valid intervals are Y (Year), M (Month), W (Week), D (Day), H (Hour),
-- 30min (30 minutes), 15min (15 minutes), 10min (10 minutes), 5min (5
-- minutes), and 1min (1 minute). For example, \"Y\" indicates every year
-- and \"5min\" indicates every five minutes.
--
-- The frequency must be greater than or equal to the TARGET_TIME_SERIES
-- dataset frequency.
--
-- When a RELATED_TIME_SERIES dataset is provided, the frequency must be
-- equal to the RELATED_TIME_SERIES dataset frequency.
newFeaturizationConfig ::
  -- | 'forecastFrequency'
  Prelude.Text ->
  FeaturizationConfig
newFeaturizationConfig :: Text -> FeaturizationConfig
newFeaturizationConfig Text
pForecastFrequency_ =
  FeaturizationConfig' :: Maybe (NonEmpty Featurization)
-> Maybe (NonEmpty Text) -> Text -> FeaturizationConfig
FeaturizationConfig'
    { $sel:featurizations:FeaturizationConfig' :: Maybe (NonEmpty Featurization)
featurizations =
        Maybe (NonEmpty Featurization)
forall a. Maybe a
Prelude.Nothing,
      $sel:forecastDimensions:FeaturizationConfig' :: Maybe (NonEmpty Text)
forecastDimensions = Maybe (NonEmpty Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:forecastFrequency:FeaturizationConfig' :: Text
forecastFrequency = Text
pForecastFrequency_
    }

-- | An array of featurization (transformation) information for the fields of
-- a dataset.
featurizationConfig_featurizations :: Lens.Lens' FeaturizationConfig (Prelude.Maybe (Prelude.NonEmpty Featurization))
featurizationConfig_featurizations :: (Maybe (NonEmpty Featurization)
 -> f (Maybe (NonEmpty Featurization)))
-> FeaturizationConfig -> f FeaturizationConfig
featurizationConfig_featurizations = (FeaturizationConfig -> Maybe (NonEmpty Featurization))
-> (FeaturizationConfig
    -> Maybe (NonEmpty Featurization) -> FeaturizationConfig)
-> Lens
     FeaturizationConfig
     FeaturizationConfig
     (Maybe (NonEmpty Featurization))
     (Maybe (NonEmpty Featurization))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FeaturizationConfig' {Maybe (NonEmpty Featurization)
featurizations :: Maybe (NonEmpty Featurization)
$sel:featurizations:FeaturizationConfig' :: FeaturizationConfig -> Maybe (NonEmpty Featurization)
featurizations} -> Maybe (NonEmpty Featurization)
featurizations) (\s :: FeaturizationConfig
s@FeaturizationConfig' {} Maybe (NonEmpty Featurization)
a -> FeaturizationConfig
s {$sel:featurizations:FeaturizationConfig' :: Maybe (NonEmpty Featurization)
featurizations = Maybe (NonEmpty Featurization)
a} :: FeaturizationConfig) ((Maybe (NonEmpty Featurization)
  -> f (Maybe (NonEmpty Featurization)))
 -> FeaturizationConfig -> f FeaturizationConfig)
-> ((Maybe (NonEmpty Featurization)
     -> f (Maybe (NonEmpty Featurization)))
    -> Maybe (NonEmpty Featurization)
    -> f (Maybe (NonEmpty Featurization)))
-> (Maybe (NonEmpty Featurization)
    -> f (Maybe (NonEmpty Featurization)))
-> FeaturizationConfig
-> f FeaturizationConfig
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty Featurization)
  (NonEmpty Featurization)
  (NonEmpty Featurization)
  (NonEmpty Featurization)
-> Iso
     (Maybe (NonEmpty Featurization))
     (Maybe (NonEmpty Featurization))
     (Maybe (NonEmpty Featurization))
     (Maybe (NonEmpty Featurization))
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 AnIso
  (NonEmpty Featurization)
  (NonEmpty Featurization)
  (NonEmpty Featurization)
  (NonEmpty Featurization)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | An array of dimension (field) names that specify how to group the
-- generated forecast.
--
-- For example, suppose that you are generating a forecast for item sales
-- across all of your stores, and your dataset contains a @store_id@ field.
-- If you want the sales forecast for each item by store, you would specify
-- @store_id@ as the dimension.
--
-- All forecast dimensions specified in the @TARGET_TIME_SERIES@ dataset
-- don\'t need to be specified in the @CreatePredictor@ request. All
-- forecast dimensions specified in the @RELATED_TIME_SERIES@ dataset must
-- be specified in the @CreatePredictor@ request.
featurizationConfig_forecastDimensions :: Lens.Lens' FeaturizationConfig (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
featurizationConfig_forecastDimensions :: (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> FeaturizationConfig -> f FeaturizationConfig
featurizationConfig_forecastDimensions = (FeaturizationConfig -> Maybe (NonEmpty Text))
-> (FeaturizationConfig
    -> Maybe (NonEmpty Text) -> FeaturizationConfig)
-> Lens
     FeaturizationConfig
     FeaturizationConfig
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FeaturizationConfig' {Maybe (NonEmpty Text)
forecastDimensions :: Maybe (NonEmpty Text)
$sel:forecastDimensions:FeaturizationConfig' :: FeaturizationConfig -> Maybe (NonEmpty Text)
forecastDimensions} -> Maybe (NonEmpty Text)
forecastDimensions) (\s :: FeaturizationConfig
s@FeaturizationConfig' {} Maybe (NonEmpty Text)
a -> FeaturizationConfig
s {$sel:forecastDimensions:FeaturizationConfig' :: Maybe (NonEmpty Text)
forecastDimensions = Maybe (NonEmpty Text)
a} :: FeaturizationConfig) ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
 -> FeaturizationConfig -> f FeaturizationConfig)
-> ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
    -> Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> FeaturizationConfig
-> f FeaturizationConfig
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
-> Iso
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
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 AnIso
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The frequency of predictions in a forecast.
--
-- Valid intervals are Y (Year), M (Month), W (Week), D (Day), H (Hour),
-- 30min (30 minutes), 15min (15 minutes), 10min (10 minutes), 5min (5
-- minutes), and 1min (1 minute). For example, \"Y\" indicates every year
-- and \"5min\" indicates every five minutes.
--
-- The frequency must be greater than or equal to the TARGET_TIME_SERIES
-- dataset frequency.
--
-- When a RELATED_TIME_SERIES dataset is provided, the frequency must be
-- equal to the RELATED_TIME_SERIES dataset frequency.
featurizationConfig_forecastFrequency :: Lens.Lens' FeaturizationConfig Prelude.Text
featurizationConfig_forecastFrequency :: (Text -> f Text) -> FeaturizationConfig -> f FeaturizationConfig
featurizationConfig_forecastFrequency = (FeaturizationConfig -> Text)
-> (FeaturizationConfig -> Text -> FeaturizationConfig)
-> Lens FeaturizationConfig FeaturizationConfig Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FeaturizationConfig' {Text
forecastFrequency :: Text
$sel:forecastFrequency:FeaturizationConfig' :: FeaturizationConfig -> Text
forecastFrequency} -> Text
forecastFrequency) (\s :: FeaturizationConfig
s@FeaturizationConfig' {} Text
a -> FeaturizationConfig
s {$sel:forecastFrequency:FeaturizationConfig' :: Text
forecastFrequency = Text
a} :: FeaturizationConfig)

instance Core.FromJSON FeaturizationConfig where
  parseJSON :: Value -> Parser FeaturizationConfig
parseJSON =
    String
-> (Object -> Parser FeaturizationConfig)
-> Value
-> Parser FeaturizationConfig
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"FeaturizationConfig"
      ( \Object
x ->
          Maybe (NonEmpty Featurization)
-> Maybe (NonEmpty Text) -> Text -> FeaturizationConfig
FeaturizationConfig'
            (Maybe (NonEmpty Featurization)
 -> Maybe (NonEmpty Text) -> Text -> FeaturizationConfig)
-> Parser (Maybe (NonEmpty Featurization))
-> Parser (Maybe (NonEmpty Text) -> Text -> FeaturizationConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (NonEmpty Featurization))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Featurizations")
            Parser (Maybe (NonEmpty Text) -> Text -> FeaturizationConfig)
-> Parser (Maybe (NonEmpty Text))
-> Parser (Text -> FeaturizationConfig)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (NonEmpty Text))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ForecastDimensions")
            Parser (Text -> FeaturizationConfig)
-> Parser Text -> Parser FeaturizationConfig
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"ForecastFrequency")
      )

instance Prelude.Hashable FeaturizationConfig

instance Prelude.NFData FeaturizationConfig

instance Core.ToJSON FeaturizationConfig where
  toJSON :: FeaturizationConfig -> Value
toJSON FeaturizationConfig' {Maybe (NonEmpty Text)
Maybe (NonEmpty Featurization)
Text
forecastFrequency :: Text
forecastDimensions :: Maybe (NonEmpty Text)
featurizations :: Maybe (NonEmpty Featurization)
$sel:forecastFrequency:FeaturizationConfig' :: FeaturizationConfig -> Text
$sel:forecastDimensions:FeaturizationConfig' :: FeaturizationConfig -> Maybe (NonEmpty Text)
$sel:featurizations:FeaturizationConfig' :: FeaturizationConfig -> Maybe (NonEmpty Featurization)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Featurizations" Text -> NonEmpty Featurization -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (NonEmpty Featurization -> Pair)
-> Maybe (NonEmpty Featurization) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty Featurization)
featurizations,
            (Text
"ForecastDimensions" Text -> NonEmpty Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (NonEmpty Text -> Pair) -> Maybe (NonEmpty Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty Text)
forecastDimensions,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"ForecastFrequency" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
forecastFrequency)
          ]
      )