Subversion Repositories SmartDukaan

Rev

Rev 323 | Rev 1915 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
75 naveen 1
import math
2
 
71 naveen 3
def getscore(struct):
75 naveen 4
 
5
    score = 0.0
6
 
7
    if struct.has_key("features") :
8
        # REVISIT - Nokia power adaptor should get more points
9
        # Power Adaptor
10
 
11
        # REVISIT - Certain battery types need to be than others
12
        # Battery Type
13
        pass
14
 
15
    # Max will be 1.5 * 7 = ceil(10.5) = 10 
16
    if struct.has_key("childrenslides") :
17
        childrenslides = struct.get("childrenslides")
18
 
19
        if childrenslides.has_key("Capacity") :
20
            capacity = childrenslides.get("Capacity")
21
            if capacity.has_key("features") :
22
                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
 
76 naveen 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
75 naveen 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")
76 naveen 44
 
45
                    if len(videoplayback) > 0 :
46
                        videoplayback = int(videoplayback[0])
47
                        print "videoplayback=" + `videoplayback`
48
 
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
75 naveen 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")
76 naveen 61
 
62
                    if len(tvplayback) > 0 :
90 naveen 63
                        tvplayback = int(tvplayback[0])
76 naveen 64
                        print "tvplayback=" + `tvplayback`
75 naveen 65
 
76 naveen 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 naveen 75
            if capacity.has_key("childrenslides") :
76
                childrenslides = capacity.get("childrenslides")
77
 
78
                if childrenslides.has_key("Talk time") :
79
                    talktime = childrenslides.get("Talk time")
80
 
81
                    if talktime.has_key("features") :
82
                        features = talktime.get("features")
83
 
84
                        # Capacity > Talk time > 2G : <5 - 0.5, <10 - 1, >10 - 1.5
85
                        if features.has_key("2G") :
86
                            twog = features.get("2G")
76 naveen 87
                            if len(twog) > 0 :
88
                                twog = twog[0]
89
                                twog = twog.split(" ")
1362 rajveer 90
                                try:
91
                                    twog = float(twog[0])
92
                                except:
93
                                    twog = 5
76 naveen 94
                                print "twog=" + `twog`
75 naveen 95
 
76 naveen 96
                                if twog < 5 :
97
                                    score = score + 0.5
98
 
99
                                elif twog < 10 :
100
                                    score = score + 1.0
101
 
102
                                elif twog > 10 :
103
                                    score = score + 1.5
104
 
75 naveen 105
                        # Capacity > Talk time > 3G : <5 - 0.5, <10 - 1, >10 - 1.5
106
                        if features.has_key("3G") :
107
                            threeg = features.get("3G")
108
 
76 naveen 109
                            if len(threeg) > 0 :
110
                                threeg = threeg[0]
111
                                threeg = threeg.split(" ")
1362 rajveer 112
                                threeg = float(threeg[0])
76 naveen 113
                                print "threeg=" + `threeg`
114
 
115
                                if threeg < 5 :
116
                                    score = score + 0.5
117
 
118
                                elif threeg < 10 :
119
                                    score = score + 1.0
120
 
121
                                elif threeg > 10 :
122
                                    score = score + 1.5
123
 
75 naveen 124
                if childrenslides.has_key("Standby time") :
125
                    standbytime = childrenslides.get("Standby time")
126
 
127
                    if standbytime.has_key("features") :
128
                        features = standbytime.get("features")
129
 
130
                        # Capacity > Standby time > 2G : <10 - 0.5, <20 - 1, >20 - 1.5
131
                        if features.has_key("2G") :
132
                            twog = features.get("2G")
133
 
76 naveen 134
                            if len(twog) > 0 :
135
                                twog = twog[0]
136
                                twog = twog.split(" ")
1362 rajveer 137
                                try:
138
                                    twog = float(twog[0])
139
                                except:
140
                                    twog = 5
76 naveen 141
                                print "twog=" + `twog`
142
 
143
                                if twog < 10 :
144
                                    score = score + 0.5
75 naveen 145
 
76 naveen 146
                                elif twog < 20 :
147
                                    score = score + 1.0
148
 
149
                                elif twog > 20 :
150
                                    score = score + 1.5
151
 
75 naveen 152
                        # Capacity > Standby time > 3G : <10 - 0.5, <20 - 1, >20 - 1.5
153
                        if features.has_key("3G") :
154
                            threeg = features.get("3G")
155
 
76 naveen 156
                            if len(threeg) > 0 :
157
                                threeg = threeg[0]
158
                                threeg = threeg.split(" ")
1362 rajveer 159
                                threeg = float(threeg[0])
76 naveen 160
                                print "threeg=" + `threeg`
161
 
162
                                if threeg < 10 :
163
                                    score = score + 0.5
164
 
165
                                elif threeg < 20 :
166
                                    score = score + 1.5
167
 
168
                                elif threeg > 20 :
169
                                    score = score + 1.5
170
 
171
    return int(math.floor(score))