module Simulation.Aivika.Experiment.SamplingStatsSource
(SamplingStatsSource,
providerToDoubleStatsSource,
providerToIntStatsSource,
SamplingStatsData,
samplingStatsSourceData,
addDataToSamplingStats) where
import Simulation.Aivika.Event
import Simulation.Aivika.Statistics
import Simulation.Aivika.Experiment.Types
data SamplingStatsSource a = SingleValueSource (Event a)
| MultipleValueSource (Event (SamplingStats a))
data SamplingStatsData a = SingleValueData !a
| MultipleValueData (SamplingStats a)
providerToDoubleStatsSource :: SeriesProvider -> Maybe (SamplingStatsSource Double)
providerToDoubleStatsSource provider =
case providerToDouble provider of
Just x -> Just $ SingleValueSource x
Nothing ->
case providerToDoubleStats provider of
Just x -> Just $ MultipleValueSource x
Nothing -> Nothing
providerToIntStatsSource :: SeriesProvider -> Maybe (SamplingStatsSource Int)
providerToIntStatsSource provider =
case providerToInt provider of
Just x -> Just $ SingleValueSource x
Nothing ->
case providerToIntStats provider of
Just x -> Just $ MultipleValueSource x
Nothing -> Nothing
samplingStatsSourceData :: SamplingStatsSource a -> Event (SamplingStatsData a)
samplingStatsSourceData source =
case source of
SingleValueSource x -> x >>= return . SingleValueData
MultipleValueSource x -> x >>= return . MultipleValueData
addDataToSamplingStats :: SamplingData a
=> SamplingStatsData a
-> SamplingStats a
-> SamplingStats a
addDataToSamplingStats d stats =
case d of
SingleValueData x -> addSamplingStats x stats
MultipleValueData x -> combineSamplingStats x stats