Subversion Repositories SmartDukaan

Rev

Rev 1362 | Rev 1936 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1362 Rev 1915
Line 1... Line 1...
1
import math
1
import math
-
 
2
from math import sqrt
-
 
3
 
2
 
4
 
3
def getscore(struct):
5
def getscore(struct):
4
    
6
    
5
    score = 0.0
7
    score = 0.0
-
 
8
    builtin_score = 0.0
-
 
9
    expansion_type_score = 0.0
-
 
10
    expansion_capacity_score = 0.0
6
    
11
    
7
    if struct.has_key("features") :
12
    if struct.has_key("features") :
8
        features = struct.get("features")
13
        features = struct.get("features")
9
    
14
    
10
        # Built-in : <=50-0.5, <=100-1, <=250-1.5, >250-2
-
 
11
        if features.has_key("Built-in") :
15
        if features.has_key("Built-in") :
12
            builtin = features.get("Built-in")
16
            builtin = features.get("Built-in")
13
            
17
            
14
            if len(builtin) > 0 :
18
            if len(builtin) > 0 :
15
                builtin = float(builtin[0])
19
                builtin = float(builtin[0])
16
                print "builtin=" + `builtin`
20
                print "builtin=" + `builtin`
17
                 
-
 
18
                if builtin <=50 :
-
 
19
                    score += 0.5
-
 
20
                    
-
 
21
                elif builtin <=100 :
-
 
22
                    score += 1
-
 
23
                
21
                
24
                elif builtin <=250 :
22
                if builtin <= 1 :
25
                    score += 1.5
23
                    builtin_score = 0.0
26
                    
24
                    
27
                elif builtin > 250 :
25
                elif builtin >= 16*1024 :
28
                    score += 2
26
                    builtin_score = 10.0 
-
 
27
                
-
 
28
                else :
-
 
29
                    builtin_score = 10 - (sqrt(16*1024) - sqrt(builtin)) / (sqrt(16*1024) - 1) * 10 
29
                      
30
                      
30
        # RAM : <=128-2, <=256-4, >256-6
-
 
31
        if features.has_key("RAM") :
-
 
32
            ram = features.get("RAM")
-
 
33
            
-
 
34
            if len(ram) > 0 :
-
 
35
                ram = int(ram[0])
-
 
36
                print "ram=" + `ram`
-
 
37
                 
-
 
38
                if ram <= 128 :
-
 
39
                    score += 1
-
 
40
                    
-
 
41
                elif builtin <= 256 :
-
 
42
                    score += 2
-
 
43
 
-
 
44
                elif builtin > 256 :
-
 
45
                    score += 3
-
 
46
        
-
 
47
        # REVISIT
31
        # REVISIT
48
        # Expansion Type : microSD-2, others-1
32
        # Expansion Type : microSD-2, others-1
-
 
33
        if features.has_key("Expansion type") :
-
 
34
            expansion_type = features.get("Expansion type")
-
 
35
            if len(expansion_type) > 0 :
-
 
36
                expansion_type = expansion_type[0]
-
 
37
                if expansion_type ==  "MicroSD card" :
-
 
38
                    expansion_type_score = 10
49
        
39
                else :
-
 
40
                    expansion_type_score = 0.0
50
        # Expansion Capacity : 2, 4, 8, 16, 32
41
        # Expansion Capacity : 2, 4, 8, 16, 32
51
        if features.has_key("Expansion Capacity") :
42
        if features.has_key("Expansion capacity") :
52
            ec = features.get("Expansion Capacity")
43
            expansion_capacity = features.get("Expansion capacity")
53
            
44
            
54
            if len(ec) > 0 :
45
            if len(expansion_capacity) > 0 :
55
                ec = int(ec[0])
46
                expansion_capacity = int(expansion_capacity[0])
56
                print "ec=" + `ec`
47
                print "expansion_capacity=" + `expansion_capacity`
57
                 
48
                 
58
                if ec <= 2 :
49
                if expansion_capacity < 2*1024 :
59
                    score += 0.5
50
                    expansion_capacity_score = 0.0  
60
                    
51
                    
61
                elif ec <= 4 :
52
                elif expansion_capacity >= 32*1024 :
62
                    score += 1
53
                    expansion_capacity_score = 10
63
                
54
                
64
                elif ec <= 8 :
55
                else :
65
                    score += 1.5
56
                    expansion_capacity_score = (sqrt(16*1024) - sqrt(expansion_capacity)) / (sqrt(16*1024) - 1) * 10
-
 
57
 
66
                    
58
    print "builtin_score" + `builtin_score`
67
                elif ec > 16 :
59
    print "expansion_type_score" + `expansion_type_score`
68
                    score += 2
60
    print "expansion_capacity_score" + `expansion_capacity_score`
69
    
61
    
-
 
62
    score = (50*builtin_score + 10*expansion_type_score + 40*expansion_capacity_score)/100
70
    return int(math.floor(score))
63
    return score