| 75 |
naveen |
1 |
import math
|
|
|
2 |
|
| 71 |
naveen |
3 |
def getscore(struct):
|
| 75 |
naveen |
4 |
|
|
|
5 |
score = 0.0
|
| 1915 |
rajveer |
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
|
| 2454 |
rajveer |
11 |
usage_time_score = 0.0
|
| 75 |
naveen |
12 |
|
|
|
13 |
if struct.has_key("features") :
|
| 1915 |
rajveer |
14 |
features = struct.get("features")
|
| 75 |
naveen |
15 |
# REVISIT - Nokia power adaptor should get more points
|
|
|
16 |
# Power Adaptor
|
|
|
17 |
|
|
|
18 |
# REVISIT - Certain battery types need to be than others
|
|
|
19 |
# Battery Type
|
| 1915 |
rajveer |
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(" ")
|
| 2454 |
rajveer |
25 |
|
| 1915 |
rajveer |
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
|
|
|
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
|
|
|
44 |
|
| 2454 |
rajveer |
45 |
if features.has_key("Usage time") :
|
|
|
46 |
usage_time = features.get("Usage time")
|
|
|
47 |
usage_time = usage_time[0]
|
|
|
48 |
usage_time = usage_time.split(" ")
|
|
|
49 |
usage_time = float(usage_time[0])
|
|
|
50 |
if usage_time > 10 :
|
|
|
51 |
usage_time_score = 10
|
|
|
52 |
else:
|
|
|
53 |
usage_time_score = usage_time
|
|
|
54 |
|
| 75 |
naveen |
55 |
# Max will be 1.5 * 7 = ceil(10.5) = 10
|
|
|
56 |
if struct.has_key("childrenslides") :
|
|
|
57 |
childrenslides = struct.get("childrenslides")
|
|
|
58 |
|
|
|
59 |
if childrenslides.has_key("Capacity") :
|
|
|
60 |
capacity = childrenslides.get("Capacity")
|
|
|
61 |
if capacity.has_key("features") :
|
|
|
62 |
features = capacity.get("features")
|
| 1915 |
rajveer |
63 |
|
| 75 |
naveen |
64 |
if capacity.has_key("childrenslides") :
|
|
|
65 |
childrenslides = capacity.get("childrenslides")
|
|
|
66 |
|
|
|
67 |
if childrenslides.has_key("Talk time") :
|
|
|
68 |
talktime = childrenslides.get("Talk time")
|
|
|
69 |
|
|
|
70 |
if talktime.has_key("features") :
|
|
|
71 |
features = talktime.get("features")
|
|
|
72 |
|
|
|
73 |
# Capacity > Talk time > 2G : <5 - 0.5, <10 - 1, >10 - 1.5
|
|
|
74 |
if features.has_key("2G") :
|
|
|
75 |
twog = features.get("2G")
|
| 76 |
naveen |
76 |
if len(twog) > 0 :
|
|
|
77 |
twog = twog[0]
|
|
|
78 |
twog = twog.split(" ")
|
| 1915 |
rajveer |
79 |
twog = float(twog[0])
|
|
|
80 |
|
| 76 |
naveen |
81 |
print "twog=" + `twog`
|
| 75 |
naveen |
82 |
|
| 1915 |
rajveer |
83 |
if twog < 3 :
|
|
|
84 |
twog_talktime_score = 3.0
|
| 76 |
naveen |
85 |
|
| 1915 |
rajveer |
86 |
elif twog >= 15 :
|
|
|
87 |
twog_talktime_score = 10.0
|
| 76 |
naveen |
88 |
|
| 1915 |
rajveer |
89 |
else :
|
|
|
90 |
twog_talktime_score = 3 + (twog - 3) / (15 - 3) * 7
|
| 76 |
naveen |
91 |
|
| 75 |
naveen |
92 |
# Capacity > Talk time > 3G : <5 - 0.5, <10 - 1, >10 - 1.5
|
|
|
93 |
if features.has_key("3G") :
|
|
|
94 |
threeg = features.get("3G")
|
|
|
95 |
|
| 76 |
naveen |
96 |
if len(threeg) > 0 :
|
|
|
97 |
threeg = threeg[0]
|
|
|
98 |
threeg = threeg.split(" ")
|
| 1362 |
rajveer |
99 |
threeg = float(threeg[0])
|
| 76 |
naveen |
100 |
print "threeg=" + `threeg`
|
|
|
101 |
|
| 1915 |
rajveer |
102 |
if threeg < 2 :
|
|
|
103 |
threeg_talktime_score = 3.0
|
| 76 |
naveen |
104 |
|
| 1915 |
rajveer |
105 |
elif threeg >= 8 :
|
|
|
106 |
threeg_talktime_score = 10.0
|
| 76 |
naveen |
107 |
|
| 1915 |
rajveer |
108 |
else :
|
|
|
109 |
threeg_talktime_score = 3.0 + (threeg - 3) / (8 - 2) * 7.0
|
|
|
110 |
|
| 75 |
naveen |
111 |
if childrenslides.has_key("Standby time") :
|
|
|
112 |
standbytime = childrenslides.get("Standby time")
|
|
|
113 |
|
|
|
114 |
if standbytime.has_key("features") :
|
|
|
115 |
features = standbytime.get("features")
|
|
|
116 |
|
|
|
117 |
# Capacity > Standby time > 2G : <10 - 0.5, <20 - 1, >20 - 1.5
|
|
|
118 |
if features.has_key("2G") :
|
|
|
119 |
twog = features.get("2G")
|
| 1915 |
rajveer |
120 |
|
| 76 |
naveen |
121 |
if len(twog) > 0 :
|
|
|
122 |
twog = twog[0]
|
|
|
123 |
twog = twog.split(" ")
|
| 1915 |
rajveer |
124 |
twog = float(twog[0])
|
|
|
125 |
|
| 76 |
naveen |
126 |
print "twog=" + `twog`
|
| 75 |
naveen |
127 |
|
| 1915 |
rajveer |
128 |
if twog < 5 :
|
|
|
129 |
twog_standbytime_score = 2.0
|
|
|
130 |
|
|
|
131 |
elif twog >= 30 :
|
|
|
132 |
twog_standbytime_score = 10.0
|
| 76 |
naveen |
133 |
|
| 1915 |
rajveer |
134 |
else :
|
|
|
135 |
twog_standbytime_score = 2 + (twog - 5) / (30 - 5) * 8
|
| 76 |
naveen |
136 |
|
| 75 |
naveen |
137 |
# Capacity > Standby time > 3G : <10 - 0.5, <20 - 1, >20 - 1.5
|
|
|
138 |
if features.has_key("3G") :
|
|
|
139 |
threeg = features.get("3G")
|
|
|
140 |
|
| 76 |
naveen |
141 |
if len(threeg) > 0 :
|
|
|
142 |
threeg = threeg[0]
|
|
|
143 |
threeg = threeg.split(" ")
|
| 1362 |
rajveer |
144 |
threeg = float(threeg[0])
|
| 76 |
naveen |
145 |
print "threeg=" + `threeg`
|
|
|
146 |
|
| 1915 |
rajveer |
147 |
if threeg < 5 :
|
|
|
148 |
threeg_standbytime_score = 2.0
|
| 76 |
naveen |
149 |
|
| 1915 |
rajveer |
150 |
elif threeg >= 30 :
|
|
|
151 |
threeg_standbytime_score = 10.0
|
| 76 |
naveen |
152 |
|
| 1915 |
rajveer |
153 |
else :
|
|
|
154 |
threeg_standbytime_score = 2 + (threeg - 5) / (30 - 5) * 8
|
|
|
155 |
|
|
|
156 |
print "battery_type_score" + `battery_type_score`
|
|
|
157 |
print "twog_talktime_score" + `twog_talktime_score`
|
|
|
158 |
print "threeg_talktime_score" + `threeg_talktime_score`
|
|
|
159 |
print "twog_standbytime_score" + `twog_standbytime_score`
|
|
|
160 |
print "threeg_standbytime_score" + `threeg_standbytime_score`
|
|
|
161 |
|
| 2454 |
rajveer |
162 |
if usage_time_score != 0:
|
|
|
163 |
score = (40*battery_type_score + 60*usage_time_score)
|
|
|
164 |
elif threeg_talktime_score == 0:
|
| 1915 |
rajveer |
165 |
score = (40*battery_type_score + 30*twog_talktime_score + 30*twog_standbytime_score )/100
|
|
|
166 |
else :
|
|
|
167 |
score = (40*battery_type_score + 20*twog_talktime_score + 10*threeg_talktime_score + 20*twog_standbytime_score + 10*threeg_standbytime_score)/100
|
|
|
168 |
return score
|