Sorting an output array of mapointstatistics

Hello
im trying sort an output array of a mapointstatistics .. I sort it correctly but then i need to be able to get or print or copy the max value to a variable
Basically i have<macalc input="day  maMoment:'add':preset:'days'" output="day2"></macalc> <macalc input="day2  maMoment:'set':{'hour': 5, 'minute': 0}" output="from"></macalc> <mapointquery query="'or(name=like=STR_5*)'" limit="300" points="box5"></mapointquery> <mapointvalues points="box5" values="box5_val" from="from" to="dateBar.to" rollup="INTEGRAL" rollupinterval="1 DAYS"> </mapointvalues> <mapointstatistics points="box5" rendered=false from="from" to="dateBar.to" statistics="statsObj"></mapointstatistics> {{ statsObj  orderBy:'integral.value'}} {{statsObj[0].integral.value }} <script> console.log(statsObj); </script>
I would expect that the {{statsObj[0].integral.value }} would give me the 0 entry of my sorted array so the max integral value .. but it doesnt . it still gives me the first entry of the unsorted array..
Is there a way to copy it to a new array and there have the sorted one ?{{statsObj2=statsObj  orderBy:'integral.value'}} {{statsObj2[0].integral.value }}
the above is not working
maybe with javascript ?
2) by the way i try to console.log the statsObj and i got error is not defined .. how do i console.log the output of any of the mango directives ?<script> console.log(statsObj); </script>
the above gives me error statsObj is undefined
 basically im trying to find the maximum of integral of few data points
What is the best approach that i have above?
a)
<mapointquery query="'or(name=like=STR_5*)'" limit="300" points="box5"></mapointquery> <mapointvalues points="box5" values="box5_val" from="from" to="dateBar.to" rollup="INTEGRAL" rollupinterval="1 DAYS"> </mapointvalues>
or b)
<mapointquery query="'or(name=like=STR_5*)'" limit="300" points="box5"></mapointquery> <mapointstatistics points="box5" rendered=false from="from" to="dateBar.to" statistics="statsObj"></mapointstatistics>
which is the fastest computing method and more clever way to do it ?
In the same page i will have multiple pairs of (queries and mapointstatistics) or (queries and mapointvalues) .. Which is the one that will crash less the system and is more time and cpu efficient?
thank you !  basically im trying to find the maximum of integral of few data points

Hi uelojazz,
I would expect that the {{statsObj[0].integral.value }} would give me the 0 entry of my sorted array so the max integral value .. but it doesnt . it still gives me the first entry of the unsorted array..
Ah but that output wasn't assigned to a variable. This is one function of the macalc, so doing
<macalc input="statsObj2  orderBy:'integral.value'" output="sortedStatsObj2"></macalc>
Would allow you to refer to the sorted array elsewhere in the markup. inside the
{{ }}
which is the fastest computing method and more clever way to do it ?
Those snippets aren't doing the same thing. The first should give the integral statistic value in time ordered one day chunks, while the second should only provide a statistics object for each point over the whole period. I wouldn't expect too significant a different in the demands on the server for the same points over the same time range.

