Subversion Repositories SmartDukaan

Rev

Rev 2657 | Blame | Compare with Previous | Last modification | View Log | RSS feed

import math

def getscore(struct) :
    score = 0.0
    resolution_score = 0.0
    flash_score = 0.0
    image_formats_score = 0.0
    secondary_camera_score = 0.0
    additional_camera_features_score = 0.0

    if struct.has_key("features") :
        features = struct.get("features")
        
        if features.has_key("Front camera") :
            resolution = features.get("Back camera") 
            if len(resolution) > 0 :
                resolution = float(resolution[0])
                print "resolution=" + `resolution`
                
                if resolution <= 1.0 :
                    resolution_score = 2.0
                    
                elif resolution >= 8 :
                    resolution_score = 10.0
                    
                else :
                    resolution_score = 2.0 + (resolution - 1.0) / (8 - 1.0) * (10 - 2)

        if features.has_key("Flash") :
            flash = features.get("Flash")
            if len(flash) > 0 :
                flash = flash[0]
                print "flash=" + `flash`
                
                
                if flash == "LED" :
                    print "Value is LED"
                    flash_score = 6.0
                    
                elif flash == "Xenon" :
                    flash_score = 8.0
                    
                elif flash == "Dual-LED" :
                    flash_score = 9.0 
    
        if features.has_key("Image formats") :
            image_formats = features.get("Image formats")
            print "image_formats=" + `image_formats`
            
            # Still Image Formats : count <=2 - 0.5, >2 - 1
            if len(image_formats) == 1 :
                image_formats_score = 6.0
            
            elif len(image_formats) == 2 :
                image_formats_score = 8.0
            
            elif len(image_formats) >= 3 :
                image_formats_score = 10.0
            
        if features.has_key("Additional camera features") :
            additional_camera_features = features.get("Additional camera features")
            if len(additional_camera_features) > 10 :
                additional_camera_features_score = 10.0
            else:
                additional_camera_features_score = len(additional_camera_features) 
    
        if features.has_key("Front camera") :
            secondary_camera_score = 10.0

        print "resolution_score" + `resolution_score`
        print "flash_score" + `flash_score`
        print "image_formats_score" + `image_formats_score`
        print "secondary_camera_score" +  `secondary_camera_score`
        print "additional_camera_features_score" + `additional_camera_features_score`
            
        score = (40*resolution_score + 20*flash_score + 20*image_formats_score + 10*secondary_camera_score + 10*additional_camera_features_score) / 100

    return score