Completed
Push — master ( 76e46d...051bad )
by Oleksandr
05:22
created

to_angle()   A

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 2
ccs 2
cts 2
cp 1
crap 1
rs 10
1
# coding: utf-8
2
3 1
import datetime
4 1
import math
5
6 1
from il2fb.commons import Skills, UnitTypes
7 1
from il2fb.commons.organization import AirForces, Belligerents
8
9 1
from .constants import NULL, CHIEF_SPEED_COEFFICIENT
10
11
12 1
def to_bool(value):
13
    """
14
    Converts a string representation of a number into boolean.
15
16
    :param str value: a string representation of a number to convert
17
18
    :returns: `False` if `value` is equal to `'0'`, `True` otherwise
19
    :rtype: :class:`bool`
20
21
    **Examples:**
22
23
    .. code-block:: python
24
25
       >>> to_bool('0')
26
       False
27
       >>> to_bool('1')
28
       True
29
       >>> to_bool('-1')
30
       True
31
    """
32 1
    return int(value) != 0
33
34
35 1
def to_belligerent(value):
36 1
    return Belligerents.get_by_value(int(value))
37
38
39 1
def to_skill(value):
40 1
    return Skills.get_by_value(int(value))
41
42
43 1
def to_unit_type(value):
44 1
    return UnitTypes.get_by_value(value.lower())
45
46
47 1
def to_air_force(value):
48 1
    if value == NULL:
49 1
        return AirForces.vvs_rkka
50 1
    elif value:
51 1
        return AirForces.get_by_value(value)
52
53
54 1
def to_time(value):
55 1
    time = float(value)
56 1
    minutes, hours = math.modf(time)
57 1
    return datetime.time(int(hours), int(minutes * 60))
58
59
60 1
def to_speed(value):
61 1
    return round(float(value) * CHIEF_SPEED_COEFFICIENT, 2)
62
63
64 1
def to_angle(value):
65
    return round(float(value) % 360, 2)
66