Subversion Repositories SmartDukaan

Rev

Rev 1936 | Rev 2663 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

def getscore(struct):
    
    score = 0.0
    
    weight_score = 0.0
    thickness_score = 0.0
    
    category = struct.has_key("category")
    max_weight = 250
    min_weight = 60
    max_thickness = 20
    min_thickness = 9
    
    if category == "Tablets":
        max_weight = 740
        min_weight = 400
        max_thickness = 13
        min_thickness = 10
        
    if struct.has_key("features") :
        features = struct.get("features")

        # Weight : >250-10, <=60-10, others linear
        if features.has_key("Weight") :
            weight = features.get("Weight")
            
            if len(weight) > 0 :
                weight = float(weight[0])
                print "weight=" + `weight`
                
                if weight > max_weight :
                    weight_score = 0
                
                elif weight <= min_weight :
                    weight_score = 10

                else :
                    weight_score = 10 - (weight - min_weight) / (max_weight - min_weight) * 10
    
        # Size : Thickness <=10-4, <=12-3, <=14-2, >14-1
        if features.has_key("Size") :
            size = features.get("Size")
            
            if len(size) > 2 :
                thickness = float(size[2])
                print "thickness=" + `thickness`
                
                if thickness <= min_thickness :
                    thickness_score = 10
                
                elif thickness > max_thickness :
                    thickness_score = 0

                else :
                    thickness_score = 10 - (thickness - min_thickness) / (max_thickness - max_thickness) * 10
    
    score = (weight_score*50 + thickness_score*50)/100.0
    
    return score