Subversion Repositories SmartDukaan

Rev

Rev 1362 | Rev 2454 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1362 Rev 1915
Line 1... Line 1...
1
import math
1
import math
2
 
2
 
3
def getscore(struct):
3
def getscore(struct):
4
 
4
 
5
    score = 0.0
5
    score = 0.0
-
 
6
    battery_type_score = 0.0
-
 
7
    twog_talktime_score = 0.0
-
 
8
    threeg_talktime_score = 0.0
-
 
9
    twog_standbytime_score = 0.0
-
 
10
    threeg_standbytime_score = 0.0
-
 
11
    
6
    
12
    
7
    if struct.has_key("features") :
13
    if struct.has_key("features") :
-
 
14
        features = struct.get("features")
8
        # REVISIT - Nokia power adaptor should get more points
15
        # REVISIT - Nokia power adaptor should get more points
9
        # Power Adaptor
16
        # Power Adaptor
10
    
17
    
11
        # REVISIT - Certain battery types need to be than others
18
        # REVISIT - Certain battery types need to be than others
12
        # Battery Type
19
        # Battery Type
-
 
20
        battery_capacity = 0.0
-
 
21
        last = "0"
-
 
22
        battery_type = features.get("Battery type")
-
 
23
        battery_type = battery_type[0]
-
 
24
        battery_type = battery_type.split(" ")
-
 
25
        print "*****"
-
 
26
        print battery_type
-
 
27
        for part in battery_type:
-
 
28
            if part.find("mAh") > -1:
-
 
29
                try:
-
 
30
                    battery_capacity = float(last)
-
 
31
                except:
-
 
32
                    battery_capacity = 1200
-
 
33
            print `last`
-
 
34
            last = part
13
        pass
35
            
-
 
36
        print "battery_capacity" + `battery_capacity`
-
 
37
        if battery_capacity < 800 :
-
 
38
            battery_type_score = 3
-
 
39
        elif battery_capacity > 1800 :
-
 
40
            battery_type_score = 10
-
 
41
        else :
-
 
42
            battery_type_score = (battery_capacity - 800)/(1800-800)*7.0
-
 
43
            battery_type_score = battery_type_score + 3.0
14
    
44
            
15
    # Max will be 1.5 * 7 = ceil(10.5) = 10 
45
    # Max will be 1.5 * 7 = ceil(10.5) = 10 
16
    if struct.has_key("childrenslides") :
46
    if struct.has_key("childrenslides") :
17
        childrenslides = struct.get("childrenslides")
47
        childrenslides = struct.get("childrenslides")
18
        
48
        
19
        if childrenslides.has_key("Capacity") :
49
        if childrenslides.has_key("Capacity") :
20
            capacity = childrenslides.get("Capacity")
50
            capacity = childrenslides.get("Capacity")
21
            if capacity.has_key("features") :
51
            if capacity.has_key("features") :
22
                features = capacity.get("features")
52
                features = capacity.get("features")
23
                    
-
 
24
                # Capacity > Music Playback : <20 - 0.5, <35 - 1, >35 - 1.5
-
 
25
                if features.has_key("Music Playback") :
-
 
26
                    musicplayback = features.get("Music Playback")
-
 
27
                    
-
 
28
                    if len(musicplayback) > 0 :
-
 
29
                        musicplayback = int(musicplayback[0])
-
 
30
                        print "musicplayback=" + `musicplayback`
-
 
31
                        
-
 
32
                        if musicplayback < 20 :
-
 
33
                            score = score + 0.5
-
 
34
                                
-
 
35
                        elif musicplayback < 35 :
-
 
36
                              score = score + 1.0
-
 
37
    
-
 
38
                        elif musicplayback > 35 :
-
 
39
                              score = score + 1.5
-
 
40
  
-
 
41
                # Capacity > Video Playback : <2 - 0.5, <5 - 1, >5 - 1.5 
-
 
42
                if features.has_key("Video Playback") :
-
 
43
                    videoplayback = features.get("Video Playback")
-
 
44
                    
-
 
45
                    if len(videoplayback) > 0 :
-
 
46
                        videoplayback = int(videoplayback[0])
-
 
47
                        print "videoplayback=" + `videoplayback`
-
 
48
                         
53
                          
49
                        if videoplayback < 2 :
-
 
