Subversion Repositories SmartDukaan

Rev

Rev 2657 | Go to most recent revision | 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 = 800
    max_battery_capacity = 1800
    
    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 = 1200
            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
            
        if features.has_key("Usage time") :
            usage_time = features.get("Usage time")
            usage_time = usage_time[0]
            usage_time = usage_time.split(" ")
            usage_time = float(usage_time[0])
            if usage_time > 10 :
                usage_time_score = 10
            else:
                usage_time_score = usage_time
                 
    if struct.has_key("childrenslides") :
        childrenslides = struct.get("childrenslides")
        
        if childrenslides.has_key("Capacity") :
            capacity = childrenslides.get("Capacity")
            if capacity.has_key("features") :
                features = capacity.get("features")
                          
            if capacity.has_key("childrenslides") :
                childrenslides = capacity.get("childrenslides")
                
                if childrenslides.has_key("Talk time") :
                    talktime = childrenslides.get("Talk time")
                    
                    if talktime.has_key("features") :
                        features = talktime.get("features")
                        
                        # Capacity > Talk time > 2G : <5 - 0.5, <10 - 1, >10 - 1.5
                        if features.has_key("2G") :
                            twog = features.get("2G")
                            if len(twog) > 0 :
                                twog = twog[0]
                                twog = twog.split(" ")
                                twog = float(twog[0])

                                print "twog=" + `twog`
                                
                                if twog < 3 :
                                    twog_talktime_score = 3.0
                                
                                elif twog >= 15 :
                                    twog_talktime_score = 10.0
    
                                else :
                                    twog_talktime_score = 3 + (twog - 3) / (15 - 3) * 7 
                                
                        # Capacity > Talk time > 3G : <5 - 0.5, <10 - 1, >10 - 1.5
                        if features.has_key("3G") :
                            threeg = features.get("3G")
                            
                            if len(threeg) > 0 :
                                threeg = threeg[0]
                                threeg = threeg.split(" ")
                                threeg = float(threeg[0])
                                print "threeg=" + `threeg`
    
                                if threeg < 2 :
                                    threeg_talktime_score = 3.0
                                
                                elif threeg >= 8 :
                                    threeg_talktime_score = 10.0
    
                                else :
                                    threeg_talktime_score = 3.0 + (threeg - 3) / (8 - 2) * 7.0
                                                            
                if childrenslides.has_key("Standby time") :
                    standbytime = childrenslides.get("Standby time")
                    
                    if standbytime.has_key("features") :
                        features = standbytime.get("features")
                        
                        # Capacity > Standby time > 2G : <10 - 0.5, <20 - 1, >20 - 1.5
                        if features.has_key("2G") :
                            twog = features.get("2G")

                            if len(twog) > 0 :
                                twog = twog[0]
                                twog = twog.split(" ")
                                twog = float(twog[0])

                                print "twog=" + `twog`
                                
                                if twog < 5 :
                                    twog_standbytime_score = 2.0
                                
                                elif twog >= 30 :
                                    twog_standbytime_score = 10.0
    
                                else :
                                    twog_standbytime_score = 2 + (twog - 5) / (30 - 5) * 8 
                                    
                        # Capacity > Standby time > 3G : <10 - 0.5, <20 - 1, >20 - 1.5
                        if features.has_key("3G") :
                            threeg = features.get("3G")
                            
                            if len(threeg) > 0 :
                                threeg = threeg[0]
                                threeg = threeg.split(" ")
                                threeg = float(threeg[0])
                                print "threeg=" + `threeg`
    
                                if threeg < 5 :
                                    threeg_standbytime_score = 2.0 
                                
                                elif threeg >= 30 :
                                    threeg_standbytime_score = 10.0
    
                                else :
                                    threeg_standbytime_score = 2 +  (threeg - 5) / (30 - 5) * 8

    print "battery_type_score" + `battery_type_score`
    print "twog_talktime_score" + `twog_talktime_score`
    print "threeg_talktime_score" + `threeg_talktime_score`
    print "twog_standbytime_score" + `twog_standbytime_score`
    print "threeg_standbytime_score" + `threeg_standbytime_score`

    if category == "Tablets":
        score = (100*battery_type_score)/100.0
    elif usage_time_score != 0:
        score = (40*battery_type_score + 60*usage_time_score)/100
    elif threeg_talktime_score == 0:
        score = (40*battery_type_score + 30*twog_talktime_score + 30*twog_standbytime_score )/100
    else :
        score = (40*battery_type_score + 20*twog_talktime_score + 10*threeg_talktime_score + 20*twog_standbytime_score + 10*threeg_standbytime_score)/100
    return score