Class: YPetri::Simulation::Timed::Recorder

Inherits:
Recorder
  • Object
show all
Defined in:
lib/y_petri/simulation/timed/recorder.rb

Overview

Timed aspect of the recorder.

Constant Summary collapse

TIME_DECIMAL_PLACES =
5

Constants inherited from Recorder

Recorder::SAMPLING_DECIMAL_PLACES

Instance Attribute Summary collapse

Attributes inherited from Recorder

#features

Instance Method Summary collapse

Methods inherited from Recorder

#recording

Constructor Details

#initialize(sampling: default_sampling, next_time: time, **nn) ⇒ Recorder

Apart from the vanilla version arguments, timed recorder takes :sampling argument.



16
17
18
19
20
# File 'lib/y_petri/simulation/timed/recorder.rb', line 16

def initialize sampling: default_sampling, next_time: time, **nn
  super
  @sampling = sampling
  @next_time = next_time
end

Instance Attribute Details

#next_timeObject (readonly)

Returns the value of attribute next_time.



7
8
9
# File 'lib/y_petri/simulation/timed/recorder.rb', line 7

def next_time
  @next_time
end

#samplingObject

Returns the value of attribute sampling.



8
9
10
# File 'lib/y_petri/simulation/timed/recorder.rb', line 8

def sampling
  @sampling
end

Instance Method Details

#alertObject

Hook to be called by simulators whenever the state changes (every time that simulation time is incremented).



41
42
43
44
45
46
47
48
# File 'lib/y_petri/simulation/timed/recorder.rb', line 41

def alert
  t = time.round( 9 )
  t2 = next_time.round( 9 )
  if t >= t2 then # it's time to sample
    sample!
    @next_time += sampling
  end
end

#new_recordingObject

Construct a new recording based on features.



24
25
26
# File 'lib/y_petri/simulation/timed/recorder.rb', line 24

def new_recording
  features.new_dataset type: :timed
end

#reset!(sampling: default_sampling, next_time: time, **nn) ⇒ Object

Like YPetri::Simulation::Recorder#reset, but allowing for an additional named argument :next_time that sets the next sampling time, and +:sampling:, resetting the sampling period.



32
33
34
35
36
# File 'lib/y_petri/simulation/timed/recorder.rb', line 32

def reset! sampling: default_sampling, next_time: time, **nn
  super
  @sampling = sampling
  @next_time = next_time
end