-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add dict interface #16
base: main
Are you sure you want to change the base?
Add dict interface #16
Conversation
I'm intrigued by outputting data in influxdb format- I'm mired in the low level writing of drivers and I don't get much exposure to how people actually use these, but I head about influxdb a lot and it seems like sensors across the board could benefit from this kind of endpoint. Whether it deserves to be in the driver or not is debatable. You never know how many other database systems or logging methods people might want supported, and it could end up being messy and complicated to endorse them all. Excuse the tests exploding, I need to fix those! |
Hokay I have fixed the tests, could I be a pain and ask you to rebase, please? |
3c51686
to
fb111c6
Compare
OK, just rebased. And yeah, whether or not the influxdb output belongs in the driver crossed my mind too and I had a couple of thoughts on it:
It's still not a perfect fit, but it did feel like something that would save people time and effort. |
Pull Request Test Coverage Report for Build 1816522940
💛 - Coveralls |
influxdb is the one solution I've actually heard of- short of pushing stuff right into a cloud service- so I'm inclined to believe its popularity extends past your neck of the woods. It's a good idea and it's great to have feedback and input from someone actually using this library. Couple of minor issues:
ef as_influxdb_line_proto(meas_name='pms5003', timestamp=True):
"""
Get the data in the form of influxDB line protocol
:return: str: the formatted data
"""
ret = ["{name},size={size},environment={environment} pm={val}u".format(name=meas_name, **x) for x in self.get_all_pm()]
ret.extend(["{},size={} count={}u".format(meas_name, s, c) for s, c in self.get_all_counts().items()])
if timestamp:
ret = ["{} {}".format(x, self.timestamp) for x in ret]
return '\n'.join(ret) |
Ahhh, tripped up on python versions. I think those changes should be good and just added them to the branch. For the timestamp, I switched it to float time in seconds, then convert to integer nanoseconds for influxdb later. I'll install the latest version on my raspberry pi when I get home tonight just to make sure I didn't make any dumb mistakes. However, it's such a small change that I expect everything should be good to go. |
OK, the code is on my raspberry pi and everything seems to be working. I just uploaded the script I use to the examples directory too. |
Okay just to be completely turbo annoying, I am migrating this library over to gpiod since the writing is on the wall for Python 2.x support will be dropped so we can go nuts with the fancy stuff. |
Hey folks, for my application I added some methods that provide aggregate output from the data class. The added methods are:
get_all_pm
- Returns all PM measurements as a list of dicts that contain the values and tags associated with measurementsget_all_counts
- Returns the particle counts as a dict where the key is particle sizeas_influxdb_line_proto
- Represents the data as a string in the format of influxdb line protocol.__iter__
- allows the class to be converted into a dict by callingdict(data)
. This may help resolve what is asked for in issue Seperate Readouts #15These are useful for my use case of calling this package and outputting the data into an influxdb database using telegraf. I was able to test everything on my raspberry pi and I am receiving data. I thought that I'd offer the changes here if you think they should be part of the package.