thank you , didnt know all the capabilities of the macalc are there more examples or documentation available? i guess it can be used in various ways.
I have multiple errors now in my console
Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: [[{"msg":"fn: r","newVal":[{"hasData":true,"first":"...","last":"...","start":"...","minimum":"...","maximum":"...","average":"...","integral":"...","sum":"...","count":6912},Basically my code now looks like that:
<macalc input="day  maMoment:'add':preset:'days'" output="day2"></macalc> <macalc input="day2  maMoment:'set':{'hour': 5, 'minute': 0}" output="myfrom"></macalc> <mapointquery query="'or(name=like=STR_4.*,name=like=*STR_5.*,name=like=*STR_6.*,name=like=STR_7.*,name=like=*STR_8.*,name=like=*STR_9.*)'" limit="300" points="points1"></mapointquery> <mapointvalues points="points1" values="combined" from="myfrom" to="dateBar.to" rollup="INTEGRAL" rollupinterval="1 DAYS"> </mapointvalues> <mapointstatistics points="points1" rendered=false from="myfrom" to="dateBar.to" displaymode="INTEGRAL" timeout=7000 statistics="statsObj"></mapointstatistics> <macalc input= statsObjorderBy:'integral.value'maFirst output="max" ></macalc> <macalc input= statsObjorderBy:'integral.value' output="sorted_integrals" ></macalc> <macalc input= "((max.integral.value) * 0.8)" output="max8" ></macalc> <div ngrepeat="(index,value) in sorted_integrals"> <div ngrepeat="point in points1">XID: {{point.xid}} , Time: {{value.timestamp  maMoment:'format':'DD/MM/YYYY'}} ,Point Name: {{point.name}} ,Point Value: {{value['value_' + point.xid]}}</div> </div>

Seems that those macalc are updating their values constantly .. tried to timeout the statistics in 7seconds but didnt work .. is this the reason of the errors in the console ?

i would like to filter and get only the integral values of my statistics object so i can print that array sorted with the ngrepeat ..
first line should be the biggest integral ..
Tried with displaymode="INTEGRAL" in the mapointstatistcs directive but im not sure exactly what is does since there is no example in the documentation ..is it supposed to filter only the integral values ?
Also i tried to filter it and print it by
<macalc input= statsObj filter:{statistics:'INTEGRAL'}orderBy:'integral.value' output="sorted_integrals" ></macalc> <div ngrepeat="(index,value) in sorted_integrals"> <div ngrepeat="point in points1">XID: {{point.xid}} , Time: {{value.timestamp  maMoment:'format':'DD/MM/YYYY'}} ,Point Name: {{point.name}} ,Point Value: {{value['value_' + point.xid]}}</div> </div>
but its not working. the sorted_integrals still contains all the statistics like average, first etc that i dont need in order to correctly ngrepeat <div ngrepeat="(index,value) in sorted_integrals">
3)also my
<div ngrepeat="(index,value) in sorted_integrals"> <div ngrepeat="point in points1">XID: {{point.xid}} , Time: {{value.timestamp  maMoment:'format':'DD/MM/YYYY'}} ,Point Name: {{point.name}} ,Point Value: {{value['value_' + point.xid]}}</div> </div>
Is not sorted by the biggest integral.. it gives me the default sort of the point XID of the mapointquery
And it gets even more complicated when i have null or undefined values in my integral values .. the orderby by default sorts the nulls and undefined as greater than numbers ... tried few workarounds like the fowllowing but none of them work.. how to sort it correctly and keep the nulls and undefined at the end so i get the biggest value first ?
<macalc input= statsObj orderBy:['integral.value==null  integral.value'] output="max" ></macalc> <macalc input= statsObj orderBy:['!integral.value', 'integral.value', ] output="max" ></macalc>
Basically i want to sort the statistics object by biggest integral, then keep only the integral values and then print a table of the sorted values withe their corresponding data point names and xid
What im doing wrong ?
thank you very much :) 

any help on the above questions ? :)
Can you at least help me out how to orderBy the combined array by the biggest value ?<manow updateinterval="1 MINUTES" output="now"></manow> <macalc input="(now  maDate: 'HH')*60++(now  maDate: 'mm')1" output="rollupHours"></macalc> <macalc input="now  maMoment:'startOf':'day'" output="myfrom"></macalc> <mapointquery query="'or(name=like=STR_4.*,name=like=*STR_5.*,name=like=*STR_6.*,name=like=STR_7.*,name=like=*STR_8.*,name=like=*STR_9.*)'" limit="300" sort="'name'" points="points1"></mapointquery> <mapointvalues points="points1" from="myfrom" to="now" values="combined" rollup="INTEGRAL" rollupinterval="{{rollupHours}} MINUTES" ></mapointvalues> <! here im trying somehow to sort the combined array by biggest values .. how to do it with my calc ? what exactly im supposed to write inthe orderBy since this array has not keys ?> <macalc input="combined" orderBy:'value_' output="combined_sorted"></macalc> <! and here im trying to print the output by orderBy .. so i would need the biggest value on top and not sorted by name as is by default > <div ngrepeat="(index,value) in combined orderBy:value['value_' + point.xid]"> <div ngrepeat="point in points1">XID: {{point.xid}} , Time: {{value.timestamp  maMoment:'format':'DD/MM/YYYY'}} ,Point Name: {{point.name}} ,Point Value: {{value['value_' + point.xid]}}</div> </div>
My output is the following which i would like to have it sorted my the biggest Point Value .. how to do this with ngrepeat and orderBy ??
thank you very muchXID: ST_000924 , Time: 27/06/2018 ,Point Name: STR_9.24 ,Point Value: 107.25
XID: ST_000923 , Time: 27/06/2018 ,Point Name: STR_9.23 ,Point Value: 152675.05
XID: ST_000922 , Time: 27/06/2018 ,Point Name: STR_9.22 ,Point Value: 154184.4
XID: ST_000921 , Time: 27/06/2018 ,Point Name: STR_9.21 ,Point Value: 0.6And what i would like to have is :
XID: ST_000922 , Time: 27/06/2018 ,Point Name: STR_9.22 ,Point Value: 154184.4
XID: ST_000923 , Time: 27/06/2018 ,Point Name: STR_9.23 ,Point Value: 152675.05
XID: ST_000924 , Time: 27/06/2018 ,Point Name: STR_9.24 ,Point Value: 107.25
XID: ST_000921 , Time: 27/06/2018 ,Point Name: STR_9.21 ,Point Value: 0.6 
@uelojazz said in Sorting an output array of mapointstatistics:
I would expect that the {{statsObj[0].integral.value }} would give me the 0 entry of my sorted array so the max integral value
This is an incorrect assumption. It does not sort the input array in place. Please see
https://docs.angularjs.org/api/ng/filter/orderBy@uelojazz said in Sorting an output array of mapointstatistics:
by the way i try to console.log the statsObj and i got error is not defined .. how do i console.log the output of any of the mango directives ?
You can't, this is not how AngularJS works. The variables used on the page are properties of the AngularJS scope, not the global window object.
If you want to see the value of a variable on the scope, use something like this
<pre ngbind="myVar  json"></pre>
@uelojazz said in Sorting an output array of mapointstatistics:
which is the fastest computing method and more clever way to do it ?
I would suggest focusing on results first. Optimize later if necessary.
Something like this is what you want.
<macalc input="statsObj2  orderBy:'integral.value'  maFirst" output="biggestValue"></macalc>
@uelojazz said in Sorting an output array of mapointstatistics:
thank you , didnt know all the capabilities of the macalc are there more examples or documentation available?
Its very basic and you have already used it, it has an input expression which it evaluates and assigns to the output.
For more documentation and examples, please see https://help.infiniteautomation.com/gettingstarted/ and https://help.infiniteautomation.com/editingthemenu for how to enable the built in examples and api docs.
@uelojazz said in Sorting an output array of mapointstatistics:
Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
This was caused by using a filter that outputs an array in the
<macalc>
, don't do that.@uelojazz said in Sorting an output array of mapointstatistics:
Seems that those macalc are updating their values constantly .. tried to timeout the statistics in 7seconds but didnt work .. is this the reason of the errors in the console ?
Correct and yes.
@uelojazz said in Sorting an output array of mapointstatistics:
but its not working
As above don't use a filter that outputs an array in a macalc. Just put the whole expression in the
ngrepeat
and it should work.@uelojazz said in Sorting an output array of mapointstatistics:
And it gets even more complicated when i have null or undefined values in my integral values ..
Use a filter  https://docs.angularjs.org/api/ng/filter/filter to remove the undefined values before sorting.
@uelojazz You are going to have to do some reading and learning on AngularJS since you are trying to use some more advanced functionality than what we expose in the Dashboard designer.
https://docs.angularjs.org/tutorial
https://www.w3schools.com/angular/angular_intro.asp 
@JaredWiltshire thank you very much !
yes i figured it out how to sort the output of a mapointstatistics with macalc..
Can you help me out how to sort an output of a mapointvalues ?
Im not sure how which variable exaclty i have to orderBy and how to correctly to the ngrepeat.
Basically this was my last question, how to sort the combined array of a mapointvalues https://forum.infiniteautomation.com/topic/3603/sortinganoutputarrayofmapointstatistics/4]Also do you have any link of User module URL examples (or an actual page that you are allowed to share) .
Just to get ideas and see how to properly write components, modules,controllers etc in the userModule.js of mango
Thank you very much ! 
@uelojazz said in Sorting an output array of mapointstatistics:
Also do you have any link of User module URL examples (or an actual page that you are allowed to share) .
https://help.infiniteautomation.com/gettingstartedwithausermodule/
Also search the forum, I have posted plenty of examples.
https://forum.infiniteautomation.com/search?term=user module&in=titlesposts@uelojazz said in Sorting an output array of mapointstatistics:
Can you help me out how to sort an output of a mapointvalues ?
What exactly are you trying to do? It looks like you are trying to find the points with the largest xminute integral? Do you want this per point for each xminute window? I would say you might need to write a custom component in a user module for this.