<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Moving avg and windowing functions in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/Moving-avg-and-windowing-functions/m-p/2199637#M2461</link>
    <description>Hi Juergen, 
&lt;BR /&gt;this is possible but only with a custom method. Following a simple routine. This is not an example for good coding practice... 
&lt;BR /&gt;But I think this is a good point to start. 
&lt;BR /&gt; 
&lt;PRE&gt;public class forum5020routine {&lt;BR /&gt;	private static Double[] values=  null;&lt;BR /&gt;	private static int      numberOfIterations= 0;&lt;BR /&gt;	private static int      count=   0;&lt;BR /&gt;	private static int      pointer= 0;&lt;BR /&gt;	&lt;BR /&gt;    /**&lt;BR /&gt;     * movingAvg: returns the moving average for a predefined number of values &lt;BR /&gt;     * &lt;BR /&gt;     * {talendTypes} Double&lt;BR /&gt;     * &lt;BR /&gt;     * {Category} User Defined&lt;BR /&gt;     * &lt;BR /&gt;     * {param} int("count") count:    Number of last values to handle for the arithmetic operation&lt;BR /&gt;     * {param} Double("value") value: Actual Double value&lt;BR /&gt;     * &lt;BR /&gt;     * {example} movingAvg(5, 3.2)&lt;BR /&gt;     */&lt;BR /&gt;    public static Double movingAvg(int count, Double value) {&lt;BR /&gt;    	// initialize count value and array for storing the values&lt;BR /&gt;    	if (forum5020routine.count == 0) {&lt;BR /&gt;    		forum5020routine.count= count;&lt;BR /&gt;    		forum5020routine.values= new Double;&lt;BR /&gt;    		for (int i=0; i &amp;lt; count; i++) {&lt;BR /&gt;    			forum5020routine.values&lt;I&gt;= new Double(0);&lt;BR /&gt;    		}&lt;BR /&gt;    	}&lt;BR /&gt;    &lt;BR /&gt;    	// add the actual value to the array and reset pointer if needed &lt;BR /&gt;    	// the array is used as a circular data container&lt;BR /&gt;    	forum5020routine.values= value;&lt;BR /&gt;    	forum5020routine.pointer++;&lt;BR /&gt;    	if (forum5020routine.pointer &amp;gt;= forum5020routine.count) {&lt;BR /&gt;    		forum5020routine.pointer= 0;&lt;BR /&gt;    	}&lt;BR /&gt;    	// remember the actual iteration. This is only needed to calculate &lt;BR /&gt;    	// the n first values (n &amp;lt; count)&lt;BR /&gt;    	forum5020routine.numberOfIterations++;&lt;BR /&gt;    	&lt;BR /&gt;    	// calculate and return value&lt;BR /&gt;    	Double sum= new Double(0.0);&lt;BR /&gt;    	for (Double v: forum5020routine.values) {&lt;BR /&gt;    		sum+=v;&lt;BR /&gt;    	}&lt;BR /&gt;    	&lt;BR /&gt;    	if (forum5020routine.numberOfIterations &amp;lt; forum5020routine.count) {&lt;BR /&gt;    		return (sum / forum5020routine.numberOfIterations);&lt;BR /&gt;    	} else {&lt;BR /&gt;    		return (sum / forum5020routine.count);&lt;BR /&gt;    	}&lt;BR /&gt;    }&lt;BR /&gt;}&lt;/I&gt;&lt;/PRE&gt; 
&lt;BR /&gt;The result is: 
&lt;BR /&gt; 
&lt;PRE&gt;1|6.74|6.74&lt;BR /&gt;2|3.82|5.28&lt;BR /&gt;3|1.65|4.07&lt;BR /&gt;4|1.71|3.4800000000000004&lt;BR /&gt;5|9.3|4.644&lt;BR /&gt;6|3.26|3.9480000000000004&lt;BR /&gt;7|6.96|4.576&lt;BR /&gt;8|1.89|4.6240000000000006&lt;BR /&gt;9|2.9|4.862&lt;BR /&gt;10|8.27|4.656000000000001&lt;/PRE&gt; 
&lt;BR /&gt;Bye 
&lt;BR /&gt;Volker</description>
    <pubDate>Tue, 16 Dec 2008 21:54:23 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2008-12-16T21:54:23Z</dc:date>
    <item>
      <title>Moving avg and windowing functions</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Moving-avg-and-windowing-functions/m-p/2199636#M2460</link>
      <description>Hello, 
&lt;BR /&gt;I'm testing and working with Talend since a few weeks now. Mainly without database but using XML files as input and output. 
&lt;BR /&gt;In my Version 3.0.2/Java on windows I can't find a way to build a moving avg over a number of rows, lets say the last 5 rows. Can anybody help me, getting on the right track. 
&lt;BR /&gt;So, I have kind of the following input-rows: 
&lt;BR /&gt;id value 
&lt;BR /&gt;1 6,74 
&lt;BR /&gt;2 3,82 
&lt;BR /&gt;3 1,65 
&lt;BR /&gt;4 1,71 
&lt;BR /&gt;5 9,3 
&lt;BR /&gt;6 3,26 
&lt;BR /&gt;7 6,96 
&lt;BR /&gt;8 1,89 
&lt;BR /&gt;9 2,9 
&lt;BR /&gt;10 8,27 
&lt;BR /&gt;Ouput-row should look like: 
&lt;BR /&gt;id value moving avg 
&lt;BR /&gt;1 6,74 6,74 -&amp;gt; avg over rows 1 to 1 
&lt;BR /&gt;2 3,82 5,28 -&amp;gt; avg over rows 1 to 2 
&lt;BR /&gt;3 1,65 4,07 -&amp;gt; avg over rows 1 to 3 
&lt;BR /&gt;4 1,71 3,48 -&amp;gt; avg over rows 1 to 4 
&lt;BR /&gt;5 9,3 4,64 -&amp;gt; avg over rows 1 to 5 
&lt;BR /&gt;6 3,26 3,95 -&amp;gt; avg over rows 2 to 6 
&lt;BR /&gt;7 6,96 4,58 -&amp;gt; avg over rows 3 to 7 
&lt;BR /&gt;8 1,89 4,62 -&amp;gt; avg over rows 4 to 8 
&lt;BR /&gt;9 2,9 4,86 -&amp;gt; avg over rows 5 to 9 
&lt;BR /&gt;10 8,27 4,66 -&amp;gt; avg over rows 6 to 10 
&lt;BR /&gt;The question is: Can I do this with Talend? Which components do that with which configuration? 
&lt;BR /&gt;Juergen</description>
      <pubDate>Sat, 16 Nov 2024 14:07:18 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Moving-avg-and-windowing-functions/m-p/2199636#M2460</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-11-16T14:07:18Z</dc:date>
    </item>
    <item>
      <title>Re: Moving avg and windowing functions</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Moving-avg-and-windowing-functions/m-p/2199637#M2461</link>
      <description>Hi Juergen, 
&lt;BR /&gt;this is possible but only with a custom method. Following a simple routine. This is not an example for good coding practice... 
&lt;BR /&gt;But I think this is a good point to start. 
&lt;BR /&gt; 
&lt;PRE&gt;public class forum5020routine {&lt;BR /&gt;	private static Double[] values=  null;&lt;BR /&gt;	private static int      numberOfIterations= 0;&lt;BR /&gt;	private static int      count=   0;&lt;BR /&gt;	private static int      pointer= 0;&lt;BR /&gt;	&lt;BR /&gt;    /**&lt;BR /&gt;     * movingAvg: returns the moving average for a predefined number of values &lt;BR /&gt;     * &lt;BR /&gt;     * {talendTypes} Double&lt;BR /&gt;     * &lt;BR /&gt;     * {Category} User Defined&lt;BR /&gt;     * &lt;BR /&gt;     * {param} int("count") count:    Number of last values to handle for the arithmetic operation&lt;BR /&gt;     * {param} Double("value") value: Actual Double value&lt;BR /&gt;     * &lt;BR /&gt;     * {example} movingAvg(5, 3.2)&lt;BR /&gt;     */&lt;BR /&gt;    public static Double movingAvg(int count, Double value) {&lt;BR /&gt;    	// initialize count value and array for storing the values&lt;BR /&gt;    	if (forum5020routine.count == 0) {&lt;BR /&gt;    		forum5020routine.count= count;&lt;BR /&gt;    		forum5020routine.values= new Double;&lt;BR /&gt;    		for (int i=0; i &amp;lt; count; i++) {&lt;BR /&gt;    			forum5020routine.values&lt;I&gt;= new Double(0);&lt;BR /&gt;    		}&lt;BR /&gt;    	}&lt;BR /&gt;    &lt;BR /&gt;    	// add the actual value to the array and reset pointer if needed &lt;BR /&gt;    	// the array is used as a circular data container&lt;BR /&gt;    	forum5020routine.values= value;&lt;BR /&gt;    	forum5020routine.pointer++;&lt;BR /&gt;    	if (forum5020routine.pointer &amp;gt;= forum5020routine.count) {&lt;BR /&gt;    		forum5020routine.pointer= 0;&lt;BR /&gt;    	}&lt;BR /&gt;    	// remember the actual iteration. This is only needed to calculate &lt;BR /&gt;    	// the n first values (n &amp;lt; count)&lt;BR /&gt;    	forum5020routine.numberOfIterations++;&lt;BR /&gt;    	&lt;BR /&gt;    	// calculate and return value&lt;BR /&gt;    	Double sum= new Double(0.0);&lt;BR /&gt;    	for (Double v: forum5020routine.values) {&lt;BR /&gt;    		sum+=v;&lt;BR /&gt;    	}&lt;BR /&gt;    	&lt;BR /&gt;    	if (forum5020routine.numberOfIterations &amp;lt; forum5020routine.count) {&lt;BR /&gt;    		return (sum / forum5020routine.numberOfIterations);&lt;BR /&gt;    	} else {&lt;BR /&gt;    		return (sum / forum5020routine.count);&lt;BR /&gt;    	}&lt;BR /&gt;    }&lt;BR /&gt;}&lt;/I&gt;&lt;/PRE&gt; 
&lt;BR /&gt;The result is: 
&lt;BR /&gt; 
&lt;PRE&gt;1|6.74|6.74&lt;BR /&gt;2|3.82|5.28&lt;BR /&gt;3|1.65|4.07&lt;BR /&gt;4|1.71|3.4800000000000004&lt;BR /&gt;5|9.3|4.644&lt;BR /&gt;6|3.26|3.9480000000000004&lt;BR /&gt;7|6.96|4.576&lt;BR /&gt;8|1.89|4.6240000000000006&lt;BR /&gt;9|2.9|4.862&lt;BR /&gt;10|8.27|4.656000000000001&lt;/PRE&gt; 
&lt;BR /&gt;Bye 
&lt;BR /&gt;Volker</description>
      <pubDate>Tue, 16 Dec 2008 21:54:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Moving-avg-and-windowing-functions/m-p/2199637#M2461</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-12-16T21:54:23Z</dc:date>
    </item>
  </channel>
</rss>

