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. 😏
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: array_pack() and array_pack(). These really don't
save you much.
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
BagReaderandBagWriterto 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
msgpackseems 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.
Metadata
Release files for the-collector 0.6.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| the_collector-0.6.1.tar.gz | 11.6 kB | Without provenance | Details for the_collector-0.6.1.tar.gz |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| the_collector-0.6.1-py3-none-any.whl | Python 3 | none | any | Details for the_collector-0.6.1-py3-none-any.whl |
| the_collector-0.6.1-py2-none-any.whl | Python 2 | none | any | Details for the_collector-0.6.1-py2-none-any.whl |
Total release size: 34.8 kB
Release files / the_collector-0.6.1.tar.gz
| Download URL | the_collector-0.6.1.tar.gz |
|---|---|
| Size | 11.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
231175ab46f4d6ef5521023d09eb81f3a201d6df8a6dffebdadd621352a6dceb
|
|
BLAKE2b-256 checksum How to use checksums |
64c79711113a7e247cc65c4318ba3ec85bd1e974e79581c81421b12686a63129
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / the_collector-0.6.1-py3-none-any.whl
| Download URL | the_collector-0.6.1-py3-none-any.whl |
|---|---|
| Size | 11.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
08f11ccdd860eb697d03ff07aecb5587436d4d3d873e59335148207fbd3b2ea7
|
|
BLAKE2b-256 checksum How to use checksums |
d28a3879830fc6a7d13edd1ba04e07a0bd7a0da0637b985fd3fae17ba09ef44a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / the_collector-0.6.1-py2-none-any.whl
| Download URL | the_collector-0.6.1-py2-none-any.whl |
|---|---|
| Size | 11.6 kB |
| Tags | Python 2 |
|
SHA-256 checksum How to use checksums |
bccb7e457b4e109c8fe758cad784f1f6a7af0b38ce2f9381d6f260aa89e39195
|
|
BLAKE2b-256 checksum How to use checksums |
9231f61c4c66ae7bdb36880a7391f72982f9f847d72f1fcddc9e45dc1d1a3147
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for the-collector 0.6.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.