Subversion Repositories SmartDukaan

Rev

Rev 1362 | Rev 2556 | 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
    
    
    if struct.has_key("features") :
        features = struct.get("features")
        # REVISIT - Nokia power adaptor should get more points
        # Power Adaptor
    
        # REVISIT - Certain battery types need to be than others
        # Battery Type
        battery_capacity = 0.0
        last = "0"
        battery_type = features.get("Battery type")
        battery_type = battery_type[0]
        battery_type = battery_type.split(" ")
        print "*****"
        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 < 800 :
            battery_type_score = 3
        elif battery_capacity > 1800 :
            battery_type_score = 10
        else :
            battery_type_score = (battery_capacity - 800)/(1800-800)*7.0
            battery_type_score = battery_type_score + 3.0
            
    # Max will be 1.5 * 7 = ceil(10.5) = 10 
    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 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