Total Complexity | 12 |
Total Lines | 77 |
Duplicated Lines | 87.01 % |
Coverage | 100% |
Changes | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
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: |
|
|||
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 | |||
79 |