module Simulation.Aivika.Results.Locale.Types
(
ResultLocale,
ResultLocalisation(..),
ResultName,
ResultDescription,
UserDefinedResult(..),
LocalisedResult(..),
russianResultLocale,
englishResultLocale,
pathResultLocalisation,
localisePathResultDescription,
localisePathResultTitle,
lookupResultLocalisation,
ResultId(..),
resultNameToTitle) where
import Data.Char
import Data.List
import qualified Data.Map as M
import Simulation.Aivika.Dynamics
import Simulation.Aivika.Statistics
import Simulation.Aivika.Statistics.Accumulator
import qualified Simulation.Aivika.Queue as Q
import qualified Simulation.Aivika.Queue.Infinite as IQ
import Simulation.Aivika.Arrival
import Simulation.Aivika.Server
import Simulation.Aivika.Activity
import Simulation.Aivika.Resource
import Simulation.Aivika.Operation
type ResultLocale = String
data ResultLocalisation =
ResultLocalisation { ResultLocalisation -> ResultId -> ResultDescription
localiseResultDescription :: ResultId -> ResultDescription,
ResultLocalisation -> ResultId -> ResultDescription
localiseResultTitle :: ResultId -> ResultDescription
}
data UserDefinedResult =
UserDefinedResult { UserDefinedResult -> ResultDescription
userDefinedResultName :: ResultName,
UserDefinedResult -> ResultDescription
userDefinedResultDescription :: ResultDescription,
UserDefinedResult -> ResultDescription
userDefinedResultTitle :: ResultDescription
} deriving (UserDefinedResult -> UserDefinedResult -> Bool
(UserDefinedResult -> UserDefinedResult -> Bool)
-> (UserDefinedResult -> UserDefinedResult -> Bool)
-> Eq UserDefinedResult
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UserDefinedResult -> UserDefinedResult -> Bool
$c/= :: UserDefinedResult -> UserDefinedResult -> Bool
== :: UserDefinedResult -> UserDefinedResult -> Bool
$c== :: UserDefinedResult -> UserDefinedResult -> Bool
Eq, Eq UserDefinedResult
Eq UserDefinedResult
-> (UserDefinedResult -> UserDefinedResult -> Ordering)
-> (UserDefinedResult -> UserDefinedResult -> Bool)
-> (UserDefinedResult -> UserDefinedResult -> Bool)
-> (UserDefinedResult -> UserDefinedResult -> Bool)
-> (UserDefinedResult -> UserDefinedResult -> Bool)
-> (UserDefinedResult -> UserDefinedResult -> UserDefinedResult)
-> (UserDefinedResult -> UserDefinedResult -> UserDefinedResult)
-> Ord UserDefinedResult
UserDefinedResult -> UserDefinedResult -> Bool
UserDefinedResult -> UserDefinedResult -> Ordering
UserDefinedResult -> UserDefinedResult -> UserDefinedResult
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: UserDefinedResult -> UserDefinedResult -> UserDefinedResult
$cmin :: UserDefinedResult -> UserDefinedResult -> UserDefinedResult
max :: UserDefinedResult -> UserDefinedResult -> UserDefinedResult
$cmax :: UserDefinedResult -> UserDefinedResult -> UserDefinedResult
>= :: UserDefinedResult -> UserDefinedResult -> Bool
$c>= :: UserDefinedResult -> UserDefinedResult -> Bool
> :: UserDefinedResult -> UserDefinedResult -> Bool
$c> :: UserDefinedResult -> UserDefinedResult -> Bool
<= :: UserDefinedResult -> UserDefinedResult -> Bool
$c<= :: UserDefinedResult -> UserDefinedResult -> Bool
< :: UserDefinedResult -> UserDefinedResult -> Bool
$c< :: UserDefinedResult -> UserDefinedResult -> Bool
compare :: UserDefinedResult -> UserDefinedResult -> Ordering
$ccompare :: UserDefinedResult -> UserDefinedResult -> Ordering
$cp1Ord :: Eq UserDefinedResult
Ord, Int -> UserDefinedResult -> ShowS
[UserDefinedResult] -> ShowS
UserDefinedResult -> ResultDescription
(Int -> UserDefinedResult -> ShowS)
-> (UserDefinedResult -> ResultDescription)
-> ([UserDefinedResult] -> ShowS)
-> Show UserDefinedResult
forall a.
(Int -> a -> ShowS)
-> (a -> ResultDescription) -> ([a] -> ShowS) -> Show a
showList :: [UserDefinedResult] -> ShowS
$cshowList :: [UserDefinedResult] -> ShowS
show :: UserDefinedResult -> ResultDescription
$cshow :: UserDefinedResult -> ResultDescription
showsPrec :: Int -> UserDefinedResult -> ShowS
$cshowsPrec :: Int -> UserDefinedResult -> ShowS
Show)
data LocalisedResult =
LocalisedResult { LocalisedResult -> Map ResultDescription ResultDescription
localisedResultDescriptions :: M.Map ResultLocale ResultDescription,
LocalisedResult -> Map ResultDescription ResultDescription
localisedResultTitles :: M.Map ResultLocale ResultDescription
} deriving (LocalisedResult -> LocalisedResult -> Bool
(LocalisedResult -> LocalisedResult -> Bool)
-> (LocalisedResult -> LocalisedResult -> Bool)
-> Eq LocalisedResult
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LocalisedResult -> LocalisedResult -> Bool
$c/= :: LocalisedResult -> LocalisedResult -> Bool
== :: LocalisedResult -> LocalisedResult -> Bool
$c== :: LocalisedResult -> LocalisedResult -> Bool
Eq, Eq LocalisedResult
Eq LocalisedResult
-> (LocalisedResult -> LocalisedResult -> Ordering)
-> (LocalisedResult -> LocalisedResult -> Bool)
-> (LocalisedResult -> LocalisedResult -> Bool)
-> (LocalisedResult -> LocalisedResult -> Bool)
-> (LocalisedResult -> LocalisedResult -> Bool)
-> (LocalisedResult -> LocalisedResult -> LocalisedResult)
-> (LocalisedResult -> LocalisedResult -> LocalisedResult)
-> Ord LocalisedResult
LocalisedResult -> LocalisedResult -> Bool
LocalisedResult -> LocalisedResult -> Ordering
LocalisedResult -> LocalisedResult -> LocalisedResult
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: LocalisedResult -> LocalisedResult -> LocalisedResult
$cmin :: LocalisedResult -> LocalisedResult -> LocalisedResult
max :: LocalisedResult -> LocalisedResult -> LocalisedResult
$cmax :: LocalisedResult -> LocalisedResult -> LocalisedResult
>= :: LocalisedResult -> LocalisedResult -> Bool
$c>= :: LocalisedResult -> LocalisedResult -> Bool
> :: LocalisedResult -> LocalisedResult -> Bool
$c> :: LocalisedResult -> LocalisedResult -> Bool
<= :: LocalisedResult -> LocalisedResult -> Bool
$c<= :: LocalisedResult -> LocalisedResult -> Bool
< :: LocalisedResult -> LocalisedResult -> Bool
$c< :: LocalisedResult -> LocalisedResult -> Bool
compare :: LocalisedResult -> LocalisedResult -> Ordering
$ccompare :: LocalisedResult -> LocalisedResult -> Ordering
$cp1Ord :: Eq LocalisedResult
Ord, Int -> LocalisedResult -> ShowS
[LocalisedResult] -> ShowS
LocalisedResult -> ResultDescription
(Int -> LocalisedResult -> ShowS)
-> (LocalisedResult -> ResultDescription)
-> ([LocalisedResult] -> ShowS)
-> Show LocalisedResult
forall a.
(Int -> a -> ShowS)
-> (a -> ResultDescription) -> ([a] -> ShowS) -> Show a
showList :: [LocalisedResult] -> ShowS
$cshowList :: [LocalisedResult] -> ShowS
show :: LocalisedResult -> ResultDescription
$cshow :: LocalisedResult -> ResultDescription
showsPrec :: Int -> LocalisedResult -> ShowS
$cshowsPrec :: Int -> LocalisedResult -> ShowS
Show)
type ResultName = String
type ResultDescription = String
data ResultId = TimeId
| VectorId
| VectorItemId String
| SamplingStatsId
| SamplingStatsCountId
| SamplingStatsMinId
| SamplingStatsMaxId
| SamplingStatsMeanId
| SamplingStatsMean2Id
| SamplingStatsVarianceId
| SamplingStatsDeviationId
| SamplingCounterId
| SamplingCounterValueId
| SamplingCounterStatsId
| TimingStatsId
| TimingStatsCountId
| TimingStatsMinId
| TimingStatsMaxId
| TimingStatsMeanId
| TimingStatsVarianceId
| TimingStatsDeviationId
| TimingStatsMinTimeId
| TimingStatsMaxTimeId
| TimingStatsStartTimeId
| TimingStatsLastTimeId
| TimingStatsSumId
| TimingStatsSum2Id
| TimingCounterId
| TimingCounterValueId
| TimingCounterStatsId
| FiniteQueueId
| InfiniteQueueId
| EnqueueStrategyId
| EnqueueStoringStrategyId
| DequeueStrategyId
| QueueNullId
| QueueFullId
| QueueMaxCountId
| QueueCountId
| QueueCountStatsId
| EnqueueCountId
| EnqueueLostCountId
| EnqueueStoreCountId
| DequeueCountId
|
| QueueLoadFactorId
| EnqueueRateId
| EnqueueStoreRateId
| DequeueRateId
|
| QueueWaitTimeId
| QueueTotalWaitTimeId
| EnqueueWaitTimeId
| DequeueWaitTimeId
| QueueRateId
| ArrivalTimerId
| ArrivalProcessingTimeId
| ServerId
| ServerInitStateId
| ServerStateId
| ServerTotalInputWaitTimeId
| ServerTotalProcessingTimeId
| ServerTotalOutputWaitTimeId
| ServerTotalPreemptionTimeId
| ServerInputWaitTimeId
| ServerProcessingTimeId
| ServerOutputWaitTimeId
| ServerPreemptionTimeId
| ServerInputWaitFactorId
| ServerProcessingFactorId
| ServerOutputWaitFactorId
| ServerPreemptionFactorId
| ActivityId
| ActivityInitStateId
| ActivityStateId
| ActivityTotalUtilisationTimeId
| ActivityTotalIdleTimeId
| ActivityTotalPreemptionTimeId
| ActivityUtilisationTimeId
| ActivityIdleTimeId
| ActivityPreemptionTimeId
| ActivityUtilisationFactorId
| ActivityIdleFactorId
| ActivityPreemptionFactorId
| ResourceId
| ResourceCountId
| ResourceCountStatsId
| ResourceUtilisationCountId
| ResourceUtilisationCountStatsId
| ResourceQueueCountId
| ResourceQueueCountStatsId
| ResourceTotalWaitTimeId
| ResourceWaitTimeId
| OperationId
| OperationTotalUtilisationTimeId
| OperationTotalPreemptionTimeId
| OperationUtilisationTimeId
| OperationPreemptionTimeId
| OperationUtilisationFactorId
| OperationPreemptionFactorId
| UserDefinedResultId UserDefinedResult
| LocalisedResultId LocalisedResult
deriving (ResultId -> ResultId -> Bool
(ResultId -> ResultId -> Bool)
-> (ResultId -> ResultId -> Bool) -> Eq ResultId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResultId -> ResultId -> Bool
$c/= :: ResultId -> ResultId -> Bool
== :: ResultId -> ResultId -> Bool
$c== :: ResultId -> ResultId -> Bool
Eq, Eq ResultId
Eq ResultId
-> (ResultId -> ResultId -> Ordering)
-> (ResultId -> ResultId -> Bool)
-> (ResultId -> ResultId -> Bool)
-> (ResultId -> ResultId -> Bool)
-> (ResultId -> ResultId -> Bool)
-> (ResultId -> ResultId -> ResultId)
-> (ResultId -> ResultId -> ResultId)
-> Ord ResultId
ResultId -> ResultId -> Bool
ResultId -> ResultId -> Ordering
ResultId -> ResultId -> ResultId
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ResultId -> ResultId -> ResultId
$cmin :: ResultId -> ResultId -> ResultId
max :: ResultId -> ResultId -> ResultId
$cmax :: ResultId -> ResultId -> ResultId
>= :: ResultId -> ResultId -> Bool
$c>= :: ResultId -> ResultId -> Bool
> :: ResultId -> ResultId -> Bool
$c> :: ResultId -> ResultId -> Bool
<= :: ResultId -> ResultId -> Bool
$c<= :: ResultId -> ResultId -> Bool
< :: ResultId -> ResultId -> Bool
$c< :: ResultId -> ResultId -> Bool
compare :: ResultId -> ResultId -> Ordering
$ccompare :: ResultId -> ResultId -> Ordering
$cp1Ord :: Eq ResultId
Ord, Int -> ResultId -> ShowS
[ResultId] -> ShowS
ResultId -> ResultDescription
(Int -> ResultId -> ShowS)
-> (ResultId -> ResultDescription)
-> ([ResultId] -> ShowS)
-> Show ResultId
forall a.
(Int -> a -> ShowS)
-> (a -> ResultDescription) -> ([a] -> ShowS) -> Show a
showList :: [ResultId] -> ShowS
$cshowList :: [ResultId] -> ShowS
show :: ResultId -> ResultDescription
$cshow :: ResultId -> ResultDescription
showsPrec :: Int -> ResultId -> ShowS
$cshowsPrec :: Int -> ResultId -> ShowS
Show)
russianResultLocale :: ResultLocale
russianResultLocale :: ResultDescription
russianResultLocale = ResultDescription
"ru"
englishResultLocale :: ResultLocale
englishResultLocale :: ResultDescription
englishResultLocale = ResultDescription
"en"
lookupResultLocalisation :: ResultLocale -> M.Map ResultLocale ResultDescription -> ResultDescription
lookupResultLocalisation :: ResultDescription
-> Map ResultDescription ResultDescription -> ResultDescription
lookupResultLocalisation ResultDescription
loc Map ResultDescription ResultDescription
m =
case ResultDescription
-> Map ResultDescription ResultDescription
-> Maybe ResultDescription
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup ResultDescription
loc Map ResultDescription ResultDescription
m of
Just ResultDescription
x -> ResultDescription
x
Maybe ResultDescription
Nothing ->
case ResultDescription
-> Map ResultDescription ResultDescription
-> Maybe ResultDescription
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup ResultDescription
russianResultLocale Map ResultDescription ResultDescription
m of
Just ResultDescription
x -> ResultDescription
x
Maybe ResultDescription
Nothing ->
case ResultDescription
-> Map ResultDescription ResultDescription
-> Maybe ResultDescription
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup ResultDescription
englishResultLocale Map ResultDescription ResultDescription
m of
Just ResultDescription
x -> ResultDescription
x
Maybe ResultDescription
Nothing -> ResultDescription
""
pathResultLocalisation :: (ResultId -> ResultDescription) -> [ResultId] -> ResultDescription
pathResultLocalisation :: (ResultId -> ResultDescription) -> [ResultId] -> ResultDescription
pathResultLocalisation ResultId -> ResultDescription
loc [ResultId]
is = [ResultId] -> [ShowS] -> ResultDescription
loop [ResultId]
is []
where loop :: [ResultId] -> [ShowS] -> ResultDescription
loop [] [ShowS]
acc = (ShowS -> ShowS)
-> ResultDescription -> [ShowS] -> ResultDescription
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr ShowS -> ShowS
forall a b. (a -> b) -> a -> b
($) [] ([ShowS] -> [ShowS]
forall a. [a] -> [a]
reverse [ShowS]
acc)
loop (ResultId
x : [ResultId]
xs) [] = [ResultId] -> [ShowS] -> ResultDescription
loop [ResultId]
xs [(ResultId -> ResultDescription
loc ResultId
x ResultDescription -> ShowS
forall a. [a] -> [a] -> [a]
++)]
loop ((VectorItemId ResultDescription
s) : [ResultId]
xs) [ShowS]
acc = [ResultId] -> [ShowS] -> ResultDescription
loop [ResultId]
xs ([ShowS] -> ResultDescription) -> [ShowS] -> ResultDescription
forall a b. (a -> b) -> a -> b
$ (ResultDescription
s ResultDescription -> ShowS
forall a. [a] -> [a] -> [a]
++) ShowS -> [ShowS] -> [ShowS]
forall a. a -> [a] -> [a]
: (ResultDescription
" " ResultDescription -> ShowS
forall a. [a] -> [a] -> [a]
++) ShowS -> [ShowS] -> [ShowS]
forall a. a -> [a] -> [a]
: [ShowS]
acc
loop (ResultId
x : [ResultId]
xs) [ShowS]
acc = [ResultId] -> [ShowS] -> ResultDescription
loop [ResultId]
xs ([ShowS] -> ResultDescription) -> [ShowS] -> ResultDescription
forall a b. (a -> b) -> a -> b
$ (ResultId -> ResultDescription
loc ResultId
x ResultDescription -> ShowS
forall a. [a] -> [a] -> [a]
++) ShowS -> [ShowS] -> [ShowS]
forall a. a -> [a] -> [a]
: (ResultDescription
" / " ResultDescription -> ShowS
forall a. [a] -> [a] -> [a]
++) ShowS -> [ShowS] -> [ShowS]
forall a. a -> [a] -> [a]
: [ShowS]
acc
localisePathResultDescription :: ResultLocalisation -> [ResultId] -> ResultDescription
localisePathResultDescription :: ResultLocalisation -> [ResultId] -> ResultDescription
localisePathResultDescription ResultLocalisation
loc [ResultId]
is = (ResultId -> ResultDescription) -> [ResultId] -> ResultDescription
pathResultLocalisation (ResultLocalisation -> ResultId -> ResultDescription
localiseResultDescription ResultLocalisation
loc) [ResultId]
is
localisePathResultTitle :: ResultLocalisation -> [ResultId] -> ResultDescription
localisePathResultTitle :: ResultLocalisation -> [ResultId] -> ResultDescription
localisePathResultTitle ResultLocalisation
loc [ResultId]
is = (ResultId -> ResultDescription) -> [ResultId] -> ResultDescription
pathResultLocalisation (ResultLocalisation -> ResultId -> ResultDescription
localiseResultTitle ResultLocalisation
loc) [ResultId]
is
resultNameToTitle :: ResultName -> ResultDescription
resultNameToTitle :: ShowS
resultNameToTitle =
[ResultDescription] -> ResultDescription
unwords ([ResultDescription] -> ResultDescription)
-> (ResultDescription -> [ResultDescription]) -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
[[ResultDescription]] -> [ResultDescription]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[ResultDescription]] -> [ResultDescription])
-> (ResultDescription -> [[ResultDescription]])
-> ResultDescription
-> [ResultDescription]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
([ResultDescription] -> [ResultDescription])
-> [[ResultDescription]] -> [[ResultDescription]]
forall a b. (a -> b) -> [a] -> [b]
map (ShowS -> [ResultDescription] -> [ResultDescription]
forall a b. (a -> b) -> [a] -> [b]
map (ShowS -> [ResultDescription] -> [ResultDescription])
-> ShowS -> [ResultDescription] -> [ResultDescription]
forall a b. (a -> b) -> a -> b
$ (Char -> Char) -> ShowS
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower) ([[ResultDescription]] -> [[ResultDescription]])
-> (ResultDescription -> [[ResultDescription]])
-> ResultDescription
-> [[ResultDescription]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
(ResultDescription -> [ResultDescription])
-> [ResultDescription] -> [[ResultDescription]]
forall a b. (a -> b) -> [a] -> [b]
map ((Char -> Char -> Bool) -> ResultDescription -> [ResultDescription]
forall a. (a -> a -> Bool) -> [a] -> [[a]]
groupBy (\Char
x Char
y -> Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ Char -> Bool
isUpper Char
y)) ([ResultDescription] -> [[ResultDescription]])
-> (ResultDescription -> [ResultDescription])
-> ResultDescription
-> [[ResultDescription]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
ResultDescription -> [ResultDescription]
words