Subversion Repositories SmartDukaan

Rev

Rev 71 | Blame | Last modification | View Log | RSS feed

import math

def getscore(struct):

    score = 0.0
    
    if struct.has_key("features") :
        # REVISIT - Nokia power adaptor should get more points
        # Power Adaptor
    
        # REVISIT - Certain battery types need to be than others
        # Battery Type
        pass
    
    # 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")
                    
                # Capacity > Music Playback : <20 - 0.5, <35 - 1, >35 - 1.5
                if features.has_key("Music Playback") :
                    musicplayback = features.get("Music Playback")
                    musicplayback = int(musicplayback[0])
                    print "musicplayback=" + `musicplayback`
                    
                    if musicplayback < 20 :
                        score = score + 0.5
                            
                    elif musicplayback < 35 :
                          score = score + 1.0

                    elif musicplayback > 35 :
                          score = score + 1.5
  
                # Capacity > Video Playback : <2 - 0.5, <5 - 1, >5 - 1.5 
                if features.has_key("Video Playback") :
                    videoplayback = features.get("Video Playback")
                    videoplayback = int(videoplayback[0])
                    print "videoplayback=" + `videoplayback`
                     
                    if videoplayback < 2 :
                        score = score + 0.5
                            
                    elif videoplayback < 5 :
                          score = score + 1.0

                    elif videoplayback > 5 :
                          score = score + 1.5

                # Capacity > TV Playback : <2 - 0.5, <5 - 1, >5 - 1.5
                if features.has_key("TV Playback") :
                    tvplayback = features.get("TV Playback")
                    tvplayback = int(tvplayback[0])
                    print "tvplayback=" + `tvplayback`

                    if tvplayback < 2 :
                        score = score + 0.5
                            
                    elif tvplayback < 5 :
                          score = score + 1.0

                    elif tvplayback > 5 :
                          score = score + 1.5
    
            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")
                            twog = twog[0]
                            twog = twog.split(" ")
                            twog = int(twog[0])
                            print "twog=" + `twog`
                            
                            if twog < 5 :
                                score = score + 0.5
                            
                            elif twog < 10 :
                                score = score + 1.0

                            elif twog > 10 :
                                score = score + 1.5
                                
                        # Capacity > Talk time > 3G : <5 - 0.5, <10 - 1, >10 - 1.5
                        if features.has_key("3G") :
                            threeg = features.get("3G")
                            threeg = threeg[0]
                            threeg = threeg.split(" ")
                            threeg = int(threeg[0])
                            print "threeg=" + `threeg`

                            if threeg < 5 :
                                score = score + 0.5
                            
                            elif threeg < 10 :
                                score = score + 1.0

                            elif threeg > 10 :
                                score = score + 1.5
                    
                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")
                            twog = twog[0]
                            twog = twog.split(" ")
                            twog = int(twog[0])
                            print "twog=" + `twog`

                            if twog < 10 :
                                score = score + 0.5
                            
                            elif twog < 20 :
                                score = score + 1.0

                            elif twog > 20 :
                                score = score + 1.5
                                
                        # Capacity > Standby time > 3G : <10 - 0.5, <20 - 1, >20 - 1.5
                        if features.has_key("3G") :
                            threeg = features.get("3G")
                            threeg = threeg[0]
                            threeg = threeg.split(" ")
                            threeg = int(threeg[0])
                            print "threeg=" + `threeg`

                            if threeg < 10 :
                                score = score + 0.5
                            
                            elif threeg < 20 :
                                score = score + 1.5

                            elif threeg > 20 :
                                score = score + 1.5
                    
    return int(math.ceil(score))