Subversion Repositories SmartDukaan

Rev

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