<commit_before>{-# LANGUAGE DataKinds         #-}
{-# LANGUAGE KindSignatures    #-}
{-# LANGUAGE OverloadedStrings #-}

-- Module      : Gen.Types
-- Copyright   : (c) 2015 <NAME>
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : <NAME> <<EMAIL>>
-- Stability   : provisional
-- Portability : non-portable (GHC extensions)

module Gen.Types where

import qualified Data.Attoparsec.Text      as A
import           Data.Function             (on)
import qualified Data.HashMap.Strict       as Map
import           Data.List                 (nub, sort)
import           Data.Monoid
import           Data.Text                 (Text)
import qualified Data.Text                 as Text
import qualified Data.Text.Lazy            as LText
import qualified Filesystem.Path.CurrentOS as Path
import           GHC.TypeLits
import           Text.EDE                  (Template)

type Map   = Map.HashMap
type Error = LText.Text
type Path  = Path.FilePath

toTextIgnore :: Path -> Text
toTextIgnore = either id id . Path.toText

data Templates = Templates
    { cabalTemplate     :: Template
    , tocTemplate       :: Template
    , readmeTemplate    :: Template
    , operationTemplate :: Template
    , typesTemplate     :: Template
    }

newtype Version (v :: Symbol) = Version Text
    deriving (Eq, Show)

type LibraryVer = Version "library"
type ClientVer  = Version "client"
type CoreVer    = Version "core"

data Versions = Versions
    { _libraryVersion :: LibraryVer
    , _clientVersion  :: ClientVer
    , _coreVersion    :: CoreVer
    } deriving (Show)

-- FIXME: need a more comprehensive 'vm_alpha' vs 'vm1.1' etc check.
data Spec = Spec
    { _specName    :: Text
    , _specPrefix  :: Text
    , _specVersion :: Text
    , _specPath    :: Path
    }

instance Eq Spec where
    (==) = on (==) _specPrefix

instance Ord Spec where
    compare a b = on compare _specPrefix a b <> on compare _specVersion a b

specFromPath :: Path -> Spec
specFromPath x = Spec (n <> v) p v x
  where
   n = Text.intercalate "/"
     . drop 1
     . dropWhile (/= "model")
     $ Text.split (== '/') p

   p = toTextIgnore (Path.parent (Path.parent x))
   v = toTextIgnore (Path.dirname x)
<commit_msg>Ensuring latest version of a service definition is used<commit_after>{-# LANGUAGE DataKinds         #-}
{-# LANGUAGE KindSignatures    #-}
{-# LANGUAGE OverloadedStrings #-}

-- Module      : Gen.Types
-- Copyright   : (c) 2015 <NAME>
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : <NAME> <<EMAIL>>
-- Stability   : provisional
-- Portability : non-portable (GHC extensions)

module Gen.Types where

import qualified Data.Attoparsec.Text      as A
import           Data.Function             (on)
import qualified Data.HashMap.Strict       as Map
import           Data.List                 (nub, sort)
import           Data.Monoid
import           Data.Ord
import           Data.Text                 (Text)
import qualified Data.Text                 as Text
import qualified Data.Text.Lazy            as LText
import qualified Filesystem.Path.CurrentOS as Path
import           GHC.TypeLits
import           Text.EDE                  (Template)

type Map   = Map.HashMap
type Error = LText.Text
type Path  = Path.FilePath

toTextIgnore :: Path -> Text
toTextIgnore = either id id . Path.toText

data Templates = Templates
    { cabalTemplate     :: Template
    , tocTemplate       :: Template
    , readmeTemplate    :: Template
    , operationTemplate :: Template
    , typesTemplate     :: Template
    }

newtype Version (v :: Symbol) = Version Text
    deriving (Eq, Show)

type LibraryVer = Version "library"
type ClientVer  = Version "client"
type CoreVer    = Version "core"

data Versions = Versions
    { _libraryVersion :: LibraryVer
    , _clientVersion  :: ClientVer
    , _coreVersion    :: CoreVer
    } deriving (Show)

-- FIXME: need a more comprehensive 'vm_alpha' vs 'vm1.1' etc check.
data Spec = Spec
    { _specName    :: Text
    , _specPrefix  :: Text
    , _specVersion :: Text
    , _specPath    :: Path
    }

instance Eq Spec where
    (==) = on (==) _specPrefix

instance Ord Spec where
    compare a b =
           on compare _specPrefix a b
        <> on compare (Down . _specVersion) a b

specFromPath :: Path -> Spec
specFromPath x = Spec (n <> v) p v x
  where
   n = Text.intercalate "/"
     . drop 1
     . dropWhile (/= "model")
     $ Text.split (== '/') p

   p = toTextIgnore (Path.parent (Path.parent x))
   v = toTextIgnore (Path.dirname x)

{'fraction_non_alphanumeric': 0.09804791481810116, 'fraction_numerical': 0.003992901508429458, 'mean_word_length': 2.2207142857142856, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3352535', 'n_tokens_mistral': 1357, 'n_tokens_neox': 1332, 'n_words': 427}