50
                            score = score + 0.5
-
 
51
                                
-
 
52
                        elif videoplayback < 5 :
-
 
53
                              score = score + 1.0
-
 
54
    
-
 
55
                        elif videoplayback > 5 :
-
 
56
                              score = score + 1.5
-
 
57
 
-
 
58
                # Capacity > TV Playback : <2 - 0.5, <5 - 1, >5 - 1.5
-
 
59
                if features.has_key("TV Playback") :
-
 
60
                    tvplayback = features.get("TV Playback")
-
 
61
                    
-
 
62
                    if len(tvplayback) > 0 :
-
 
63
                        tvplayback = int(tvplayback[0])
-
 
64
                        print "tvplayback=" + `tvplayback`
-
 
65
    
-
 
66
                        if tvplayback < 2 :
-
 
67
                            score = score + 0.5
-
 
68
                                
-
 
69
                        elif tvplayback < 5 :
-
 
70
                              score = score + 1.0
-
 
71
    
-
 
72
                        elif tvplayback > 5 :
-
 
73
                              score = score + 1.5
-
 
74
        
-
 
75
            if capacity.has_key("childrenslides") :
54
            if capacity.has_key("childrenslides") :
76
                childrenslides = capacity.get("childrenslides")
55
                childrenslides = capacity.get("childrenslides")
77
                
56
                
78
                if childrenslides.has_key("Talk time") :
57
                if childrenslides.has_key("Talk time") :
79
                    talktime = childrenslides.get("Talk time")
58
                    talktime = childrenslides.get("Talk time")
Line 85... Line 64...
85
                        if features.has_key("2G") :
64
                        if features.has_key("2G") :
86
                            twog = features.get("2G")
65
                            twog = features.get("2G")
87
                            if len(twog) > 0 :
66
                            if len(twog) > 0 :
88
                                twog = twog[0]
67
                                twog = twog[0]
89
                                twog = twog.split(" ")
68
                                twog = twog.split(" ")
90
                                try:
-
 
91
                                    twog = float(twog[0])
69
                                twog = float(twog[0])
92
                                except:
-
 
93
                                    twog = 5
-
 
-
 
70
 
94
                                print "twog=" + `twog`
71
                                print "twog=" + `twog`
95
                                
72
                                
96
                                if twog < 5 :
73
                                if twog < 3 :
97
                                    score = score + 0.5
74
                                    twog_talktime_score = 3.0
98
                                
75
                                
99
                                elif twog < 10 :
76
                                elif twog >= 15 :
100
                                    score = score + 1.0
77
                                    twog_talktime_score = 10.0
101
    
78
    
102
                                elif twog > 10 :
79
                                else :
103
                                    score = score + 1.5
80
                                    twog_talktime_score = 3 + (twog - 3) / (15 - 3) * 7 
104
                                
81
                                
105
                        # Capacity > Talk time > 3G : <5 - 0.5, <10 - 1, >10 - 1.5
82
                        # Capacity > Talk time > 3G : <5 - 0.5, <10 - 1, >10 - 1.5
106
                        if features.has_key("3G") :
83
                        if features.has_key("3G") :
107
                            threeg = features.get("3G")
84
                            threeg = features.get("3G")
108
                            
85
                            
Line 110... Line 87...
110
                                threeg = threeg[0]
87
                                threeg = threeg[0]
111
                                threeg = threeg.split(" ")
88
                                threeg = threeg.split(" ")
112
                                threeg = float(threeg[0])
89
                                threeg = float(threeg[0])
113
                                print "threeg=" + `threeg`
90
                                print "threeg=" + `threeg`
114
    
91
    
115
                                if threeg < 5 :
92
                                if threeg < 2 :
116
                                    score = score + 0.5
93
                                    threeg_talktime_score = 3.0
117
                                
94
                                
118
                                elif threeg < 10 :
95
                                elif threeg >= 8 :
119
                                    score = score + 1.0
96
                                    threeg_talktime_score = 10.0
120
    
97
    
121
                                elif threeg > 10 :
98
                                else :
122
                                    score = score + 1.5
99
                                    threeg_talktime_score = 3.0 + (threeg - 3) / (8 - 2) * 7.0
123
                        
100
                                                            
124
                if childrenslides.has_key("Standby time") :
