Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code refactor: Refactor code and create custom class for node, edge, graph, animation etc, #18

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Bishalsarang
Copy link
Owner

Description

This PR adds custom classes for node, edge, graph. animation to make animation easier. For every class, test cases are also written.
This PR doesn't necessarily add new feature/functionality but make the codebase easier to improve animation in the future.

@Bishalsarang Bishalsarang marked this pull request as ready for review April 18, 2021 05:02
@Bishalsarang
Copy link
Owner Author

@CodiumAI-Agent /review

@CodiumAI-Agent
Copy link

PR Analysis

  • 🎯 Main theme: Refactoring the codebase to introduce custom classes for nodes, edges, graphs, and animations to improve future animations.
  • 📌 Type of PR: Refactoring
  • 🧪 Relevant tests added: True
  • Focused PR: Yes, the PR is focused as all the changes are related to the introduction of new classes and refactoring the existing codebase to accommodate these changes.
  • 🔒 Security concerns: No security concerns found

PR Feedback

  • General suggestions: The PR is well-structured and the code is clean. The introduction of custom classes for nodes, edges, graphs, and animations is a good approach to make the codebase more modular and maintainable. However, there are some methods in the classes that are not implemented yet. It would be better to either implement these methods or remove them if they are not needed.

  • 🤖 Code feedback:

    • relevant file: visualiser/graph.py
      suggestion: Consider adding docstrings to your methods to provide a brief explanation of their functionality. This will make your code more readable and maintainable. [medium]
      relevant line: def get_node(self, name):

    • relevant file: visualiser/animation.py
      suggestion: The 'next_frame' and 'previous_frame' methods are not implemented. If these methods are not needed, consider removing them to avoid confusion. If they are needed, make sure to implement them. [important]
      relevant line: def next_frame(self):

    • relevant file: tests/test_graph.py
      suggestion: The 'test_node_methods', 'test_edge_methods', and 'test_mutations' methods in the 'TestGraph' class are not implemented. If these tests are not needed, consider removing them. If they are needed, make sure to implement them. [important]
      relevant line: def test_node_methods(self):

How to use

Tag me in a comment '@CodiumAI-Agent' and add one of the following commands:
/review [-i]: Request a review of your Pull Request. For an incremental review, which only considers changes since the last review, include the '-i' option.
/describe: Modify the PR title and description based on the contents of the PR.
/improve [--extended]: Suggest improvements to the code in the PR. Extended mode employs several calls, and provides a more thorough feedback.
/ask <QUESTION>: Pose a question about the PR.
/update_changelog: Update the changelog based on the PR's contents.

To edit any configuration parameter from configuration.toml, add --config_path=new_value
For example: /review --pr_reviewer.extra_instructions="focus on the file: ..."
To list the possible configuration parameters, use the /config command.

@Bishalsarang
Copy link
Owner Author

@CodiumAI-Agent /improve [--extended]

Comment on lines +9 to +13
def __init__(self, source_node: Union[Node, str], destination_node: Union[Node, str], label: str = '',
**attrs: str) -> None:
self._source_node = Node(source_node) if isinstance(source_node, str) else copy.deepcopy(source_node)
self._destination_node = Node(destination_node) if isinstance(destination_node, str) else copy.deepcopy(
destination_node)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Consider adding error handling for when the source_node or destination_node is not of type Node or str. This will prevent the program from crashing when an invalid type is passed.

Suggested change
def __init__(self, source_node: Union[Node, str], destination_node: Union[Node, str], label: str = '',
**attrs: str) -> None:
self._source_node = Node(source_node) if isinstance(source_node, str) else copy.deepcopy(source_node)
self._destination_node = Node(destination_node) if isinstance(destination_node, str) else copy.deepcopy(
destination_node)
def __init__(self, source_node: Union[Node, str], destination_node: Union[Node, str], label: str = '',
**attrs: str) -> None:
if not isinstance(source_node, (Node, str)) or not isinstance(destination_node, (Node, str)):
raise TypeError('source_node and destination_node must be of type Node or str')
self._source_node = Node(source_node) if isinstance(source_node, str) else copy.deepcopy(source_node)
self._destination_node = Node(destination_node) if isinstance(destination_node, str) else copy.deepcopy(
destination_node)

Comment on lines +30 to +34
self._nodes.append(copy.deepcopy(node))

def set_node_attributes(self, node, **attrs):
for key, value in attrs.items():
self.set_node_attribute(node, key, value)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Consider adding error handling for when the node or edge is not of the correct type. This will prevent the program from crashing when an invalid type is passed.

Suggested change
self._nodes.append(copy.deepcopy(node))
def set_node_attributes(self, node, **attrs):
for key, value in attrs.items():
self.set_node_attribute(node, key, value)
def add_node(self, node):
if not isinstance(node, Node):
raise TypeError('node must be of type Node')
if self.get_node(node.name) is not None:
self.remove_node(node)
self._nodes.append(copy.deepcopy(node))
def add_edge(self, edge):
if not isinstance(edge, Edge):
raise TypeError('edge must be of type Edge')
if self.get_edge(edge.name) is not None:
self.remove_edge(edge)
self._edges.append(copy.deepcopy(edge))

Comment on lines +32 to +33
def get_frame(self, frame_id):
return self.frames[frame_id]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Consider adding error handling for when the frame_id is not of type int. This will prevent the program from crashing when an invalid type is passed.

Suggested change
def get_frame(self, frame_id):
return self.frames[frame_id]
def get_frame(self, frame_id):
if not isinstance(frame_id, int):
raise TypeError('frame_id must be of type int')
return self.frames[frame_id]

Comment on lines +9 to +16
def test_create_new_edge(self):
# Create Node
A = Node('A', color='red', style='filled')
B = Node('B', label='B label', color='red', style='filled')

# Create Edge
edge = Edge(A, B, label='Test Label')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Consider adding more assertions to the test case to ensure that all properties of the Edge class are functioning as expected.

Suggested change
def test_create_new_edge(self):
# Create Node
A = Node('A', color='red', style='filled')
B = Node('B', label='B label', color='red', style='filled')
# Create Edge
edge = Edge(A, B, label='Test Label')
def test_create_new_edge(self):
# Create Node
A = Node('A', color='red', style='filled')
B = Node('B', label='B label', color='red', style='filled')
# Create Edge
edge = Edge(A, B, label='Test Label')
assert edge.label == 'Test Label'
assert edge.source_node.label == 'A'
assert edge.source_node == A
assert edge.destination_node.label == 'B label'
assert edge.destination_node == B

Comment on lines +28 to +35
def test_node_methods(self):
pass

def test_edge_methods(self):
pass

def test_mutations(self):
pass

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Consider adding test cases for the test_node_methods, test_edge_methods, and test_mutations methods. Currently, these methods are empty and do not test anything.

Suggested change
def test_node_methods(self):
pass
def test_edge_methods(self):
pass
def test_mutations(self):
pass
def test_node_methods(self):
# Add test cases for node methods
def test_edge_methods(self):
# Add test cases for edge methods
def test_mutations(self):
# Add test cases for mutations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants