Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

import utils

def getscore(struct):
    
    score = 0.0
    weight_score = 0.0
    size_score = 0.0
    
    if struct.has_key('features'):
        features = struct.get('features')
        
        if features.has_key("Weight"):
            weight = features.get('Weight')
            
            if weight <= 1.5:
                weight_score = 10.0
            elif weight > 1.5 and weight <= 2.5:
                weight_score = 10.0 - (weight - 1.5) * 6
            else:
                weight_score = 4.0
            
        if features.has_key('Size'):
            size = features.get('Size')
            
            if len(size) > 2:
                thickness = float(size[2])
                
                if thickness <= 20.0:
                    size_score = 10.0
                elif thickness > 20.0 and thickness < 40.0:
                    size_score = 10 - (thickness - 20.0) * 6 / 20
                else:
                    size_score = 4.0
        
    score = (60 * weight_score + 40 * size_score) / 100
    return score
    

print "expSlide=" + `expSlide`

struct = utils.contentModel2Struct(expSlide, categoryObj)
print "struct=" + `struct`

score = getscore(struct)