A library to store robot data in a msgpack format
Project description
The Collector
This is still under heavy development
The idea behind this a container that can store data and time tag the data when it is captured. The main structure is a dict which has keys for each data series stored.
This was written for a class I taught on robotics. It is meant to be simple and teach the students some things. There are probably better solutions out there, but I like this. :smirk:
Setup
Install
The suggested way to install this is via the pip
command as follows:
pip install the_collector
pip install the_collector[numpy]
If you install numpy
, then you get access to working with numpy arrays
using the functions:
Development
To submit git pulls, clone the repository and set it up as follows:
git clone https://github.com/MomsFriendlyRobotCompany/the-collector
cd the-collector
pip install -e .
Usage
Bag stores data in memory until the buffer size limit is reached then it dumps the data to a file.
from __future__ import print_function
from the_collector import BagReader, BagWriter
d = {'a': 1, 'b': 2}
# bag = BagWriter('bob.bag', buffer_size=1000) # you can change buffer size
bag = BagWriter('bob.bag') # .bag is automagically appended if not present
# grab some data
for _ in range(100):
bag.push('temperature', d) # the key name can be anything
bag.push('something else', d) # when you use BagReader, these become dict keys
# flushes any remaining data to the file and closes the file
bag.close()
# now read it back
bag = BagReader()
data = bag.read('bob.bag')
If you want to record a time stamp for each data collect (using python's
time.time()
), just do a bag.push_stamp()
. However, when you read back
the data, it will now be (data, time_stamp).
Custom Pack/Unpack
You can pass functions to pack
or unpack
custom data structures to
BagReader(pack=...)
and BagWriter(unpack=...)
as expained in the msgpack
docs here
def ext_unpack(msg):
# do some cool stuff here
# see msgpack docs for examples
# calls the function ext_unpack when something custom is encountered
bag = BagReader(unpack=ext_unpack)
def ext_pack(msg):
# do some cool stuff here
# see msgpack docs for examples
# calls the function ext_unpack when something custom is encountered
bag = BagWriter('bob.bag', pack=ext_pack)
Todo
- Maybe allow
BagReader
andBagWriter
to accept a file-like object (io.BytesIO) but I am not sure of the value for this. It would be nice for testing, so I don't have to always useos.remove()
to clean up bag files. What is a use case?
History
- Originally started with storing the file as a json file
- Added compression to reduce the size, this proved to be superior to python's pickle library
- Looked at Google's protobufs, they seemed complex and the message types didn't really have what I wanted
msgpack
seems to be fast and compact, tried using compression (gzip library) on msgpack data, but it actually made it worse. Decided to go with this and it saves me a compression step
Change Log
Date | Version | Notes |
---|---|---|
2018-07-14 | 0.6.0 | changed interface to support buffered writing to disk |
2018-07-09 | 0.5.0 | moved away from json and now using msgpack |
2017-11-23 | 0.4.0 | fixes, documentation, unit tests |
2017-10-04 | 0.0.1 | init |
The MIT License (MIT)
Copyright (c) 2017 Kevin J. Walchko
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file the_collector-0.6.0.tar.gz
.
File metadata
- Download URL: the_collector-0.6.0.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c29a6a33c19431a656f28ba96cbf30266b9facabc90fb864d5afac969ab1c874 |
|
MD5 | 56ce09607a0cc0f39ddf5fc80ccaaaa1 |
|
BLAKE2b-256 | bae1e5cfcba0ecfb3cdb2bd950d8d505b061de66b1dd1bcfb59d055eebf9bf67 |
File details
Details for the file the_collector-0.6.0-py3-none-any.whl
.
File metadata
- Download URL: the_collector-0.6.0-py3-none-any.whl
- Upload date:
- Size: 11.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3847688c7d727ea0568439db168c7e691d490441e9c3ea18160b2eba08ca6323 |
|
MD5 | 5dfa083e975298519abe19bd054522e3 |
|
BLAKE2b-256 | 6ea66cd8130fb6d892891e7ec0440e259aacb846ae8412a38034a5a6f48d58af |
File details
Details for the file the_collector-0.6.0-py2-none-any.whl
.
File metadata
- Download URL: the_collector-0.6.0-py2-none-any.whl
- Upload date:
- Size: 11.6 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c44e0dfa9553fdd1d70fb836adca9caa8d3e3c0fd7921eaf0487dc795311cabf |
|
MD5 | 1b82b0c809e0ad640dddbf0ab84e42f7 |
|
BLAKE2b-256 | 53b68ad69db377c35e4d7ab47dcf36a6ce5c0d559253b21df96b3e0a5e721c63 |