Package: event-data-logging
event_data_loggingSave events to json or csv files. This package comes in 4 flavors:CSVWriterStampedCSVWriterJSONWriterStampedJSONWriterAll of these will check if the given filename already exists and add a numerical suffix if it does to give a unused new filename. Additionally, if a filename that includes directories is used, the directories will be created if they don't exist, if possible.The StampedWriters will add a leading entry with the currentepoch timestampto each event or line saved. The default format is in seconds with fraction of a second as decimal numbers. Alternatively you can save the timestamps as nanoseconds instead.Readme content:InstallUsageDevelopingros2 message handlingInstallInstall from PYPIpip install event_data_loggingAlternatively, install from githubpip install git+https://git@github.com/maimonlab/event_data_logging.gitUsageJSON example without timestampsfromevent_data_logging.json_writerimportJSONWritertest_events=[{"bar_color":[1,2,3]},{"bar_width_degrees":10},{"example_float":0.1},]filename="data/json_data.json"writer=JSONWriter(filename)foreventintest_events:writer.save_event(event)This would create the filedata/json_data.jsonwith content:[
{"bar_color": [1, 2, 3]},
{"bar_width_degrees": 10},
{"example_float": 0.1}
]JSON example with timestampfromevent_data_logging.json_writerimportStampedJSONWritertest_events=[{"bar_color":[1,2,3]},{"bar_width_degrees":10},{"example_float":0.1},]filename="data/stamped_json_data.json"writer=StampedJSONWriter(filename)foreventintest_events:writer.save_event(event)This would create the filedata/stamped_json_data.jsonwith content:[
{"timestamp": 1661201947.0682852, "bar_color": [1, 2, 3]},
{"timestamp": 1661201947.0683577, "bar_width_degrees": 10},
{"timestamp": 1661201947.0684075, "example_float": 0.1}
]CSV example with nanosecond timestampfromevent_data_logging.csv_writerimportStampedCSVWriter,TimestampModesfilename="data/csv_data.csv"xyz_header=["x","y","z"]csv_writer=StampedCSVWriter(filename,header=xyz_header,timestamp_mode=TimestampModes.NANOSECONDS)foriinrange(3):line=[str(10*i+1),str(10*i+2),str(10*i+3),]csv_writer.save_line(line)This will give the filedata/csv_data.csvwith the following content:timestamp,x,y,z
1661110000123456789,1,2,3
1661110001123456789,11,12,13
1661110002123456789,21,22,23DevelopingTo install the testing dependencies, install withpip install -e .[test]You can run the tests with pytest, and check the coverage. To do so, use the following commands:coverage run -m pytestThe coverage report prints to the terminal with:coverage reportThis report shows how much of all the code is actually run during the test.Uploading to pypiBuild the distributionpython3 -m buildUpload the distribution to pypipython3 -m twine upload --repository pypi dist/* --verboseros2_message_handling using outside dependenciesIn our lab, this package is mainly used to save ros2 data, and thus turning ros2 messages to dictionaries is very common. The ros2_message_handling module therefore requires some ros2 packages to be installed, and is outside of the scope of most uses.Thetest_ros2_message_handling.pywill thus fail in environments without ROS2.
_We will likely remove this module before the stable release. the ros2_message handling should be integrated in it's own ros packages