Passed
Branch master (17b603)
by P.R.
01:31
created

etlt.helper.Allen.Allen.relation()   D

Complexity

Conditions 12

Size

Total Lines 47
Code Lines 25

Duplication

Lines 47
Ratio 100 %

Code Coverage

Tests 25
CRAP Score 12

Importance

Changes 0
Metric Value
cc 12
eloc 25
nop 4
dl 47
loc 47
ccs 25
cts 25
cp 1
crap 12
rs 4.8
c 0
b 0
f 0

How to fix   Complexity   

Complexity

Complex classes like etlt.helper.Allen.Allen.relation() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
"""
2
ETLT
3
4
Copyright 2016 Set Based IT Consultancy
5
6
Licence MIT
7
"""
8
9
10 1 View Code Duplication
class Allen:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
11
    """
12
    Utility class for Allen's interval algebra, https://en.wikipedia.org/wiki/Allen%27s_interval_algebra.
13
    """
14
    # ------------------------------------------------------------------------------------------------------------------
15 1
    X_BEFORE_Y = 1
16 1
    X_MEETS_Y = 2
17 1
    X_OVERLAPS_WITH_Y = 3
18 1
    X_STARTS_Y = 4
19 1
    X_DURING_Y = 5
20 1
    X_FINISHES_Y = 6
21 1
    X_EQUAL_Y = 0
22 1
    X_BEFORE_Y_INVERSE = -1
23 1
    X_MEETS_Y_INVERSE = -2
24 1
    X_OVERLAPS_WITH_Y_INVERSE = -3
25 1
    X_STARTS_Y_INVERSE = -4
26 1
    X_DURING_Y_INVERSE = -5
27 1
    X_FINISHES_Y_INVERSE = -6
28
29
    # ------------------------------------------------------------------------------------------------------------------
30 1
    @staticmethod
31 1
    def relation(x_start, x_end, y_start, y_end):
32
        """
33
        Returns the relation between two intervals.
34
35
        :param int x_start: The start point of the first interval.
36
        :param int x_end: The end point of the first interval.
37
        :param int y_start: The start point of the second interval.
38
        :param int y_end: The end point of the second interval.
39
40
        :rtype: int|None
41
        """
42
43 1
        if (x_end - x_start) < 0 or (y_end - y_start) < 0:
44 1
            return None
45
46 1
        diff_end = y_end - x_end
47
48 1
        if diff_end < 0:
49 1
            return -Allen.relation(y_start, y_end, x_start, x_end)
50
51 1
        diff_start = y_start - x_start
52 1
        gab = y_start - x_end
53
54 1
        if diff_end == 0:
55 1
            if diff_start == 0:
56 1
                return Allen.X_EQUAL_Y
57
58 1
            if diff_start < 0:
59 1
                return Allen.X_FINISHES_Y
60
61 1
            return Allen.X_FINISHES_Y_INVERSE
62
63 1
        if gab > 1:
64 1
            return Allen.X_BEFORE_Y
65
66 1
        if gab == 1:
67 1
            return Allen.X_MEETS_Y
68
69 1
        if diff_start > 0:
70 1
            return Allen.X_OVERLAPS_WITH_Y
71
72 1
        if diff_start == 0:
73 1
            return Allen.X_STARTS_Y
74
75 1
        if diff_start < 0:
76 1
            return Allen.X_DURING_Y
77
78
# ----------------------------------------------------------------------------------------------------------------------
79