Skip to main content

Hi,

I'm trying to find a transformer that's able to create a new attribute, check my data for different conditions based on values from multiple different attributes, and subsequently add to the value of the newly created attribute WHILE these conditions hold true. Something like an "overall score attribute".

I put while in caps because with the attribute creator there are only "if" statements. I'm not a programmer, but I know that with if statements, as soon as one holds true, the scripts stops. That is what seems to happen with the attribute creator transformer that I have been using. I could be mistaken of course. Like I said, I'm not a programmer.

However, I don't want that. I want the program to keep checking all conditions and adding to the "score attribute". How do I do that?

So basically something like this:

if/while attribute1 >= 10, add 1 to new overall score attribute

if/while attribute 1 < 10, add 2 to new overall score attribute

if while attribute 2= yes, add 3 to new overall score attribute

if/while attribute 4 is missing, add 4 to new overall score

etc

It may be easier to do this as a two step process.

If I've understood this correctly you have a feature with several attributes and you want to give a score based on the value of these attributes. Something like this

I would create intermediate attributes that assign a numeric value for each attribute you are testing based on the value and then sum this at the end


It may be easier to do this as a two step process.

If I've understood this correctly you have a feature with several attributes and you want to give a score based on the value of these attributes. Something like this

I would create intermediate attributes that assign a numeric value for each attribute you are testing based on the value and then sum this at the end

I thought about adding multiple attribute creators, but I have to check for a lot of conditions. That will make my workbench really large. I've edited my question to clarify what I meant.

 

 


Hi @fmenco, if I understand the requirement correctly, you can do that with just setting multiple conditional values in an AttributeCreator like this.


Hi @fmenco, if I understand the requirement correctly, you can do that with just setting multiple conditional values in an AttributeCreator like this.

@takashi This will add the total score per feature. Follow up with the StatisticsCalculater to sum the score for the overall dataset.

 


And the Python Caller answer when Attributes to expose is FinalScore:

import fme
import fmeobjects

class FeatureProcessor(object):
    def __init__(self):
        pass
    def input(self,feature):
        # get all your Attributes
        attribute1 = feature.getAttribute('attribute1')
        attribute2 = feature.getAttribute('attribute2')
        attribute3 = feature.getAttribute('attribute3')
        attribute4 = feature.getAttribute('attribute4')
        
        #create your finalScore 
        finalScore = 0
        
        #if/while attribute1 >= 10, add 1 to new overall score attribute
        if attribute1 >= 10:
            finalScore = finalScore + 1
            
        #if/while attribute 1 < 10, add 2 to new overall score attribute    
        else:
            finalScore = finalScore + 2
            
        #if while attribute 2= yes, add 3 to new overall score attribute    
        if attribute2 == "yes":
            finalScore = finalScore + 3
            
        # if/while attribute 4 is missing, add 4 to new overall score    
        if not attribute4:
            finalScore = finalScore + 4
            
        feature.setAttribute('FinalScore', finalScore)
        self.pyoutput(feature)
    def close(self):
        pass

You may have a bit of fun with yes being true or 1 but this would be a great way of learning python in FME

With a combination of If else or If, elif, else you can do anything you like really.

# if attribute1 is less than 5?
if attribute1  < 5:
finalScore = finalScore + 1
#if not then is it less than 10?
elif attribute1  < 10:
finalScore = finalScore + 2
# if false both statements then do this instead
else:
finalScore = finalScore + 3


I thought about adding multiple attribute creators, but I have to check for a lot of conditions. That will make my workbench really large. I've edited my question to clarify what I meant.

 

 

You should just need one attribute creator creating multiple attributes, so an attribute e.g. Test1 which is set with your first test, Test 2 which is set with your second test etc. all in the same attribute creator

 

 

Then a final attribute creator where score = test1 + test2 + test3 etc.

 

 


Reply