• Products
    • Isadora
    • Get It
    • ADD-ONS
    • IzzyCast
    • Get It
  • Forum
  • Help
  • Werkstatt
  • Newsletter
  • Impressum
  • Dsgvo
  • Press
  • Isadora
  • Get It
  • ADD-ONS
  • IzzyCast
  • Get It
  • Press
  • Dsgvo
  • Impressum

Navigation

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Tags

    [SOLVED] ​Measuring average of a numeric value

    How To... ?
    6
    19
    3893
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • dbini
      dbini @jhoepffner last edited by

      @jhoepffner

      that's the one. much more simple than i expected. (i haven't really explored the Float Counter yet, but i guessed it would be useful in this situation) :)

      John Collingswood
      taikabox.com
      2019 MBPT 2.6GHZ i7 OSX15.3.2 16GB
      plus an old iMac and assorted Mac Minis for installations

      jhoepffner ? 2 Replies Last reply Reply Quote 0
      • jhoepffner
        jhoepffner @dbini last edited by

        @dbini

        Yes but there is no easy solution inside Isadora for very long time or for exact time of average… If you need a very accurate solution to make an average with the last 3200 sample (as in the Lauri answer, 1 hour of second sample), it would be necessary to have the possibility to store a 3200 (or more) items list. For me it is doable easily in Max/Msp (item list) or TD (Python array) but I dont know an easy way to do it in Isadora. Javascript (in my knowledge) cannot because the lack of global variable, data array is limited in number of items and you cannot move all the sample as you can do it with array in Python or list in Max. I think it would be also easy in Processing with OSC in/out but I have to see the weather outside !

        Another chalenge for json specialist.

        Jacques Hoepffner http://hoepffner.info
        GigaByte 550b / Ryzen 7 3800X / Ram 64 Go / RTX 3090 24 Go / SSD 2 To / raid0 32 To
        MBP 13' i5 2.6 Ghz 16 Go / Intel Iris / macOs 10.11.6 / izzy 2.6.1 + 3.0.3b2
        MBP 15' i7 2.6 Ghz 16 Go / GTX 650M 1Go/ MacOs10.13.3 / Izzy 2.6.1
        MSI GS65 i7 3.6 Ghz 32 Go / GTX 1070 8 Go / Windows 10 / Izzy 3.0.3b2

        DusX 1 Reply Last reply Reply Quote 0
        • ?
          A Former User @dbini last edited by

          @dbini

          40 sec interval, for this case.

          r.

          1 Reply Last reply Reply Quote 0
          • L
            Lauri last edited by

            Thank you ALL for your help! Yes, of course, that’s the solution, should have thought through it myself. 

            Anyway, here’s an image of my simple version, in this case, for measuring performance cycles. Seems to work well.

            Thousand thanks again!

            Lauri

            MacPro (2013), 3.0GHz 8-Core Intel Xeon E5, RAM 64GB, Dual AMB FirePro D700, OSX 10.13.6
            MacBookPro (15 inch 2018), 2.6 GHz Intel Core i7, RAM 32GB, Radeon Pro Vega 20, OSX 10.14.6

            DusX 1 Reply Last reply Reply Quote 0
            • DusX
              DusX Tech Staff last edited by

              it's easily done with javascript.. 

              I will write some code later today that will allow you to very flexibly setup the storing of values and calculation of there average. 

              Troikatronix Technical Support

              • New Support Ticket Link: https://support.troikatronix.com/support/tickets/new
              • My Add-ons: https://troikatronix.com/add-ons/?u=dusx
              • Profession Services: https://support.troikatronix.com/support/solutions/articles/13000109444-professional-services

              Running: Win 11 64bit, i7, M.2 PCIe SSD's, 32gb DDR4, nVidia GTX 4070 | located in Ontario Canada.

              1 Reply Last reply Reply Quote 0
              • DusX
                DusX Tech Staff @Lauri last edited by DusX

                @lauri

                Ok, I believe this Javascript code will do what you are looking for. https://gist.github.com/rwebbe...

                var dataSet = [];
                function debug(printString){
                    if (DebugMode){
                        print(printString + "\n");  
                    }
                }
                function main(){
                    // DO setup here: ONCE ONLY ************************************************
                    DebugMode = true; //example usage: debug("string" + var + "\n");
                    MaxValues = arguments[0]; // no Var makes global
                    
                    debug("Start DataSet Length = " + dataSet.length + "\n\n");
                

                // main function for LOOP **************************************************
                    main = function(){
                 
                if (dataSet.length >= MaxValues){
                dataSet.splice(0, 1); // remove first value since buffer is at Max
                }
                dataSet.push(arguments[1]); // add last received value to end of array, increasing total.
                 
                debug("DataSet Length = " + dataSet.length + "\n");
                //debug("DataSet = " + dataSet + "\n"); // gets big... but useful if you want to see all array values in smaller sets.
                 
                // reduce array using a function at add all values contained together.
                var Sum = dataSet.reduce(function(accumulator, currentValue, currentIndex, array) {
                return accumulator + currentValue;
                });
                 
                debug("DataSet Sum = " + Sum + "\n");
                 
                var Average = Sum / dataSet.length;
                 
                debug("DataSet Avg = " + Average + "\n\n");
                 
                out = [Average] // set output array
                return out; // return out array
                };

                // RUN ONCE FOR INIT ONLY
                var out = []; // declare out 
                    return out; // return from INIT state
                }


                This will create an array that expands with every new value that is received and output the Average of all the received values.
                It takes 2 inputs. The first is the Max number of values you want to hold for creating a sum (I tested with 3600).
                If you receive 1 value per second, setting this to 60 would make it so the code always gives you the average for the last minute (older values are dropped, and if there are less than 60 values... say its been running for 5 seconds... it will use the 5 values).
                You can of course set this number very high so the buffer/array covers a longer period of time. (this will use more system memory, but it should be very minimal).


                Currently, I have set

                DebugMode = true;

                This will output some useful information to the 'Monitor' Window if you open it.
                Once you have viewed this information, and are happy with the functioning of the code, change DebugMode to = false

                Troikatronix Technical Support

                • New Support Ticket Link: https://support.troikatronix.com/support/tickets/new
                • My Add-ons: https://troikatronix.com/add-ons/?u=dusx
                • Profession Services: https://support.troikatronix.com/support/solutions/articles/13000109444-professional-services

                Running: Win 11 64bit, i7, M.2 PCIe SSD's, 32gb DDR4, nVidia GTX 4070 | located in Ontario Canada.

                1 Reply Last reply Reply Quote 0
                • DusX
                  DusX Tech Staff @jhoepffner last edited by

                  @jhoepffner

                  There is no lack of Globals in Javascript. 
                  Declaring a variable without using the Var keyword makes it a global..
                  Using the Var keyword binds it to the scope of the current function.
                  In the case of the code I wrote, the array [] is set using the Var keyword, but its defined outside the Main functions scope, so it behaves as a global.

                  Troikatronix Technical Support

                  • New Support Ticket Link: https://support.troikatronix.com/support/tickets/new
                  • My Add-ons: https://troikatronix.com/add-ons/?u=dusx
                  • Profession Services: https://support.troikatronix.com/support/solutions/articles/13000109444-professional-services

                  Running: Win 11 64bit, i7, M.2 PCIe SSD's, 32gb DDR4, nVidia GTX 4070 | located in Ontario Canada.

                  jhoepffner 1 Reply Last reply Reply Quote 0
                  • jhoepffner
                    jhoepffner @DusX last edited by

                    @dusx

                    Thanks Ryan for the JS lesson and for the brillant demo.

                    Jacques Hoepffner http://hoepffner.info
                    GigaByte 550b / Ryzen 7 3800X / Ram 64 Go / RTX 3090 24 Go / SSD 2 To / raid0 32 To
                    MBP 13' i5 2.6 Ghz 16 Go / Intel Iris / macOs 10.11.6 / izzy 2.6.1 + 3.0.3b2
                    MBP 15' i7 2.6 Ghz 16 Go / GTX 650M 1Go/ MacOs10.13.3 / Izzy 2.6.1
                    MSI GS65 i7 3.6 Ghz 32 Go / GTX 1070 8 Go / Windows 10 / Izzy 3.0.3b2

                    1 Reply Last reply Reply Quote 0
                    • L
                      Lauri last edited by

                      @DusX Thousand thanks for your help!!! This is a great solution!

                      However, I noticed one flaw with it: if the value does not change, then it is not registered as a new value, it registers a value when it differs from the previous one.

                      For example, if I measure the average of performance fps (see the attached image), the output value of fps tends to stay at the value set in the preferences. And in this case the JS actor registers only values deviating from that (and the set value, when it reaches that again). So, lets say the fps cannot keep the set value all the time, but instead goes (time to time) below more than above, then the received value is not really an average.

                      Another thing is that the JS actor cannot be reset, unless you exit the stage and return into it. But this is a minor thing, and I can manage without that feature.

                      I don't know Java, so I cannot really propose a solution. My apologies for that.

                      MacPro (2013), 3.0GHz 8-Core Intel Xeon E5, RAM 64GB, Dual AMB FirePro D700, OSX 10.13.6
                      MacBookPro (15 inch 2018), 2.6 GHz Intel Core i7, RAM 32GB, Radeon Pro Vega 20, OSX 10.14.6

                      DusX 1 Reply Last reply Reply Quote 0
                      • DusX
                        DusX Tech Staff @Lauri last edited by DusX

                        @lauri
                        You are absolutely correct, submitting the same value doesn't work. 
                        Luckily there is a very easy fix.
                        Increase the number of Inputs from 2 to 3. Mutate the 3rd input to a trigger (connect a trigger to it.. maybe from a trigger delay)
                        And then connect your data value source to the 3rd input as well.
                        This will cause the JS actor to see a new trigger each time a value is entered, even when the value doesn't change. Running the code as expected.


                        And a fast fix to add a reset, enter this code:

                        if (arguments[3]){
                        dataSet = [];
                        return;
                        }

                        after

                        // main function for LOOP **************************************************
                            main = function(){

                        So that it looks like:

                        // main function for LOOP **************************************************
                         main = function(){
                        if (arguments[3]){
                        dataSet = [];
                        return;
                        }
                        if (dataSet.length >= MaxValues){

                        Then add another (4th) input, and mutate it to a trigger.
                        That trigger (input 4) will reset the array to empty.

                        Troikatronix Technical Support

                        • New Support Ticket Link: https://support.troikatronix.com/support/tickets/new
                        • My Add-ons: https://troikatronix.com/add-ons/?u=dusx
                        • Profession Services: https://support.troikatronix.com/support/solutions/articles/13000109444-professional-services

                        Running: Win 11 64bit, i7, M.2 PCIe SSD's, 32gb DDR4, nVidia GTX 4070 | located in Ontario Canada.

                        1 Reply Last reply Reply Quote 0
                        • L
                          Lauri last edited by

                          @DusX 

                          Thousand thanks! Works perfectly! 

                          Mutating the 3rd input to a trigger was a bit difficult – in what order to connect the input – but in the end, yes, works flawlessly. 

                          Thanks!!!

                          MacPro (2013), 3.0GHz 8-Core Intel Xeon E5, RAM 64GB, Dual AMB FirePro D700, OSX 10.13.6
                          MacBookPro (15 inch 2018), 2.6 GHz Intel Core i7, RAM 32GB, Radeon Pro Vega 20, OSX 10.14.6

                          D 1 Reply Last reply Reply Quote 1
                          • D
                            dritter @Lauri last edited by dritter

                            @lauri

                            I wrote the attached user actor  a few months  ago to provide an ongoing average FPS calculated from the most recent 100 samples, but it can be used for any stream of numbers. You are welcome to use it.

                            Don



                            Izzy 2.6.1 USB | MBP (mid 2015) 2.8 GHz i7, 16GB, AMD Radeon R9 | OSX 10.11.6
                            Corsair One, 3.7 GHz i7, 32GB, GTX1080 | Windows 10

                            1 Reply Last reply Reply Quote 2
                            • First post
                              Last post