Passed
Push — main ( 2ba9b1...8014f2 )
by Eran
03:22
created

polygonal_graph   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 62
Duplicated Lines 45.16 %

Importance

Changes 0
Metric Value
eloc 25
dl 28
loc 62
rs 10
c 0
b 0
f 0
wmc 2

1 Function

Rating   Name   Duplication   Size   Complexity  
A polygonal_graph_model() 0 22 2

How to fix   Duplicated Code   

Duplicated Code

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
import graphinate
2
import graphinate.modeling
3
import networkx as nx
4
5
N: int = 8
6
7
8
def polygonal_graph_model(number_of_sides: int = N):
9
    """
10
    Create a polygonal graph model.
11
12
    Args:
13
        number_of_sides (int): Number of sides in the polygon. Defaults to N.
14
15
    Returns:
16
        GraphModel: A graph model representing a polygonal graph.
17
    """
18
19
    # Define GraphModel
20
    graph_model = graphinate.model(name="Octagonal Graph")
21
22
    # Register edges supplier function
23
    @graph_model.edge()
24
    def edge():
25
        for i in range(number_of_sides - 1):
26
            yield {'source': i, 'target': i + 1}
27
        yield {'source': number_of_sides - 1, 'target': 0}
28
29
    return graph_model
30
31
32
model = polygonal_graph_model()
33
34 View Code Duplication
if __name__ == '__main__':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
35
    use_materialize = True
36
37
    if use_materialize:
38
        # Materialize the GraphModel
39
        graphinate.materialize(
40
            model,
41
            builder=graphinate.builders.GraphQLBuilder,
42
            actualizer=graphinate.graphql
43
        )
44
45
    else:
46
        # Or
47
48
        # 1. Define Graph Builder
49
        builder = graphinate.builders.NetworkxBuilder(model=model)
50
51
        # Then
52
        # 2. Build the Graph object
53
        graph: nx.Graph = builder.build()
54
55
        # Then
56
        # 3. Option A - Output to console
57
        print(graph)
58
59
        # Or
60
        # 3. Option B - Output as a plot
61
        graphinate.materializers.plot(graph)
62