Subversion Repositories SmartDukaan

Rev

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

import utils

def getscore(struct):
    
    score = 0.0
    storage_capacity_score = 0.0
    rotational_speed_score = 0.0
    optical_drive_score = 0.0
    
    if struct.has_key('childrenslides'):
        childslides = struct.get('childrenslides')
        
        if childslides.has_key('Hard disk drive'):
            hard_disk_drive_slide = childslides.get('Hard disk drive')
            
            if hard_disk_drive_slide.has_key('features'):
                features = hard_disk_drive_slide.get('features')
                
                if features.has_key('Storage capacity'):
                    storage_capacity = float(features.get('Storage capacity')[0])
                    
                    if storage_capacity > 1024.0 and storage_capacity < (1024.0 * 1024.0):
                        storage_capacity = storage_capacity / 1024.0      #MBs to GBs
                    elif storage_capacity > 1024.0 * 1024.0:
                        storage_capacity = storage_capacity / (1024.0 * 1024.0)      #KBs to GBs
                    
                    if storage_capacity <= 250.0:
                        storage_capacity_score = 4.0
                    elif storage_capacity > 640.0:
                        storage_capacity_score = 10.0
                    else:
                        storage_capacity_score = 4.0 + (storage_capacity - 250.0) * 6.0 / 390.0
                    
                if features.has_key('Hard disk rotational speed'):
                    rotational_speed = features.get('Hard disk rotational speed')
                    rotational_speed_score = 5.0 if int(rotational_speed) <= 5400 else 10.0
        
        if childslides.has_key('Optical drive'):
            optical_drive_slide = childslides.get('Optical drive')
            
            if optical_drive_slide.has_key('features'):
                features = optical_drive_slide.get('features')
                
                if features.has_key('Type'):
                    optical_drive_score = 10.0  #TODO: Get the list of optical drive types
        
        score = (70.0 * storage_capacity_score + 10.0 * rotational_speed_score + 20.0 * optical_drive_score) / 100.0
    return score


print "expSlide=" + `expSlide`

struct = utils.contentModel2Struct(expSlide, categoryObj)
print "struct=" + `struct`

score = getscore(struct)