Class DataStorageMessageWriter
- Namespace
- NominalSystems.Classes
- Assembly
- NominalSystems.Classes.dll
[Nominal] The message logger model is able to log registered messages to the partitioned data storage system. These messages can be retrieved at a later time or can be exported as a CSV file.
[UniverseParent(typeof(PartitionedDataStorage))]
public class DataStorageMessageWriter : UniverseBehaviour
- Inheritance
-
DataStorageMessageWriter
Constructors
DataStorageMessageWriter()
Default constructor
protected DataStorageMessageWriter()
Fields
In_EpochMsg
An optional epoch message that can be used to store the epoch data within the data.
public EpochMessage? In_EpochMsg
Field Value
Key
The key to write the data to within the model. By default, it is the basic key that is used to store the data within the system.
public string Key
Field Value
Messages
A cache for the messages that need to be saved. Any messages that will need to be saved will exist here and if the flag is true, they will be written on the update loop.
[Hidden]
public Dictionary<Message, bool> Messages
Field Value
NextWriteTime
The next write time to copy the data into the storage system. This will be updated at each update frame and will be used to determine when the data should be copied.
[Unit(UnitType.SECOND)]
[Metadata(IsAdvanced = true)]
[ReadOnly]
public double NextWriteTime
Field Value
WriteInterval
The interval to write and copy the data into the partitioned storage system between writes.
[Unit(UnitType.SECOND)]
public double WriteInterval
Field Value
Properties
NumSaved
The number of saved message pointers that have been stored in the system.
[Unit(UnitType.NONE)]
[ReadOnly]
public int NumSaved { get; }
Property Value
Methods
DeleteAll()
Deletes all data and messages from being tracked by the system. This will not delete the messages, but rather remove the connections with the messages from the cache and delete all memory associated with those messages in the data storage unit.
public void DeleteAll()
DeleteMessage(Message)
Deletes the message from the cache and will ensure that all data that was tracked for that message is deleted.
public bool DeleteMessage(Message msg)
Parameters
msg
MessageThe message to delete
Returns
- bool
A successful deletion flag
DeregisterAll()
Deregisters all the messages from the message logger model. This will not remove any data that has been saved, but will stop the messages from being tracked.
public void DeregisterAll()
DeregisterMessage(Message)
Deregisters the message from the message logger model, which will stop it from being tracked each frame. However, the data will not be deleted if the message is deregistered.
public void DeregisterMessage(Message msg)
Parameters
msg
MessageThe message to deregister
Export(string, bool, bool)
Exports all the data that has been saved to the data storage system. This will save the data to a CSV file in the directory that is passed in. The data can also be formatted to a DateTime format and the data can be deleted after it has been exported.
public void Export(string directory, bool formatTime = false, bool delete = false)
Parameters
directory
stringThe directory to save the data to
formatTime
boolA flag whether to use a datetime format
delete
boolA flag whether to delete the data after being written
OnCreate()
Called when the object is created from the controller and has been attached to the parent object. By this point, it has been registered to the simulation and will run after the constructor.
protected override void OnCreate()
OnLoad(double)
Called after all of the data has been loaded from a save state on this object. This enables any post-load operations to be performed and extra data to be loaded from the metadata.
protected override void OnLoad(double time)
Parameters
time
double[s] The current clock time of the simulation
OnSave()
Called before the object is saved into the save state. This ensures that any additional metadata can be saved on the object before it is automatically serialized.
protected override void OnSave()
OnUpdate(double, double)
Called when the object should update from the simulation tick. This will take in a time and a step, where the time is the time of the clock before updating the object.
protected override void OnUpdate(double time, double step)
Parameters
time
double[s] Current time of the simulation before the update
step
double[s] The time-step to update during this tick
PopData(bool)
Pops the oldest data from the data storage that is tracking the data and returns the JToken data for the object that was being saved. This will go through all the messages stored and will return the oldest data that was saved chronologically on the message track. If adding the include name parameter, when the data is returned, the 'm_Name' field will be added to the JSON object with the name of the message type as well as the 'm_ID' field with the ID of the message.
public JToken? PopData(bool includeName = false)
Parameters
includeName
boolA flag whether to include the name of the message in the JSON
Returns
- JToken
The JSON object timestamped with the data.
ReadClosest(Message, double)
Reads the message data that is associated with the closest value to some time that is passed in. This will look into the messages that are tracked and will find the closest time to the time that is passed in. This will then update the data in the message.
public bool ReadClosest(Message msg, double time)
Parameters
msg
MessageThe message to write the data into
time
double[s] The time to fetch the closest value from
Returns
- bool
A successful write
ReadLatest(Message)
Reads the latest value of the message from the data storage system. This will write the data into the message reference that is passed in.
public bool ReadLatest(Message msg)
Parameters
msg
MessageThe message reference to write the data in
Returns
- bool
A successful write to the message
RegisterMessage(Message)
Registers a particular message to the message logger model. This will enable the message to be copied into the data storage system at each update frame based on the write frequency.
public void RegisterMessage(Message msg)
Parameters
msg
MessageThe message reference to copy and save