Skip to main content
Solved

Calculating moving average (3 rolling points) in FME.

  • September 20, 2023
  • 4 replies
  • 146 views

Forum|alt.badge.img

Hello,

I have a dataset with 1000 categories (A, B, ...) (please see the following sample). For each category I want to calculate 3 points moving averages. Table 1I developed the following workbench that using a Tester filter data for each category and then calculating the 3 points moving averages for one category (here port A). However, for each port of the Tester I should repeat all transformers again (transformer after the Tester), which is difficult for 1000 categories. I created a custom transformer but again I should import the custom transformer 1000 times. In the custom transformer I used a Counter which for each port should start counting from zero. But it is added up after that it is applied for each port. I set the Count Space of the Counter on local. But still didn't work. Can someone please let me know a better way to calculate this moving averages without those all repetitions of transformer. FYI, I am using FME 2022.

image

Best answer by jkh

virtualcitymatt wrote:

You should be able to do this in just an AttributeCreator.

 

Inside the AttributeCreate you can enable "Adjacent Feature Attributes" which can let you look back a a given number of features.

 

Here's an example:

 

image

Essentially the logic is as follows:

 

If the category in the current feature matches the previous category and the one 2 behind then calculate the average of the 3 features. If the catagory does not match then do nothing (which leave ave_3 empty)

 

image

Hi @virtualcitymatt thank you so much for the answer and for your great explanation about the logic behind the transformer.

View original
Did this help you find an answer to your question?

4 replies

virtualcitymatt
Celebrity
Forum|alt.badge.img+35

You should be able to do this in just an AttributeCreator.

 

Inside the AttributeCreate you can enable "Adjacent Feature Attributes" which can let you look back a a given number of features.

 

Here's an example:

 

image

Essentially the logic is as follows:

 

If the category in the current feature matches the previous category and the one 2 behind then calculate the average of the 3 features. If the catagory does not match then do nothing (which leave ave_3 empty)

 

image


nielsgerrits
VIP
Forum|alt.badge.img+54

You are looking for Adjacent Feature Attributes in the AttributeCreator. Then you can do it as it is done in Excel. Attached sample workspace demonstrating this.

If 
Category = feature[-2].Category 
then 
@average(@Value(feature[-2].Value),@Value(feature[-1].Value),@Value(Value))

RollingAverage3Sample(2021)_1RollingAverage3Sample(2021)_2RollingAverage3Sample(2021)_3 

 


Forum|alt.badge.img
  • Author
  • Best Answer
  • September 20, 2023
virtualcitymatt wrote:

You should be able to do this in just an AttributeCreator.

 

Inside the AttributeCreate you can enable "Adjacent Feature Attributes" which can let you look back a a given number of features.

 

Here's an example:

 

image

Essentially the logic is as follows:

 

If the category in the current feature matches the previous category and the one 2 behind then calculate the average of the 3 features. If the catagory does not match then do nothing (which leave ave_3 empty)

 

image

Hi @virtualcitymatt thank you so much for the answer and for your great explanation about the logic behind the transformer.


Forum|alt.badge.img
  • Author
  • September 20, 2023
nielsgerrits wrote:

You are looking for Adjacent Feature Attributes in the AttributeCreator. Then you can do it as it is done in Excel. Attached sample workspace demonstrating this.

If 
Category = feature[-2].Category 
then 
@average(@Value(feature[-2].Value),@Value(feature[-1].Value),@Value(Value))

RollingAverage3Sample(2021)_1RollingAverage3Sample(2021)_2RollingAverage3Sample(2021)_3 

 

Hi @nielsgerrits thank you so much. This is a great answer. 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings