Subversion Repositories SmartDukaan

Rev

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

import math

def getscore(struct):
    
    score = 0.0
    
    if struct.has_key("features") :
        features = struct.get("features")
        
        # Screen Size : <=2 - 1, <=2.5 - 2, > 2.5 - 3
        if features.has_key("Screen Size") :
            ss = features.get("Screen Size")
            
            if len(ss) > 0 :
                ss = ss[0]
                ss = float(ss)
                print "ss=" + `ss`
                
                if  ss <= 2 :
                    score += 1

                elif  ss <= 2.5 :
                    score += 2

                elif  ss > 2.5 :
                    score += 3
                
        # Resolution : 320x240 px - 1, 480x360 px - 2
        if features.has_key("Resolution") :
            res = features.get("Resolution")
            
            if len(res) > 1 :
                width = int(res[0])
                height = int(res[1])
                print "width=" + `width`
                print "height=" + `height`
                
                if  width <= 320 :
                    score += 1
        
                elif  width > 320 :
                    score += 2

        # Number of Colors : 64 K - 0.5, 256 K - 1, 16 M - 1.5, 4 B - 2
        if features.has_key("Number of Colors") :
            nfcs = features.get("Number of Colors")
            
            if len(nfcs) > 0 :
                nfcs = nfcs[0]
            
            if nfcs == "64 K" :
                score += 0.5

            elif nfcs == "256 K" :
                score += 1
            
            elif nfcs == "16 M" :
                score += 1.5
            
            elif nfcs == "4 B" :
                score += 2

        # REVISIT
        # Type : TFT - 1, Others - 0.5
        if features.has_key("Type") :
            type = features.get("Type")
            
            if len(type) > 0 :
                type = type[0]
            
            if type == "TFT" :
                score += 1

            else :
                score += 0.5
   
    return int(math.floor(score))