module Simulation.Aivika.Statistics.Accumulator
(
TimingStatsAccumulator,
newTimingStatsAccumulator,
timingStatsAccumulated) where
import Simulation.Aivika.Simulation
import Simulation.Aivika.Dynamics
import Simulation.Aivika.Event
import Simulation.Aivika.Ref
import Simulation.Aivika.Statistics
import Simulation.Aivika.Signal
newtype TimingStatsAccumulator a =
TimingStatsAccumulator { forall a. TimingStatsAccumulator a -> Ref (TimingStats a)
timingStatsAccumulatedRef :: Ref (TimingStats a) }
timingStatsAccumulated :: TimingStatsAccumulator a -> Event (TimingStats a)
timingStatsAccumulated :: forall a. TimingStatsAccumulator a -> Event (TimingStats a)
timingStatsAccumulated = forall a. Ref a -> Event a
readRef forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. TimingStatsAccumulator a -> Ref (TimingStats a)
timingStatsAccumulatedRef
newTimingStatsAccumulator :: TimingData a => Signalable a -> Event (TimingStatsAccumulator a)
newTimingStatsAccumulator :: forall a.
TimingData a =>
Signalable a -> Event (TimingStatsAccumulator a)
newTimingStatsAccumulator Signalable a
x =
do Double
t0 <- forall (m :: * -> *) a. DynamicsLift m => Dynamics a -> m a
liftDynamics Dynamics Double
time
a
a0 <- forall a. Signalable a -> Event a
readSignalable Signalable a
x
Ref (TimingStats a)
r <- forall (m :: * -> *) a. SimulationLift m => Simulation a -> m a
liftSimulation forall a b. (a -> b) -> a -> b
$ forall a. a -> Simulation (Ref a)
newRef (forall a. TimingData a => Double -> a -> TimingStats a
returnTimingStats Double
t0 a
a0)
forall a. Signal a -> (a -> Event ()) -> Event ()
handleSignal_ (forall a. Signalable a -> Signal a
signalableChanged Signalable a
x) forall a b. (a -> b) -> a -> b
$ \a
a ->
do Double
t <- forall (m :: * -> *) a. DynamicsLift m => Dynamics a -> m a
liftDynamics Dynamics Double
time
forall a. Ref a -> (a -> a) -> Event ()
modifyRef Ref (TimingStats a)
r forall a b. (a -> b) -> a -> b
$ forall a.
TimingData a =>
Double -> a -> TimingStats a -> TimingStats a
addTimingStats Double
t a
a
forall (m :: * -> *) a. Monad m => a -> m a
return TimingStatsAccumulator { timingStatsAccumulatedRef :: Ref (TimingStats a)
timingStatsAccumulatedRef = Ref (TimingStats a)
r }