DataPoint values into a var javascript
-
Hello,
I need to insert a button in a dashboard that generates a csv file with values(included in a range of dates) of a given data point.
Is there any way to do it?
Or the best alternative would be to put all the values of a datapoint into a javascript variable, so you can process them and then generate a csv.Thanks a lot.
-
A similar question has already been asked,
This asks to upload but it also contains the code required to generate a new csv.
Assuming you are a competent programmer, this is a route you can take.
https://forum.infiniteautomation.com/topic/4041/processing-files -
Here's an example, you can download CSV straight from the REST API
<ma-watch-list-get ng-model="designer.watchList" parameters="designer.parameters" on-points-change="designer.points = $points" id="29305bf3-cc2a-4bac-9650-3cbf64d738a9" watch-list-xid="WL_Flow"></ma-watch-list-get> <div class="ma-designer-root" id="1a2a6980-f5bb-4acc-a41a-f8f69d5c12d2" style="width: 1366px; height: 768px; position: relative;"> <ma-calc input="designer.points | filter:{name:'Flow'}:true | maFirst" output="point"></ma-calc> <md-button id="2585b1fa-a630-4255-8670-41884b8754e2" style="position: absolute; left: 260px; top: 70px;" class="md-raised" ng-href="/rest/v2/point-values/time-period/{{point.xid}}?fields=TIMESTAMP&fields=VALUE&fields=ANNOTATION&from={{dateBar.from.toISOString()}}&to={{dateBar.to.toISOString()}}&format=csv2" download="{{point.name}}.csv">Download values</md-button> </div>
-
Thanks for the answers.
I used the Jared method and it works, but due to a problem with the data timestamp I need to have the values of a data point in a javascript variable.
Do you have any options? -
What's wrong with the time format?
Are you opening the csv with excel or something like notepad? -
You can add
&dateTimeFormat=yyyy-MM-dd%20HH%3Amm%3Ass.SSS
to the end of the URL to change the date encoding to a Excel compatible format.edit.
Also, you can write a user module that loads point values using themaPointValues
service and do whatever you please. Reference the thread that @MattFox linked to above for inspiration. Also search the help site and forum, there are lots of threads about user modules / components. -
I need to download a csv file with the values of multiple data points, but not all values have the same timestamp. For this reason, I would like to have the values in a variable so I can process it and write it all in one line.
-
Just so I understand correctly. You want all values to appear in the same row in order for a given day/hour?
Timestamps will differ as no two values will ever come in at the same time.
But for those that do, you want them appended on the same line. Correct?To make things easier, it might be better to average all of your points so all timestamps match then you can list columns as a
timestamp,datapoint1,datapoint2
format.
Let me know your thoughtsFox
-
@davide27 said in DataPoint values into a var javascript:
I need to download a csv file with the values of multiple data points, but not all values have the same timestamp. For this reason, I would like to have the values in a variable so I can process it and write it all in one line.
Please have a play with the CSV download from the watch list. Try it with different rollup options and see if you can get something that works for you. If this suffices I can give you an example of a new URL you can use in the example I posted above.
The reason I am suggesting this is because it will be easier for you, I have given you suggestions on how to proceed if you really want to process the values using JavaScript but you haven't given me any indication that you have looked at the documentation I referenced.