Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
71 naveen 1
def getscore(struct):
78 naveen 2
 
1915 rajveer 3
    score = 0.0
78 naveen 4
 
1915 rajveer 5
    weight_score = 0.0
6
    thickness_score = 0.0
7
 
2655 rajveer 8
    category = struct.has_key("category")
9
    max_weight = 250
10
    min_weight = 60
11
    max_thickness = 20
12
    min_thickness = 9
13
 
14
    if category == "Tablets":
15
        max_weight = 740
16
        min_weight = 400
17
        max_thickness = 13
18
        min_thickness = 10
19
 
78 naveen 20
    if struct.has_key("features") :
21
        features = struct.get("features")
22
 
1915 rajveer 23
        # Weight : >250-10, <=60-10, others linear
78 naveen 24
        if features.has_key("Weight") :
25
            weight = features.get("Weight")
26
 
27
            if len(weight) > 0 :
110 naveen 28
                weight = float(weight[0])
78 naveen 29
                print "weight=" + `weight`
30
 
2655 rajveer 31
                if weight > max_weight :
1915 rajveer 32
                    weight_score = 0
78 naveen 33
 
2655 rajveer 34
                elif weight <= min_weight :
1915 rajveer 35
                    weight_score = 10
78 naveen 36
 
1915 rajveer 37
                else :
2655 rajveer 38
                    weight_score = 10 - (weight - min_weight) / (max_weight - min_weight) * 10
78 naveen 39
 
40
        # Size : Thickness <=10-4, <=12-3, <=14-2, >14-1
41
        if features.has_key("Size") :
42
            size = features.get("Size")
43
 
44
            if len(size) > 2 :
45
                thickness = float(size[2])
46
                print "thickness=" + `thickness`
47
 
2655 rajveer 48
                if thickness <= min_thickness :
1915 rajveer 49
                    thickness_score = 10
78 naveen 50
 
2655 rajveer 51
                elif thickness > max_thickness :
1915 rajveer 52
                    thickness_score = 0
78 naveen 53
 
1915 rajveer 54
                else :
2658 rajveer 55
                    thickness_score = 10 - (thickness - min_thickness) / (max_thickness - min_thickness) * 10
78 naveen 56
 
1936 rajveer 57
    score = (weight_score*50 + thickness_score*50)/100.0
78 naveen 58
 
59
    return score