Package org.opentrafficsim.kpi.sampling
Class SamplerData<G extends GtuDataInterface>
- java.lang.Object
-
- org.opentrafficsim.kpi.sampling.AbstractTable
-
- org.opentrafficsim.kpi.sampling.SamplerData<G>
-
- Type Parameters:
G
- gtu data type
- All Implemented Interfaces:
Iterable<Record>
,Identifiable
,Table
public class SamplerData<G extends GtuDataInterface> extends AbstractTable
SamplerData is a storage for trajectory data. Adding trajectory groups can only be done by subclasses. This is however not a guaranteed read-only class. Any type can obtain the lane directions and with those the coupled trajectory groups. Trajectories can be added to these trajectory groups. Data can also be added to the trajectories themselves.Copyright (c) 2020-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.- Author:
- Alexander Verbraeck, Peter Knoppers, Wouter Schakel
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SamplerData.CompressionMethod
Defines the compression method for stored data.
-
Constructor Summary
Constructors Constructor Description SamplerData(Collection<Column<?>> columns)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
contains(KpiLaneDirection kpiLaneDirection)
Returns whether there is data for the give lane direction.Set<KpiLaneDirection>
getLaneDirections()
Returns the set of lane directions.TrajectoryGroup<G>
getTrajectoryGroup(KpiLaneDirection kpiLaneDirection)
Returns the trajectory group of given lane direction.boolean
isEmpty()
Returns whether the table is empty.Iterator<Record>
iterator()
static SamplerData<?>
loadFromFile(String file)
Loads sampler data from a file.static SamplerData<?>
loadFromFile(String file, Set<ExtendedDataType<?,?,?,?>> extendedDataTypes, Set<FilterDataType<?>> metaDataTypes)
Loads sampler data from a file.protected void
putTrajectoryGroup(KpiLaneDirection kpiLaneDirection, TrajectoryGroup<G> trajectoryGroup)
Stores a trajectory group with the lane direction.void
writeToFile(String file)
Write the contents of the sampler in to a file.void
writeToFile(String file, String format, SamplerData.CompressionMethod compression)
Write the contents of the sampler in to a file.-
Methods inherited from class org.opentrafficsim.kpi.sampling.AbstractTable
getColumns, getDescription, getId
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Methods inherited from interface org.opentrafficsim.kpi.sampling.Table
getNumberOfColumns
-
-
-
-
Constructor Detail
-
SamplerData
public SamplerData(Collection<Column<?>> columns)
Constructor.- Parameters:
columns
- Collection<Column<?>>; columns
-
-
Method Detail
-
putTrajectoryGroup
protected final void putTrajectoryGroup(KpiLaneDirection kpiLaneDirection, TrajectoryGroup<G> trajectoryGroup)
Stores a trajectory group with the lane direction.- Parameters:
kpiLaneDirection
- KpiLaneDirection; lane directiontrajectoryGroup
- trajectory group for given lane direction
-
getLaneDirections
public final Set<KpiLaneDirection> getLaneDirections()
Returns the set of lane directions.- Returns:
- Set<KpiLaneDirection>; lane directions
-
contains
public final boolean contains(KpiLaneDirection kpiLaneDirection)
Returns whether there is data for the give lane direction.- Parameters:
kpiLaneDirection
- KpiLaneDirection; lane direction- Returns:
- whether there is data for the give lane direction
-
getTrajectoryGroup
public final TrajectoryGroup<G> getTrajectoryGroup(KpiLaneDirection kpiLaneDirection)
Returns the trajectory group of given lane direction.- Parameters:
kpiLaneDirection
- KpiLaneDirection; lane direction- Returns:
- trajectory group of given lane direction,
null
if none
-
writeToFile
public final void writeToFile(String file)
Write the contents of the sampler in to a file. By default this is zipped and numeric data is formated %.3f.- Parameters:
file
- String; file
-
writeToFile
public final void writeToFile(String file, String format, SamplerData.CompressionMethod compression)
Write the contents of the sampler in to a file.- Parameters:
file
- String; fileformat
- String; number format, as used inString.format()
compression
- CompressionMethod; how to compress the data
-
loadFromFile
public static SamplerData<?> loadFromFile(String file)
Loads sampler data from a file. There are a few limitations with respect to live sampled data:- The number of decimals in numeric data is equal to the stored format.
- All extended data types are stored as
String
. - Meta data types are not recognized, and hence stored as extended data types. Values are always stored as
String
.
- Parameters:
file
- String; file- Returns:
- Sampler data from file
-
loadFromFile
public static SamplerData<?> loadFromFile(String file, Set<ExtendedDataType<?,?,?,?>> extendedDataTypes, Set<FilterDataType<?>> metaDataTypes)
Loads sampler data from a file. There are a few limitations with respect to live sampled data:- The number of decimals in numeric data is equal to the stored format.
- All extended data types are stored as
String
, unless recognized by id as provided. - Meta data types are not recognized, and hence stored as extended data types, unless recognized by id as provided.
Values are always stored as
String
.
- Parameters:
file
- String; fileextendedDataTypes
- Set<ExtendedDataType<?, ?, ?, ?>>; extended data typesmetaDataTypes
- Set<MetaDataType<?>>; meta data types- Returns:
- Sampler data from file
-
isEmpty
public boolean isEmpty()
Returns whether the table is empty.- Returns:
- whether the table is empty
-
-