Subversion Repositories SmartDukaan

Rev

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

import math

def getscore(struct):

    score = 0.0
    battery_type_score = 0.0
    twog_talktime_score = 0.0
    threeg_talktime_score = 0.0
    twog_standbytime_score = 0.0
    threeg_standbytime_score = 0.0
    usage_time_score = 0.0

    category = struct.get("category")    
    
    min_battery_capacity = 500
    max_battery_capacity = 3000
    
    if category == "Tablets":
        min_battery_capacity = 1000
        max_battery_capacity = 5000
        
    if struct.has_key("features") :
        features = struct.get("features")
        
        battery_capacity = 0.0
        last = "0"
        battery_type = features.get("Battery type")
        battery_type = battery_type[0]
        battery_type = battery_type.split(" ")

        print battery_type
        for part in battery_type:
            if part.find("mAh") > -1:
                try:
                    battery_capacity = float(last)
                except:
                    battery_capacity = 1600
            print `last`
            last = part
            
        print "battery_capacity" + `battery_capacity`
        if battery_capacity < min_battery_capacity :
            battery_type_score = 3
        elif battery_capacity > max_battery_capacity :
            battery_type_score = 10
        else :
            battery_type_score = (battery_capacity - min_battery_capacity)/(max_battery_capacity-min_battery_capacity)*7.0
            battery_type_score = battery_type_score + 3.0
            


    score = (100*battery_type_score)/100.0
    return score