Subversion Repositories SmartDukaan

Rev

Rev 1362 | Rev 2454 | 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
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
75 naveen 11
 
1915 rajveer 12
 
75 naveen 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(" ")
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
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
 
75 naveen 45
    # Max will be 1.5 * 7 = ceil(10.5) = 10 
46
    if struct.has_key("childrenslides") :
47
        childrenslides = struct.get("childrenslides")
48
 
49
        if childrenslides.has_key("Capacity") :
50
            capacity = childrenslides.get("Capacity")
51
            if capacity.has_key("features") :
52
                features = capacity.get("features")
1915 rajveer 53
 
75 naveen 54
            if capacity.has_key("childrenslides") :
55
                childrenslides = capacity.get("childrenslides")
56
 
57
                if childrenslides.has_key("Talk time") :
58
                    talktime = childrenslides.get("Talk time")
59
 
60
                    if talktime.has_key("features") :
61
                        features = talktime.get("features")
62
 
63
                        # Capacity > Talk time > 2G : <5 - 0.5, <10 - 1, >10 - 1.5
64
                        if features.has_key("2G") :
65
                            twog = features.get("2G")
76 naveen 66
                            if len(twog) > 0 :
67
                                twog = twog[0]
68
                                twog = twog.split(" ")
1915 rajveer 69
                                twog = float(twog[0])
70
 
76 naveen 71
                                print "twog=" + `twog`
75 naveen 72
 
1915 rajveer 73
                                if twog < 3 :
74
                                    twog_talktime_score = 3.0
76 naveen 75
 
1915 rajveer 76
                                elif twog >= 15 :
77
                                    twog_talktime_score = 10.0
76 naveen 78
 
1915 rajveer 79
                                else :
80
                                    twog_talktime_score = 3 + (twog - 3) / (15 - 3) * 7 
76 naveen 81
 
75 naveen 82
                        # Capacity > Talk time > 3G : <5 - 0.5, <10 - 1, >10 - 1.5
83
                        if features.has_key("3G") :
84
                            threeg = features.get("3G")
85
 
76 naveen 86
                            if len(threeg) > 0 :
87
                                threeg = threeg[0]
88
                                threeg = threeg.split(" ")
1362 rajveer 89
                                threeg = float(threeg[0])
76 naveen 90
                                print "threeg=" + `threeg`
91
 
1915 rajveer 92
                                if threeg < 2 :
93
                                    threeg_talktime_score = 3.0
76 naveen 94
 
1915 rajveer 95
                                elif threeg >= 8 :
96
                                    threeg_talktime_score = 10.0
76 naveen 97
 
1915 rajveer 98
                                else :
99
                                    threeg_talktime_score = 3.0 + (threeg - 3) / (8 - 2) * 7.0
100
 
75 naveen 101
                if childrenslides.has_key("Standby time") :
102
                    standbytime = childrenslides.get("Standby time")
103
 
104
                    if standbytime.has_key("features") :
105
                        features = standbytime.get("features")
106
 
107
                        # Capacity > Standby time > 2G : <10 - 0.5, <20 - 1, >20 - 1.5
108
                        if features.has_key("2G") :
109
                            twog = features.get("2G")
1915 rajveer 110
 
76 naveen 111
                            if len(twog) > 0 :
112
                                twog = twog[0]
113
                                twog = twog.split(" ")
1915 rajveer 114
                                twog = float(twog[0])
115
 
76 naveen 116
                                print "twog=" + `twog`
75 naveen 117
 
1915 rajveer 118
                                if twog < 5 :
119
                                    twog_standbytime_score = 2.0
120
 
121
                                elif twog >= 30 :
122
                                    twog_standbytime_score = 10.0
76 naveen 123
 
1915 rajveer 124
                                else :
125
                                    twog_standbytime_score = 2 + (twog - 5) / (30 - 5) * 8 
76 naveen 126
 
75 naveen 127
                        # Capacity > Standby time > 3G : <10 - 0.5, <20 - 1, >20 - 1.5
128
                        if features.has_key("3G") :
129
                            threeg = features.get("3G")
130
 
76 naveen 131
                            if len(threeg) > 0 :
132
                                threeg = threeg[0]
133
                                threeg = threeg.split(" ")
1362 rajveer 134
                                threeg = float(threeg[0])
76 naveen 135
                                print "threeg=" + `threeg`
136
 
1915 rajveer 137
                                if threeg < 5 :
138
                                    threeg_standbytime_score = 2.0 
76 naveen 139
 
1915 rajveer 140
                                elif threeg >= 30 :
141
                                    threeg_standbytime_score = 10.0
76 naveen 142
 
1915 rajveer 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