Question

Conditional Counters

  • 6 March 2014
  • 2 replies
  • 10 views

Badge
Hi,

 

 

     I have a bunch of datasets passing through a counter. The datasets are grouped by area (region) so that each region gets its own count.  This works and I get a nice count of datasets per region  as they are sorted by date.  1 being the most recent dataset.  The problem is.  There is another attribute of [Catagory] and I need it so that every time [Catagory] = Update, the counter does something to freeze the count on the next record to go through.  So the [Catagory=] Update record gets counted like normal, but the next one to go through after it does not increase in count, as follows:

 

 

Dataset 1 - [Catagory] = [], Count = 1

 

Dataset 2 - [Catagory] = [], Count = 2

 

Dataset 3 - [Catagory] = [], Count = 3

 

Dataset 4 - [Catagory] = [Update], Count = 4

 

Dataset 5 - [Catagory] = [], Count = 4

 

Dataset 6 - [Catagory] = [], Count = 5

 

Dataset 7 - [Catagory] = [Update], Count = 6

 

Dataset 8 - [Catagory] = [], Count = 6

 

 

And so on...

 

 

     My mind is already twisting with the logic I have used in this script and hopefully I have simplified the problem for everyone here and I am sure there is a simple combination of transformers that I have just missed due to my drowning in other intricacies of the existing script.

 

 

Thanks for any help,

2 replies

Badge +2
Rather than the Counter, try variables with a Tester and ExpressionEvaluator. e.g.

 

 

VariableRetriever - Retrieve count

 

NullAttributeReplacer - Is count not set yet? If so, default it to one

 

ExpressionEvaluator - Increment count by one

 

Tester - Is the Categiry = Update? If not use a VariableSetter to set the count.

 

Userlevel 2
Badge +17
# sorry. I misunderstood your question, deleted my previous post.

 

 

Hi,

 

 

Alternatively, you can use the AttributeCreator with "Multiple Feature Attribute Support" option (FME 2013 SP2 or later).

 

 

1) Add an AttributeExposer to expose the count attribute name, i.e. "_count".

 

 

2) Add an AttributeCreator. Parameter settings are:

 

-----

 

Check "Multiple Feature Attribute Support" option.

 

Number of Prior Features: 1

 

If Attribute is Missing, Null, or Empty: Use Other Value

 

Attribute Replacement Value: 0

 

-----

 

Attribute To Set

 

Attribute Name: _count

 

Value: 2 possible values (conditional value setting)

 

If @Value(feature[-1].Catagoly) = Update Then feature[-1]._count

 

Else @Evaluate(@Value(feature[-1]._count)+1)

 

 

Takashi

Reply