Subversion Repositories SmartDukaan

Rev

Rev 71 | Blame | Last modification | View Log | RSS feed

import math

def getscore(struct) :
    score = 0.0

    if struct.has_key("features") :
        features = struct.get("features")
        
        if features.has_key("Resolution") :
            resolution = features.get("Resolution") 
            if len(resolution) > 0 :
                resolution = float(resolution[0])
                print "resolution=" + `resolution`
                
                # Resolution : <=2 - 1, <=3 - 2, >3 - 3
                if resolution <= 2 :
                    score = score + 1
                    
                elif resolution <= 3 :
                    score = score + 2
                    
                elif resolution > 3 :
                    score = score + 3

        if features.has_key("Flash") :
            flash = features.get("Flash")
            if len(flash) > 0 :
                flash = flash[0]
                print "flash=" + `flash`
                
                # Flash : LED - 0.5, Dual-LED - 1.0
                if flash == "LED" :
                    print "Value is LED"
                    score = score + 0.5
                    
                elif flash == "Dual-LED" :
                    score = score + 1
    
        if features.has_key("Still Image Formats") :
            siformats = features.get("Still Image Formats")
            print "siformats=" + `siformats`
            
            # Still Image Formats : count <=2 - 0.5, >2 - 1
            if len(siformats) <= 2 :
                score = score + 0.5
            
            elif len(siformats) > 2 :
                score = score + 1
            
        if features.has_key("Additional Camera features") :
            # Additional Camera features : 1, 0
            score = score + 1
    
    if struct.has_key("childrenslides") :
        childrenslides = struct.get("childrenslides")

        if childrenslides.has_key("Number of Cameras") :
            nfcs = childrenslides.get("Number of Cameras")
            if nfcs.has_key("features") :
                features = nfcs.get("features")
                
                # Number of Cameras > Primary camera : 1, 0
                if features.has_key("Primary camera") :
                    score = score + 1
    
                # Number of Cameras > Secondary camera : 1, 0
                if features.has_key("Secondary camera") :
                    score = score + 1

    return int(math.floor(score))