Completed
Push — master ( 263efb...8c1082 )
by Oleksandr
03:25
created

Refly   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 4
c 4
b 0
f 1
dl 0
loc 56
ccs 8
cts 10
cp 0.8
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A default() 0 5 2
B from_ini() 0 26 2
1
# coding: utf-8
2
3 1
import zope.interface
4
5 1
from schematics.models import Model
6 1
from schematics.types import BooleanType, IntType, FloatType
7
8 1
from .constants import NO_DEATH_LIMIT_FLAG
9 1
from .helpers import field_from_ini
10
from .interfaces import INISerializable, DefaultProvider
11
12 1
13 1
@zope.interface.implementer(INISerializable)
14 1
@zope.interface.implementer(DefaultProvider)
15 1
class Refly(Model):
16
    enabled = BooleanType(
17
        default=True,
18
        required=True,
19 1
    )
20
    death_penalty = IntType(
21
        min_value=0,
22
        default=0,
23
        required=True,
24 1
    )
25
    death_penalty_multiplier = FloatType(
26
        min_value=0.0,
27
        default=0.0,
28
        required=True,
29 1
    )
30
    death_limit = IntType(
31
        min_value=1,
32
        default=None,
33
        required=False,
34
    )
35 1
36
    @classmethod
37
    def from_ini(cls, ini):
38
        death_limit = field_from_ini(
39
            cls.death_limit, ini,
40
            'NET', 'maxAllowedKIA',
41
        )
42
        death_limit = (
43
            None
44
            if death_limit == NO_DEATH_LIMIT_FLAG
45
            else death_limit
46
        )
47
48
        return cls({
49
            'enabled': not field_from_ini(
50
                cls.enabled, ini,
51
                'NET', 'reflyDisabled',
52
            ),
53
            'death_penalty': field_from_ini(
54
                cls.death_penalty, ini,
55
                'NET', 'reflyKIADelay',
56 1
            ),
57
            'death_penalty_multiplier': field_from_ini(
58
                cls.death_penalty_multiplier, ini,
59
                'NET', 'reflyKIADelayMultiplier',
60
            ),
61
            'death_limit': death_limit,
62
        })
63
64
    @classmethod
65
    def default(cls):
66
        return cls({
67
            field_name: field.default
68
            for field_name, field in cls.fields.items()
69
        })
70