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
Filter listener sensor graphs by value and date range. #337
Conversation
This is great @paul121 !
👍 Makes sense to me.
This is the one thing that's stopping me from merging this as-is. When I first added the graphs, I went back and forth between loading the past "X days of data" vs the past "X data points", and decided to go with "X data points" for this exact reason. I want old sensors to show their "last" data in the graph, even if it was not recent.
I kinda like the latter idea there... try to determine when the last data point was and set the default start/end dates of the filters accordingly. This would work for old and current sensors, I think. One small thing to change: I like the "No data in this time range" message. But: we try to avoid using Bootstrap styles outside of An easy workaround would be: instead of building that message as markup that appears in the graphs fieldset, add it to the top of the page via Also minor minor nit: only capitalize the first word in "Sensor Graphs". |
@mstenta so I just realized it would be helpful to provide a list of sensor value names via the API (useful for viewing data in Field Kit) at What do ya think? That function & API path could be used to return additional info in the future, too. Perhaps a translated Made the small changes regarding boostrap styles & text capitalization. Makes sense on bootstrap - lets just remove the class for now. |
Oh maybe this should be |
Here is an example of data returned from the {
"Temperature": {
"first": "1596355200",
"last": "1597129200"
},
"Moisture": {
"first": "1596355200",
"last": "1597129200"
},
"Other value": {
"first": "1596355200",
"last": "1597129200"
}
} |
The query range() method does not support passing NULL. When NULL is passed for both parameters the query is built with LIMIT 0 OFFSET 0. When range() is called with no parameters, no LIMIT or OFFSET is set. https://www.drupal.org/project/drupal/issues/1943754 https://api.drupal.org/comment/49938#comment-49938
Hi @paul121 - looking over this again now with the hopes of merging before 7.x-1.5... Noticed a small issue: // Limit the results.
// Don't apply a range if both offset and limit are NULL.
if (!empty($offset) && !empty($limit)) {
$query->range($offset, $limit);
} The default value of the |
On second thought - rather than checking I will also update the call to this function where you used |
d016d67
to
84d3733
Compare
(I also rebased onto latest |
I'm looking through sensors in the Wolfe's Neck database. Noticing some strange "empty data" behavior - not working as expected I think... Here is a sensor that never had any data pushed to it: http://localhost/farm/sensor/high-roller-humidity I think we should omit the "Sensor graphs" fieldset entirely in that scenario. Here are two sensors that have SOME data, but the graphs are not showing and the empty text is: http://localhost/farm/sensor/dons-co-deployment-sensor-1 http://localhost/farm/sensor/dwbgatewaya Not sure why those aren't showing graphs. |
I like it! Having a place for high-level meta data for each sensor makes a lot of sense.
So actually... what if we just add an additional Perhaps something like: I feel like the distinction between Also using the existing page callback means less duplicated code (eg: the logic for checking the private key, adding the And with all the above in mind, what do you think about renaming the I have this sketched up... will push commits shortly for your review... |
cdcf1be
to
87d59ad
Compare
…tead of a ?summary=1 GET parameter.
So I think we just need to fix the "empty" text issues (described above: #337 (comment)) - and then this is ready to merge! |
Thanks @mstenta! Just added two commits to fix those issues. Data wasn't displaying because the timestamp was being rounded to 12am that day in order to fit the |
Ah - this introduced a little bug. A check using |
Talked with @paul121 yesterday and added a few more commits:
|
Also documented these changes in the farmOS.org repo's |
Rebased and merged! Thanks again @paul121 ! |
This adds a
farm_sensor_listener_data_graphs_form
which renders graphs of sensor data with a fieldset of filters for value and date range. This is only a minor step towards a solution for #227, but seems likely that this is the most we will accomplish in farmOS 1.x. While there is greater support for graphing data with views in D8, it would be quite a bit of work to get it working in D7.I chose to make the graphs load a default date range (the past 7 days) rather than a default
limit
of 100 data points. Overall this seems more intuitive for users. The downside is that sensors which have not posted data within the past week, but have older values, will not display graphs of data by default. Open to ideas on this! Perhaps we could add a fallback condition to display the past X data points if the date range fails? Also, because this is a form, I believe that those loading the form could pre-load the form state with default filter values too.To make the date range work I had to make a change to the
farm_sensor_listener_data
helper function to allow disabling thelimit
(see notes on this commit: 1d95005). This seems to be the best solution that doesn't require changing the function's default values which might affect other current uses (especially those returning data via API).