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 { localiseResultDescription :: ResultId -> ResultDescription,
localiseResultTitle :: ResultId -> ResultDescription
}
data UserDefinedResult =
UserDefinedResult { userDefinedResultName :: ResultName,
userDefinedResultDescription :: ResultDescription,
userDefinedResultTitle :: ResultDescription
} deriving (Eq, Ord, Show)
data LocalisedResult =
LocalisedResult { localisedResultDescriptions :: M.Map ResultLocale ResultDescription,
localisedResultTitles :: M.Map ResultLocale ResultDescription
} deriving (Eq, Ord, 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
| DequeueExtractCountId
| QueueLoadFactorId
| EnqueueRateId
| EnqueueStoreRateId
| DequeueRateId
| DequeueExtractRateId
| 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 (Eq, Ord, Show)
russianResultLocale :: ResultLocale
russianResultLocale = "ru"
englishResultLocale :: ResultLocale
englishResultLocale = "en"
lookupResultLocalisation :: ResultLocale -> M.Map ResultLocale ResultDescription -> ResultDescription
lookupResultLocalisation loc m =
case M.lookup loc m of
Just x -> x
Nothing ->
case M.lookup russianResultLocale m of
Just x -> x
Nothing ->
case M.lookup englishResultLocale m of
Just x -> x
Nothing -> ""
pathResultLocalisation :: (ResultId -> ResultDescription) -> [ResultId] -> ResultDescription
pathResultLocalisation loc is = loop is []
where loop [] acc = foldr ($) [] (reverse acc)
loop (x : xs) [] = loop xs [(loc x ++)]
loop ((VectorItemId s) : xs) acc = loop xs $ (s ++) : (" " ++) : acc
loop (x : xs) acc = loop xs $ (loc x ++) : (" / " ++) : acc
localisePathResultDescription :: ResultLocalisation -> [ResultId] -> ResultDescription
localisePathResultDescription loc is = pathResultLocalisation (localiseResultDescription loc) is
localisePathResultTitle :: ResultLocalisation -> [ResultId] -> ResultDescription
localisePathResultTitle loc is = pathResultLocalisation (localiseResultTitle loc) is
resultNameToTitle :: ResultName -> ResultDescription
resultNameToTitle =
unwords .
concat .
map (map $ map toLower) .
map (groupBy (\x y -> not $ isUpper y)) .
words