Class EventBasedTimestampWeightedTally
- java.lang.Object
-
- org.djutils.stats.summarizers.WeightedTally
-
- org.djutils.stats.summarizers.TimestampWeightedTally
-
- org.djutils.stats.summarizers.event.EventBasedTimestampWeightedTally
-
- All Implemented Interfaces:
Serializable
,Remote
,EventListener
,EventListener
,EventProducer
,Statistic
,TallyStatistic
public class EventBasedTimestampWeightedTally extends TimestampWeightedTally implements EventProducer, EventListener
The TimestampWeightedTally class defines a time-weighted tally based on timestamped data. The difference with a normal time-weighed tally is that the weight of a value is only known at the occurrence of the next timestamp. Furthermore, a last timestamp needs to be specified to determine the weight of the last value. This EventBased version of the tally can be notified with timestamps and values using the EventListenerInterface. It also produces events when values are tallied and when the tally is initialized. Timestamps can be Number based or Calendar based.Copyright (c) 2020-2023 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://simulation.tudelft.nl. The DSOL project is distributed under a three-clause BSD-style license, which can be found at https://simulation.tudelft.nl/dsol/3.0/license.html.
- Author:
- Alexander Verbraeck
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class org.djutils.stats.summarizers.WeightedTally
semaphore
-
Fields inherited from interface org.djutils.event.EventProducer
FIRST_POSITION, LAST_POSITION
-
-
Constructor Summary
Constructors Constructor Description EventBasedTimestampWeightedTally(String description)
constructs a new EventBasedTimestampWeightedTally with a description.EventBasedTimestampWeightedTally(String description, EventProducer eventProducer)
Construct a new EventBasedTimestampWeightedTally with a description.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected <T extends Serializable & Comparable<T>>
voidfireEvents(Serializable timestamp)
Method that can be overridden to fire own events or additional events when registering an observation.EventListenerMap
getEventListenerMap()
void
initialize()
Initialize the statistic.void
notify(Event event)
double
register(double timestamp, double value)
Explicit;y override the double value method signature of WeightedTally to call the right method.
Process one observed double value.double
register(Number timestamp, double value)
Process one observed Number-based value.double
register(Calendar timestamp, double value)
Process one observed Calender-based value.String
toString()
-
Methods inherited from class org.djutils.stats.summarizers.TimestampWeightedTally
endObservations, endObservations, getLastValue, isActive, registerValue, reportFooter, reportHeader, reportLine
-
Methods inherited from class org.djutils.stats.summarizers.WeightedTally
getDescription, getMax, getMin, getN, getWeightedPopulationMean, getWeightedPopulationStDev, getWeightedPopulationVariance, getWeightedSampleMean, getWeightedSampleStDev, getWeightedSampleVariance, getWeightedSum
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.djutils.event.EventProducer
addListener, addListener, addListener, addListener, fireEvent, fireEvent, fireEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, getEventTypesWithListeners, getListenerReferences, hasListeners, numberOfListeners, removeAllListeners, removeAllListeners, removeListener
-
Methods inherited from interface org.djutils.stats.summarizers.Statistic
formatFixed
-
-
-
-
Constructor Detail
-
EventBasedTimestampWeightedTally
public EventBasedTimestampWeightedTally(String description)
constructs a new EventBasedTimestampWeightedTally with a description.- Parameters:
description
- String; the description of this EventBasedTimestampWeightedTally
-
EventBasedTimestampWeightedTally
public EventBasedTimestampWeightedTally(String description, EventProducer eventProducer)
Construct a new EventBasedTimestampWeightedTally with a description.- Parameters:
description
- String; the description of this WeightedTallyeventProducer
- EventProducer; the EventProducer to embed and use in this statistic
-
-
Method Detail
-
getEventListenerMap
public EventListenerMap getEventListenerMap() throws RemoteException
- Specified by:
getEventListenerMap
in interfaceEventProducer
- Throws:
RemoteException
-
initialize
public void initialize()
Initialize the statistic.- Specified by:
initialize
in interfaceStatistic
- Overrides:
initialize
in classTimestampWeightedTally
-
notify
public void notify(Event event)
- Specified by:
notify
in interfaceEventListener
-
register
public double register(Calendar timestamp, double value)
Process one observed Calender-based value. The time used will be the Calendar's time in milliseconds. Silently ignore when a value is registered, but tally is not active, i.e. when endObservations() has been called.- Overrides:
register
in classTimestampWeightedTally
- Parameters:
timestamp
- Calendar; the Calendar object representing the timestampvalue
- double; the value to process- Returns:
- double; the value
- Throws:
NullPointerException
- when timestamp is nullIllegalArgumentException
- when value is NaNIllegalArgumentException
- when given timestamp is before last timestamp
-
register
public double register(Number timestamp, double value)
Process one observed Number-based value. Silently ignore when a value is registered, but tally is not active, i.e. when endObservations() has been called.- Overrides:
register
in classTimestampWeightedTally
- Parameters:
timestamp
- Number; the object representing the timestampvalue
- double; the value to process- Returns:
- double; the value
- Throws:
NullPointerException
- when timestamp is nullIllegalArgumentException
- when value is NaN or timestamp is NaNIllegalArgumentException
- when given timestamp is before last timestamp
-
register
public double register(double timestamp, double value)
Explicit;y override the double value method signature of WeightedTally to call the right method.
Process one observed double value. Silently ignore when a value is registered, but tally is not active, i.e. when endObservations() has been called.- Overrides:
register
in classTimestampWeightedTally
- Parameters:
timestamp
- Number; the object representing the timestampvalue
- double; the value to process- Returns:
- double; the value
- Throws:
NullPointerException
- when timestamp is nullIllegalArgumentException
- when value is NaN or timestamp is NaNIllegalArgumentException
- when given timestamp is before last timestamp
-
fireEvents
protected <T extends Serializable & Comparable<T>> void fireEvents(Serializable timestamp) throws RemoteException
Method that can be overridden to fire own events or additional events when registering an observation.- Type Parameters:
T
- a type for the timestamp that is Serializable and Comparable- Parameters:
timestamp
- T; the timestamp to use in the TimedEvents- Throws:
RemoteException
- on network error
-
toString
public String toString()
- Overrides:
toString
in classTimestampWeightedTally
-
-