Subversion Repositories SmartDukaan

Rev

Rev 2655 | Rev 5244 | 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
    
    category = struct.has_key("category")
    max_screen_size = 5
    min_screen_size = 1.5
    max_resolution = 409920
    min_resolution = 16384
    
    if category == "Tablets":
        max_screen_size = 10
        min_screen_size = 5
        max_resolution = 1024000
        min_resolution = 200000
         
    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 >= max_screen_size :
                    screen_size_score = 10

                elif  ss <= min_screen_size :
                    screen_size_score = 0

                else :
                    screen_size_score = ((ss**2) - (min_screen_size**2))/((max_screen_size**2) - (min_screen_size**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 < min_resolution :
                    screen_resolution_score = 0
        
                elif  area >= max_resolution :
                    screen_resolution_score = 10
                    
                else :
                    screen_resolution_score = (area - min_resolution) / (max_resolution - min_resolution) * 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

                if nfcs == "65 K" :
                    number_of_colors_score = 2
    
                elif nfcs == "256 K" :
                    number_of_colors_score = 6

                elif nfcs == "262 K" :
                    number_of_colors_score = 6.5
                                    
                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 Plus" :
                    type_score = 10
                elif type == "Retina Display":
                    type_score = 9.5
                elif type == "Nova Display":
                    type_score = 9                        
                elif type == "Super AMOLED" :
                    type_score = 8.5
                elif type == "Super Clear LCD":
                    type_score = 8.0
                elif type == "Super LCD":
                    type_score = 8.0                   
                elif type == "AMOLED":
                    type_score = 7.5
                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
                
                if category == "Tablets":
                    if type == "TFT LCD" :
                        type_score = 8.5
                    elif type == "Super LCD":
                        type_score = 9.5                   
    
 
 
    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