oval_graph.oval_tree.builder   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
eloc 67
dl 0
loc 79
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A Builder.dict_to_oval_tree() 0 21 2
A Builder._definition_dict_to_node() 0 27 3
A Builder.dict_of_rule_to_oval_tree() 0 14 1
A Builder._get_id_defintion() 0 5 2
1 1
import uuid
2
3 1
from .oval_node import OvalNode
4
5
6 1
class Builder:
7 1
    @staticmethod
8
    def _definition_dict_to_node(dict_of_definition):
9 1
        children = []
10 1
        for child in dict_of_definition['node']:
11 1
            if 'operator' in child:
12 1
                children.append(
13
                    Builder._definition_dict_to_node(child))
14
            else:
15 1
                children.append(
16
                    OvalNode(
17
                        node_id=child['value_id'],
18
                        node_type='value',
19
                        value=child['value'],
20
                        negation=child['negate'],
21
                        comment=child['comment'],
22
                        tag=child['tag'],
23
                        test_result_details=child['test_result_details'],
24
                    ))
25
26 1
        return OvalNode(
27
            node_id=Builder._get_id_defintion(dict_of_definition),
28
            node_type='operator',
29
            value=dict_of_definition['operator'],
30
            negation=dict_of_definition['negate'],
31
            comment=dict_of_definition['comment'],
32
            tag=dict_of_definition['tag'],
33
            children=children,
34
        )
35
36 1
    @staticmethod
37
    def _get_id_defintion(dict_of_definition):
38 1
        if 'definition_id' in dict_of_definition:
39 1
            return dict_of_definition['definition_id']
40 1
        return str(uuid.uuid4())
41
42 1
    @staticmethod
43
    def dict_of_rule_to_oval_tree(rule):
44 1
        dict_of_definition = rule['definition']
45 1
        dict_of_definition['node']['definition_id'] = rule['definition_id']
46 1
        return OvalNode(
47
            node_id=rule['rule_id'],
48
            node_type='operator',
49
            value='and',
50
            negation=False,
51
            comment=dict_of_definition['comment'],
52
            tag='Rule',
53
            children=[
54
                Builder._definition_dict_to_node(
55
                    dict_of_definition['node'])],
56
        )
57
58 1
    @staticmethod
59
    def dict_to_oval_tree(dict_of_tree):
60 1
        if dict_of_tree['child'] is None:
61 1
            return OvalNode(
62
                node_id=dict_of_tree['node_id'],
63
                node_type=dict_of_tree['type'],
64
                value=dict_of_tree['value'],
65
                negation=dict_of_tree['negation'],
66
                comment=dict_of_tree['comment'],
67
                tag=dict_of_tree['tag'],
68
                test_result_details=dict_of_tree['test_result_details']
69
            )
70 1
        return OvalNode(
71
            node_id=dict_of_tree['node_id'],
72
            node_type=dict_of_tree['type'],
73
            value=dict_of_tree['value'],
74
            negation=dict_of_tree['negation'],
75
            comment=dict_of_tree['comment'],
76
            tag=dict_of_tree['tag'],
77
            test_result_details=dict_of_tree['test_result_details'],
78
            children=[Builder.dict_to_oval_tree(i) for i in dict_of_tree['child']]
79
        )
80