Power Network: Exporting Data
Registering Messages
A message writer component can be added to the simulation which will record the data of messages over time from the simulation. The message writer can register multiple messages and each message will be saved into a CSV file every specified amount of seconds. This can be done by adding the BP_MessageWriter
scene component to the Begin Play event. By default, the /Saved/
directory is used for the files.
- Write Interval: The time in simulation seconds between each save point. Each time the simulation reaches this interval, all messages that are registered will be saved into their respective files.
- Parent: The message writer is a simulation object that can be attached to a particular spacecraft or entity. This enables the object to individually track unique object messages.
Once the message writer has been added to the level, it can add any number of unique messages to be registered. The data from the message will be stored until it is ready to be exported as a CSV file.
Exporting Messages
When the simulation has ended, or when the user is required to fetch the data back from the message writer, the data must be exported to a CSV file or a directory. This can be done using the export functions on the message writer. In this example, the messages should output their data when the user ends the level. This will execute the Event End Play
. Similar to the tick and begin events, this can be added to the level blueprint and code can be executed.
When this event is called, the messages should be exported to the appropriate directory. This is done by calling the Export to CSV (All Messages)
function. This method will save all of the individual messages into their own CSV files, named by the message name into a directory. The directory is the absolute path to the saved folder. As such, one example is to use Project Saved Dir
to fetch the saved directory to save the data to. The delimiter variable defines the separator.
Warning
For message writers, it is common to use a different delimiter than the conventional comma. This is because JSON data may be present within the messages (depending on the type) and may make the columns invalid if the data includes commas. A pipe ( | ) character is more appropriate in this case.
Viewing Data
Once the simulation is completed, the data will be outputted to a CSV file within the directory provided for each message. This tutorial is now complete and the data from the power network can be extracted and stored in a CSV file for analysis.
Note
If the simulation runs again, the file that was previously used will remain in the folder. This will create another file with a unique ID. For naming files with fixed names (which will override existing ones), use the Export Message
function for each message that is being recorded.