Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.

Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website

Sorting an output array of ma-point-statistics


  • Hello
    im trying sort an output array of a ma-point-statistics .. 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

    <ma-calc input="day | maMoment:'add':preset:'days'" output="day2"></ma-calc>
    <ma-calc input="day2 | maMoment:'set':{'hour': 5, 'minute': 0}" output="from"></ma-calc>
    <ma-point-query query="'or(name=like=STR_5*)'" limit="300" points="box5"></ma-point-query>
    <ma-point-values points="box5" values="box5_val" from="from" to="dateBar.to" rollup="INTEGRAL" rollup-interval="1 DAYS">
    </ma-point-values>
    <ma-point-statistics points="box5" rendered=false from="from" to="dateBar.to" statistics="statsObj"></ma-point-statistics>
    
    {{ 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

    1. basically im trying to find the maximum of integral of few data points
      What is the best approach that i have above?
      a)
    <ma-point-query query="'or(name=like=STR_5*)'" limit="300" points="box5"></ma-point-query>
    <ma-point-values points="box5" values="box5_val" from="from" to="dateBar.to" rollup="INTEGRAL" rollup-interval="1 DAYS">
    </ma-point-values>
    

    or b)

    <ma-point-query query="'or(name=like=STR_5*)'" limit="300" points="box5"></ma-point-query>
    <ma-point-statistics points="box5" rendered=false from="from" to="dateBar.to" statistics="statsObj"></ma-point-statistics>
    

    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 ma-point-statistics) or (queries and ma-point-values) .. Which is the one that will crash less the system and is more time and cpu efficient?
    thank you !


  • 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 ma-calc, so doing

    <ma-calc input="statsObj2 | orderBy:'-integral.value'" output="sortedStatsObj2"></ma-calc>
    

    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 ma-calc 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:

    <ma-calc input="day | maMoment:'add':preset:'days'" output="day2"></ma-calc>
    <ma-calc input="day2 | maMoment:'set':{'hour': 5, 'minute': 0}" output="myfrom"></ma-calc>
    <ma-point-query 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"></ma-point-query>
    <ma-point-values points="points1" values="combined" from="myfrom" to="dateBar.to" rollup="INTEGRAL" rollup-interval="1 DAYS">
    </ma-point-values>
    
    <ma-point-statistics points="points1" rendered=false from="myfrom" to="dateBar.to" display-mode="INTEGRAL" timeout=7000 statistics="statsObj"></ma-point-statistics>
    
    <ma-calc input= statsObj|orderBy:'-integral.value'|maFirst  output="max" ></ma-calc>
    <ma-calc input= statsObj|orderBy:'-integral.value' output="sorted_integrals" ></ma-calc>
    <ma-calc input= "((max.integral.value) * 0.8)" output="max8" ></ma-calc>
    
    <div ng-repeat="(index,value) in sorted_integrals">
        <div ng-repeat="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>
    
    1. Seems that those ma-calc 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 ?

    2. i would like to filter and get only the integral values of my statistics object so i can print that array sorted with the ng-repeat ..
      first line should be the biggest integral ..
      Tried with display-mode="INTEGRAL" in the ma-point-statistcs 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

    <ma-calc input= statsObj |filter:{statistics:'INTEGRAL'}|orderBy:'-integral.value' output="sorted_integrals" ></ma-calc>
    
    <div ng-repeat="(index,value) in sorted_integrals">
        <div ng-repeat="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 ng-repeat <div ng-repeat="(index,value) in sorted_integrals">

    3)also my

    <div ng-repeat="(index,value) in sorted_integrals">
        <div ng-repeat="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 ma-point-query

    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 ?

    <ma-calc input= statsObj| orderBy:['integral.value==null || integral.value']  output="max" ></ma-calc>
    <ma-calc input= statsObj| orderBy:['!integral.value', '-integral.value', ]  output="max" ></ma-calc>
    

    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 ?

    <ma-now update-interval="1 MINUTES" output="now"></ma-now>
    <ma-calc input="(now | maDate: 'HH')*60++(now | maDate: 'mm')--1"   output="rollupHours"></ma-calc>
    <ma-calc input="now | maMoment:'startOf':'day'" output="myfrom"></ma-calc>
    
    <ma-point-query 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"></ma-point-query>
    <ma-point-values points="points1" from="myfrom" to="now" values="combined"  rollup="INTEGRAL" rollup-interval="{{rollupHours}} MINUTES" ></ma-point-values>
    
    <!-- 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 ?-->
    <ma-calc input="combined" |orderBy:'value_' output="combined_sorted"></ma-calc>
    
    <!-- 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 ng-repeat="(index,value) in combined |orderBy:value['value_' + point.xid]">
        <div ng-repeat="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 ng-repeat and orderBy ??
    thank you very much

    XID: 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.6

    And 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 ma-point-statistics:

    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 ma-point-statistics:

    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 ng-bind="myVar | json"></pre>

    @uelojazz said in Sorting an output array of ma-point-statistics:

    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.
    <ma-calc input="statsObj2 | orderBy:'-integral.value' | maFirst" output="biggestValue"></ma-calc>

    @uelojazz said in Sorting an output array of ma-point-statistics:

    thank you , didnt know all the capabilities of the ma-calc 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/getting-started/ and https://help.infiniteautomation.com/editing-the-menu for how to enable the built in examples and api docs.

    @uelojazz said in Sorting an output array of ma-point-statistics:

    Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!

    This was caused by using a filter that outputs an array in the <ma-calc>, don't do that.

    @uelojazz said in Sorting an output array of ma-point-statistics:

    Seems that those ma-calc 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 ma-point-statistics:

    but its not working

    As above don't use a filter that outputs an array in a ma-calc. Just put the whole expression in the ng-repeat and it should work.

    @uelojazz said in Sorting an output array of ma-point-statistics:

    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


  • @Jared-Wiltshire thank you very much !
    yes i figured it out how to sort the output of a ma-point-statistics with ma-calc..
    Can you help me out how to sort an output of a ma-point-values ?
    Im not sure how which variable exaclty i have to orderBy and how to correctly to the ng-repeat.
    Basically this was my last question, how to sort the combined array of a ma-point-values https://forum.infiniteautomation.com/topic/3603/sorting-an-output-array-of-ma-point-statistics/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 ma-point-statistics:

    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/getting-started-with-a-user-module/

    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 ma-point-statistics:

    Can you help me out how to sort an output of a ma-point-values ?

    What exactly are you trying to do? It looks like you are trying to find the points with the largest x-minute integral? Do you want this per point for each x-minute window? I would say you might need to write a custom component in a user module for this.