{-|
Module      : Gargantext.Database.Admin.Types.Hyperdata.Model
Description :
Copyright   : (c) CNRS, 2017-Present
License     : AGPL + CECILL v3
Maintainer  : team@gargantext.org
Stability   : experimental
Portability : POSIX

-}

{-# LANGUAGE DeriveGeneric              #-}
{-# LANGUAGE FlexibleContexts           #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses      #-}
{-# LANGUAGE NoImplicitPrelude          #-}
{-# LANGUAGE OverloadedStrings          #-}
{-# LANGUAGE RankNTypes                 #-}
{-# LANGUAGE TemplateHaskell            #-}

module Gargantext.Database.Admin.Types.Hyperdata.Model
  where

import Gargantext.Prelude
import Gargantext.Database.Admin.Types.Hyperdata.Prelude

------------------------------------------------------------------------
data HyperdataModel =
  HyperdataModel { HyperdataModel -> (Int, Int)
_hm_params  :: !(Int, Int)
                 , HyperdataModel -> Text
_hm_path    :: !Text
                 , HyperdataModel -> Maybe Double
_hm_score   :: !(Maybe Double)
                 } deriving (Int -> HyperdataModel -> ShowS
[HyperdataModel] -> ShowS
HyperdataModel -> String
(Int -> HyperdataModel -> ShowS)
-> (HyperdataModel -> String)
-> ([HyperdataModel] -> ShowS)
-> Show HyperdataModel
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HyperdataModel] -> ShowS
$cshowList :: [HyperdataModel] -> ShowS
show :: HyperdataModel -> String
$cshow :: HyperdataModel -> String
showsPrec :: Int -> HyperdataModel -> ShowS
$cshowsPrec :: Int -> HyperdataModel -> ShowS
Show, (forall x. HyperdataModel -> Rep HyperdataModel x)
-> (forall x. Rep HyperdataModel x -> HyperdataModel)
-> Generic HyperdataModel
forall x. Rep HyperdataModel x -> HyperdataModel
forall x. HyperdataModel -> Rep HyperdataModel x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep HyperdataModel x -> HyperdataModel
$cfrom :: forall x. HyperdataModel -> Rep HyperdataModel x
Generic)

defaultHyperdataModel :: HyperdataModel
defaultHyperdataModel :: HyperdataModel
defaultHyperdataModel = (Int, Int) -> Text -> Maybe Double -> HyperdataModel
HyperdataModel (Int
400,Int
500) Text
"data/models/test.model" (Double -> Maybe Double
forall a. a -> Maybe a
Just Double
0.83)

------------------------------------------------------------------------
-- Instances
------------------------------------------------------------------------
instance Hyperdata HyperdataModel
$(makeLenses ''HyperdataModel)
$(deriveJSON (unPrefix "_hm_") ''HyperdataModel)

instance Arbitrary HyperdataModel where
  arbitrary :: Gen HyperdataModel
arbitrary = HyperdataModel -> Gen HyperdataModel
forall (f :: * -> *) a. Applicative f => a -> f a
pure HyperdataModel
defaultHyperdataModel

instance FromField HyperdataModel
  where
    fromField :: FieldParser HyperdataModel
fromField = FieldParser HyperdataModel
forall b.
(Typeable b, FromJSON b) =>
Field -> Maybe ByteString -> Conversion b
fromField'

instance DefaultFromField PGJsonb HyperdataModel
  where
    defaultFromField :: FromField PGJsonb HyperdataModel
defaultFromField = FromField PGJsonb HyperdataModel
forall haskell pgType.
FromField haskell =>
FromField pgType haskell
fieldQueryRunnerColumn

instance ToSchema HyperdataModel where
  declareNamedSchema :: Proxy HyperdataModel -> Declare (Definitions Schema) NamedSchema
declareNamedSchema Proxy HyperdataModel
proxy =
    SchemaOptions
-> Proxy HyperdataModel -> Declare (Definitions Schema) NamedSchema
forall a.
(Generic a, GToSchema (Rep a),
 TypeHasSimpleShape a "genericDeclareNamedSchemaUnrestricted") =>
SchemaOptions
-> Proxy a -> Declare (Definitions Schema) NamedSchema
genericDeclareNamedSchema (String -> SchemaOptions
unPrefixSwagger String
"_hm_") Proxy HyperdataModel
proxy
    Declare (Definitions Schema) NamedSchema
-> (Declare (Definitions Schema) NamedSchema
    -> Declare (Definitions Schema) NamedSchema)
-> Declare (Definitions Schema) NamedSchema
forall a b. a -> (a -> b) -> b
& (NamedSchema -> Identity NamedSchema)
-> Declare (Definitions Schema) NamedSchema
-> Identity (Declare (Definitions Schema) NamedSchema)
forall (f :: * -> *) a b. Functor f => Setter (f a) (f b) a b
mapped((NamedSchema -> Identity NamedSchema)
 -> Declare (Definitions Schema) NamedSchema
 -> Identity (Declare (Definitions Schema) NamedSchema))
-> ((Maybe Text -> Identity (Maybe Text))
    -> NamedSchema -> Identity NamedSchema)
-> (Maybe Text -> Identity (Maybe Text))
-> Declare (Definitions Schema) NamedSchema
-> Identity (Declare (Definitions Schema) NamedSchema)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Schema -> Identity Schema) -> NamedSchema -> Identity NamedSchema
forall s a. HasSchema s a => Lens' s a
schema((Schema -> Identity Schema)
 -> NamedSchema -> Identity NamedSchema)
-> ((Maybe Text -> Identity (Maybe Text))
    -> Schema -> Identity Schema)
-> (Maybe Text -> Identity (Maybe Text))
-> NamedSchema
-> Identity NamedSchema
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Maybe Text -> Identity (Maybe Text)) -> Schema -> Identity Schema
forall s a. HasDescription s a => Lens' s a
description ((Maybe Text -> Identity (Maybe Text))
 -> Declare (Definitions Schema) NamedSchema
 -> Identity (Declare (Definitions Schema) NamedSchema))
-> Text
-> Declare (Definitions Schema) NamedSchema
-> Declare (Definitions Schema) NamedSchema
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Text
"Model Hyperdata"
    Declare (Definitions Schema) NamedSchema
-> (Declare (Definitions Schema) NamedSchema
    -> Declare (Definitions Schema) NamedSchema)
-> Declare (Definitions Schema) NamedSchema
forall a b. a -> (a -> b) -> b
& (NamedSchema -> Identity NamedSchema)
-> Declare (Definitions Schema) NamedSchema
-> Identity (Declare (Definitions Schema) NamedSchema)
forall (f :: * -> *) a b. Functor f => Setter (f a) (f b) a b
mapped((NamedSchema -> Identity NamedSchema)
 -> Declare (Definitions Schema) NamedSchema
 -> Identity (Declare (Definitions Schema) NamedSchema))
-> ((Maybe Value -> Identity (Maybe Value))
    -> NamedSchema -> Identity NamedSchema)
-> (Maybe Value -> Identity (Maybe Value))
-> Declare (Definitions Schema) NamedSchema
-> Identity (Declare (Definitions Schema) NamedSchema)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Schema -> Identity Schema) -> NamedSchema -> Identity NamedSchema
forall s a. HasSchema s a => Lens' s a
schema((Schema -> Identity Schema)
 -> NamedSchema -> Identity NamedSchema)
-> ((Maybe Value -> Identity (Maybe Value))
    -> Schema -> Identity Schema)
-> (Maybe Value -> Identity (Maybe Value))
-> NamedSchema
-> Identity NamedSchema
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Maybe Value -> Identity (Maybe Value))
-> Schema -> Identity Schema
forall s a. HasExample s a => Lens' s a
example ((Maybe Value -> Identity (Maybe Value))
 -> Declare (Definitions Schema) NamedSchema
 -> Identity (Declare (Definitions Schema) NamedSchema))
-> Value
-> Declare (Definitions Schema) NamedSchema
-> Declare (Definitions Schema) NamedSchema
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ HyperdataModel -> Value
forall a. ToJSON a => a -> Value
toJSON HyperdataModel
defaultHyperdataModel