Completed
Push — master ( 9d3bc0...b059cb )
by Oleksandr
01:07
created

Statistics.default()   A

Complexity

Conditions 1

Size

Total Lines 6

Duplication

Lines 6
Ratio 100 %

Code Coverage

Tests 1
CRAP Score 1.125

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 6
loc 6
ccs 1
cts 2
cp 0.5
rs 9.4285
cc 1
crap 1.125
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
7 1
from schematics.types.compound import ModelType
8
9 1
from .interfaces import INISerializable, DefaultProvider
10 1
from .helpers import field_from_ini
11
12
13 1 View Code Duplication
@zope.interface.implementer(INISerializable)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
14 1
@zope.interface.implementer(DefaultProvider)
15 1
class Users(Model):
16 1
    show_number = BooleanType(
17
        default=True,
18
        required=True,
19
    )
20 1
    show_ping = BooleanType(
21
        default=True,
22
        required=True,
23
    )
24 1
    show_name = BooleanType(
25
        default=True,
26
        required=True,
27
    )
28 1
    show_belligerent = BooleanType(
29
        default=True,
30
        required=True,
31
    )
32 1
    show_aircraft_designation = BooleanType(
33
        default=True,
34
        required=True,
35
    )
36 1
    show_aircraft_type = BooleanType(
37
        default=True,
38
        required=True,
39
    )
40 1
    show_score = BooleanType(
41
        default=True,
42
        required=True,
43
    )
44
45 1
    @classmethod
46
    def from_ini(cls, ini):
47
        return cls({
48
            'show_number': field_from_ini(
49
                cls.show_number, ini,
50
                'NET', 'showPilotNumber',
51
            ),
52
            'show_ping': field_from_ini(
53
                cls.show_ping, ini,
54
                'NET', 'showPilotPing',
55
            ),
56
            'show_name': field_from_ini(
57
                cls.show_name, ini,
58
                'NET', 'showPilotName',
59
            ),
60
            'show_belligerent': field_from_ini(
61
                cls.show_belligerent, ini,
62
                'NET', 'showPilotArmy',
63
            ),
64
            'show_aircraft_designation': field_from_ini(
65
                cls.show_aircraft_designation, ini,
66
                'NET', 'showPilotACDesignation',
67
            ),
68
            'show_aircraft_type': field_from_ini(
69
                cls.show_aircraft_type, ini,
70
                'NET', 'showPilotACType',
71
            ),
72
            'show_score': field_from_ini(
73
                cls.show_score, ini,
74
                'NET', 'showPilotScore',
75
            ),
76
        })
77
78 1
    @classmethod
79
    def default(cls):
80
        return cls({
81
            field_name: field.default
82
            for field_name, field in cls.fields.items()
83
        })
84
85
86 1 View Code Duplication
@zope.interface.implementer(INISerializable)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
87 1
@zope.interface.implementer(DefaultProvider)
88 1
class Belligerents(Model):
89 1
    show_score = BooleanType(
90
        default=False,
91
        required=True,
92
    )
93 1
    accumulate_score = BooleanType(
94
        default=False,
95
        required=True,
96
    )
97
98 1
    @classmethod
99
    def from_ini(cls, ini):
100
        return cls({
101
            'show_score': field_from_ini(
102
                cls.show_score, ini,
103
                'NET', 'showTeamScore',
104
            ),
105
            'accumulate_score': field_from_ini(
106
                cls.accumulate_score, ini,
107
                'NET', 'cumulativeTeamScore',
108
            ),
109
        })
110
111 1
    @classmethod
112
    def default(cls):
113
        return cls({
114
            field_name: field.default
115
            for field_name, field in cls.fields.items()
116
        })
117
118
119 1 View Code Duplication
@zope.interface.implementer(INISerializable)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
120 1
@zope.interface.implementer(DefaultProvider)
121 1
class Statistics(Model):
122 1
    is_disabled = BooleanType(
123
        default=False,
124
        required=True,
125
    )
126 1
    users = ModelType(
127
        model_spec=Users,
128
        required=True,
129
    )
130 1
    belligerents = ModelType(
131
        model_spec=Belligerents,
132
        required=True,
133
    )
134
135 1
    @classmethod
136
    def from_ini(cls, ini):
137
        return cls({
138
            'is_disabled': field_from_ini(
139
                cls.is_disabled, ini,
140
                'NET', 'disableNetStatStatistics',
141
            ),
142
            'users': Users.from_ini(ini),
143
            'belligerents': Belligerents.from_ini(ini),
144
        })
145
146 1
    @classmethod
147
    def default(cls):
148
        return cls({
149
            'is_disabled': cls.is_disabled.default,
150
            'users': Users.default(),
151
            'belligerents': Belligerents.default(),
152
        })
153