Skip to main content

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

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


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(featuret-1].Value),@Value(Value))

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

 


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.


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(featuret-1].Value),@Value(Value))

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

 

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


Reply