Hello
I have a data table that represents results from several devices. Columns are Name, Size, Steps, Time.
I would like to create a workflow that will, on every new state received, calculate a minimum on the “Time” column and push the “Name” from that line into a new virtual device, for display on the dashboard.
I do not know MongoDB, can anyone help, please?
Thanks
Uri
Hi Uri,
I am looking for just a bit more information to help you here: are you trying to implement a MongoDB Node to update an already existing MongoDB database? Or are you trying to update a Losant Data Table with MongoDB Data?
In addition, what do you mean by “new virtual device”?
If you are trying to update values to new ones within the Mongo database, I would recommend taking a look at our MongoDB Node documentation. The way I would accomplish this is by placing z MongoDB Node after function node, which can be used to modify your payload data before updating it. Here is an example below:
Thanks!
Julia
Hi
Thank you for your reply.
I have used a create Losant data table node to store results from several devices. The table headers are “name”, “time” “distance”.
What I want is to create a node that will search the table for the minimal value on the time column, then extract the “name” property associated with that line. I want to use that valu in another node (“device command”) to set a variable in a second device to the “name” value extracted from the table. I will use an indicator node on a dashboard to display that “name” that corresponds to the minimum “time”
Make sense?
Thanks
Uri
Hi,
To find the minimal time value, which will be the oldest time value, you will need to implement a Function Node. Below you can see more on how to do this:
Here I have a workflow with a Table: Get Rows node that calls all of the data from my Data Table and stores it in an array on the payload. Adding a function node, we format the time correctly so it can be read as a number, and then the smallest value will be at the top of my array with correctly formatted numbers. You can also see all other available data for the row in the data table. For example, you can see “id”, “title”, and many other data points within the array. You can then use this data to set a variable in another device, like you mentioned, with the name on the payload. Here is an example of using a payload value to update another device:
.
Hopefully this helps,
Julia
Hello Julia
Thant worked like a charm, thanks a lot!
which arise 2 new questions:
-
How do I create a virtual button (new workflow) that will delete ALL rows in a table
-
In the dashboard, I placed a table view item for the table. This item does not auto-refresh when a new data comes in. Any way to make it do so?
Thanks!
Uri
Hi Uri,
Glad to hear it’s working!
For your first question, it sounds like you want the ability to delete everything in your data table with one click, which can be helpful if you have a lot of data, and no use for it! The way I would do this is to use the Table: Delete Rows node with a Virtual Button. Here is an example:
Here I have my table, it holds two values “First” and “Last.”
Within my workflow I use the Table: Delete Rows node and compare the id value to zeros, as I know my id will never be this value. You can also do this with other properties, such as createdAt or, in my case, Name. If I know I will never have anyone named “Zack,” I could put “First !== Zack,” and every Row where the First value is not Ryan will be deleted.
Now I have successfully deleted all of my rows, and can fill my table again!
For your second question, there is not currently a way to auto-refresh this block, but I will give this to our dev team as a feature request!
Hopefully this helps,
Julia
Thanks a lot!
I was hoping the table does have a secret refresh-on-update as I have a project due this tuesday that needs to show such a table…
Is there a way around this? say trigger a workflow on a new device status that will read the table, delete all, then refill it?
Hi Uri,
What is your overarching goal for this project and the table? I want to make sure we give you the best suggestions for your use case.
What are you currently using the data table to show, and what is your goal in deleting and replacing data in your table?
Thanks!
Julia
Here goes…
The table represents the results obtained by my students when they run an experiment on an IoT device they built as their final class project.
Each student will run several experiments while the data collects to MY account so that the best result (student with most accurate result) can be found.
For this I calculate several functions on the row data and calculate either a minimum or a maximum as needed to find the “best” one.
Deleting is a way to reset this data between major experiment types.
The dashboard for this app shows the “best” results using indicators & gauges while the table is there so that each student can see that his result was added to the calculation as he completed his task. For this I want to show results in a chronological order as soon as they come in - even if the “best” result (shown by the indicators/gauges) does not change.
making sense?
Uri
Hello!
The Data Table is, unfortunately, unable to live update with the dashboard, though I have requested it as a feature. In this use case, if you are looking to show the data coming in live, I would recommend using the Device State Table block within your dashboard, so you will be able to see each state come in, and will be able to order them in chronological order. The dashboard will also live-update as new states come in. Here is an example:
You can also use an Indicator Block next to your Data Table or Device State Table to show the data you would like to, as you can display data and use Context Variables within the Indicator Block.
I would recommend still using the data table to do these calculations. This way, using both the device state and data table, you will be able to show the data on your dashboard, as well as use it in calculations within a workflow.
Hopefully this helps,
Julia