Subversion Repositories SmartDukaan

Rev

Details | 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
                    musicplayback = int(musicplayback[0])
28
                    print "musicplayback=" + `musicplayback`
29
 
30
                    if musicplayback < 20 :
31
                        score = score + 0.5
32
 
33
                    elif musicplayback < 35 :
34
                          score = score + 1.0
35
 
36
                    elif musicplayback > 35 :
37
                          score = score + 1.5
38
 
39
                # Capacity > Video Playback : <2 - 0.5, <5 - 1, >5 - 1.5 
40
                if features.has_key("Video Playback") :
41
                    videoplayback = features.get("Video Playback")
42
                    videoplayback = int(videoplayback[0])
43
                    print "videoplayback=" + `videoplayback`
44
 
45
                    if videoplayback < 2 :
46
                        score = score + 0.5
47
 
48
                    elif videoplayback < 5 :
49
                          score = score + 1.0
50
 
51
                    elif videoplayback > 5 :
52
                          score = score + 1.5
53
 
54
                # Capacity > TV Playback : <2 - 0.5, <5 - 1, >5 - 1.5
55
                if features.has_key("TV Playback") :
56
                    tvplayback = features.get("TV Playback")
57
                    tvplayback = int(tvplayback[0])
58
                    print "tvplayback=" + `tvplayback`
59
 
60
                    if tvplayback < 2 :
61
                        score = score + 0.5
62
 
63
                    elif tvplayback < 5 :
64
                          score = score + 1.0
65
 
66
                    elif tvplayback > 5 :
67
                          score = score + 1.5
68
 
69
            if capacity.has_key("childrenslides") :
70
                childrenslides = capacity.get("childrenslides")
71
 
72
                if childrenslides.has_key("Talk time") :
73
                    talktime = childrenslides.get("Talk time")
74
 
75
                    if talktime.has_key("features") :
76
                        features = talktime.get("features")
77
 
78
                        # Capacity > Talk time > 2G : <5 - 0.5, <10 - 1, >10 - 1.5
79
                        if features.has_key("2G") :
80
                            twog = features.get("2G")
81
                            twog = twog[0]
82
                            twog = twog.split(" ")
83
                            twog = int(twog[0])
84
                            print "twog=" + `twog`
85
 
86
                            if twog < 5 :
87
                                score = score + 0.5
88
 
89
                            elif twog < 10 :
90
                                score = score + 1.0
91
 
92
                            elif twog > 10 :
93
                                score = score + 1.5
94
 
95
                        # Capacity > Talk time > 3G : <5 - 0.5, <10 - 1, >10 - 1.5
96
                        if features.has_key("3G") :
97
                            threeg = features.get("3G")
98
                            threeg = threeg[0]
99
                            threeg = threeg.split(" ")
100
                            threeg = int(threeg[0])
101
                            print "threeg=" + `threeg`
102
 
103
                            if threeg < 5 :
104
                                score = score + 0.5
105
 
106
                            elif threeg < 10 :
107
                                score = score + 1.0
108
 
109
                            elif threeg > 10 :
110
                                score = score + 1.5
111
 
112
                if childrenslides.has_key("Standby time") :
113
                    standbytime = childrenslides.get("Standby time")
114
 
115
                    if standbytime.has_key("features") :
116
                        features = standbytime.get("features")
117
 
118
                        # Capacity > Standby time > 2G : <10 - 0.5, <20 - 1, >20 - 1.5
119
                        if features.has_key("2G") :
120
                            twog = features.get("2G")
121
                            twog = twog[0]
122
                            twog = twog.split(" ")
123
                            twog = int(twog[0])
124
                            print "twog=" + `twog`
125
 
126
                            if twog < 10 :
127
                                score = score + 0.5
128
 
129
                            elif twog < 20 :
130
                                score = score + 1.0
131
 
132
                            elif twog > 20 :
133
                                score = score + 1.5
134
 
135
                        # Capacity > Standby time > 3G : <10 - 0.5, <20 - 1, >20 - 1.5
136
                        if features.has_key("3G") :
137
                            threeg = features.get("3G")
138
                            threeg = threeg[0]
139
                            threeg = threeg.split(" ")
140
                            threeg = int(threeg[0])
141
                            print "threeg=" + `threeg`
142
 
143
                            if threeg < 10 :
144
                                score = score + 0.5
145
 
146
                            elif threeg < 20 :
147
                                score = score + 1.5
148
 
149
                            elif threeg > 20 :
150
                                score = score + 1.5
151
 
152
    return int(math.ceil(score))