Subversion Repositories SmartDukaan

Rev

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

import math

def getscore(struct):
    
    score = 0.0
    
    type_score = 0.0
    screen_size_score = 0.0
    screen_resolution_score = 0.0
    number_of_colors_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 "Screen Size=" + `ss`
                
                if  ss >= 5 :
                    screen_size_score = 10

                elif  ss <= 1.5 :
                    screen_size_score = 0

                else :
                    screen_size_score = ((ss**2) - (1.5**2))/((5**2) - (1.5**2))*10
                
        # 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])
                area = height * width
                print "width=" + `width`
                print "height=" + `height`
                
                if  area < 16384 :
                    screen_resolution_score = 0
        
                elif  area >= 409920 :
                    screen_resolution_score = 10
                    
                else :
                    screen_resolution_score = (area - 16384) / (409920 - 16384) * 10
                    
        # 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" :
                    number_of_colors_score = 2
    
                elif nfcs == "256 K" :
                    number_of_colors_score = 6
                
                elif nfcs == "16 M" :
                    number_of_colors_score = 9
                
                elif nfcs == "4 B" :
                    number_of_colors_score = 10
        
        # Type :
        '''
            Super AMOLED   10
            AMOLED         8
            OLED           6
            TFT LCD        6
            CSTN LCD       4
            STN LCD        2
        '''

        if features.has_key("Type") :
            type = features.get("Type")
            print type
            if len(type) > 0 :
                type = type[0]
                #print "Type=" + type
                        
                if type == "Super AMOLED" :
                    type_score = 10
                elif type == "AMOLED" :
                    type_score = 8
                elif type == "OLED" :
                    type_score = 6
                elif type == "TFT LCD" :
                    type_score = 6
                elif type == "CSTN LCD" :
                    type_score = 4
                elif type == "STN LCD" :
                    type_score = 2
   
 
    print "type_score" + str(type_score)
    print "screen_size_score: " + str(screen_size_score)
    print "screen_resolution_score"  + str(screen_resolution_score)
    print "number_of_colors_score" + str(number_of_colors_score)
    
    
    score = (type_score * 30.0 + screen_size_score * 50.0 + screen_resolution_score * 15.0 + number_of_colors_score * 5.0)/100
    return score