101
                if childrenslides.has_key("Standby time") :
125
                    standbytime = childrenslides.get("Standby time")
102
                    standbytime = childrenslides.get("Standby time")
126
                    
103
                    
127
                    if standbytime.has_key("features") :
104
                    if standbytime.has_key("features") :
128
                        features = standbytime.get("features")
105
                        features = standbytime.get("features")
129
                        
106
                        
130
                        # Capacity > Standby time > 2G : <10 - 0.5, <20 - 1, >20 - 1.5
107
                        # Capacity > Standby time > 2G : <10 - 0.5, <20 - 1, >20 - 1.5
131
                        if features.has_key("2G") :
108
                        if features.has_key("2G") :
132
                            twog = features.get("2G")
109
                            twog = features.get("2G")
133
                            
-
 
-
 
110
 
134
                            if len(twog) > 0 :
111
                            if len(twog) > 0 :
135
                                twog = twog[0]
112
                                twog = twog[0]
136
                                twog = twog.split(" ")
113
                                twog = twog.split(" ")
137
                                try:
-
 
138
                                    twog = float(twog[0])
114
                                twog = float(twog[0])
139
                                except:
-
 
140
                                    twog = 5
-
 
-
 
115
 
141
                                print "twog=" + `twog`
116
                                print "twog=" + `twog`
142
    
-
 
143
                                if twog < 10 :
-
 
144
                                    score = score + 0.5
-
 
145
                                
117
                                
-
 
118
                                if twog < 5 :
-
 
119
                                    twog_standbytime_score = 2.0
-
 
120
                                
146
                                elif twog < 20 :
121
                                elif twog >= 30 :
147
                                    score = score + 1.0
122
                                    twog_standbytime_score = 10.0
148
    
123
    
149
                                elif twog > 20 :
124
                                else :
150
                                    score = score + 1.5
125
                                    twog_standbytime_score = 2 + (twog - 5) / (30 - 5) * 8 
151
                                    
126
                                    
152
                        # Capacity > Standby time > 3G : <10 - 0.5, <20 - 1, >20 - 1.5
127
                        # Capacity > Standby time > 3G : <10 - 0.5, <20 - 1, >20 - 1.5
153
                        if features.has_key("3G") :
128
                        if features.has_key("3G") :
154
                            threeg = features.get("3G")
129
                            threeg = features.get("3G")
155
                            
130
                            
Line 157... Line 132...
157
                                threeg = threeg[0]
132
                                threeg = threeg[0]
158
                                threeg = threeg.split(" ")
133
                                threeg = threeg.split(" ")
159
                                threeg = float(threeg[0])
134
                                threeg = float(threeg[0])
160
                                print "threeg=" + `threeg`
135
                                print "threeg=" + `threeg`
161
    
136
    
162
                                if threeg < 10 :
137
                                if threeg < 5 :
163
                                    score = score + 0.5
138
                                    threeg_standbytime_score = 2.0 
164
                                
139
                                
165
                                elif threeg < 20 :
140
                                elif threeg >= 30 :
166
                                    score = score + 1.5
141
                                    threeg_standbytime_score = 10.0
167
    
142
    
168
                                elif threeg > 20 :
-
 
169
                                    score = score + 1.5
-
 
170
                        
-
 
171
    return int(math.floor(score))
-
 
172
143
                                else :
-
 
144
                                    threeg_standbytime_score = 2 +  (threeg - 5) / (30 - 5) * 8
-
 
145
 
-
 
146
    print "battery_type_score" + `battery_type_score`
-
 
147
    print "twog_talktime_score" + `twog_talktime_score`
-
 
148
    print "threeg_talktime_score" + `threeg_talktime_score`
-
 
149
    print "twog_standbytime_score" + `twog_standbytime_score`
-
 
150
    print "threeg_standbytime_score" + `threeg_standbytime_score`
-
 
151
 
-
 
152
                
-
 
153
    if threeg_talktime_score == 0:
-
 
154
        score = (40*battery_type_score + 30*twog_talktime_score + 30*twog_standbytime_score )/100
-
 
155
    else :
-
 
156
        score = (40*battery_type_score + 20*twog_talktime_score + 10*threeg_talktime_score + 20*twog_standbytime_score + 10*threeg_standbytime_score)/100
-
 
157
    return score
-
 
158
173
159