Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
arneboockmeyer committed Jun 21, 2024
1 parent 8e9edee commit 3009bf4
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
poetry run isort -c .
- name: Lint with pylint
run: |
poetry run pylint yaramo
poetry run pylint yaramo --fail-under 6
test:

Expand Down
5 changes: 3 additions & 2 deletions test/topology_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from yaramo.model import Topology, Node, Edge
from yaramo.model import Edge, Node, Topology


def test_get_edge_by_nodes():
topology = Topology()
Expand All @@ -21,4 +22,4 @@ def _test_edge(_node_a, _node_b, _expected_edge):

_test_edge(node_a, node_b, edge)
_test_edge(node_b, node_a, edge)
_test_edge(node_a, node_c, None)
_test_edge(node_a, node_c, None)
1 change: 0 additions & 1 deletion yaramo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@


2 changes: 1 addition & 1 deletion yaramo/base_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def to_serializable(self) -> Tuple[dict, dict]:
In subclasses this creates a dictionary with immediately serializable attributes and
references (uuids) to attributes that are objects and also a second dictionary where said objects are serialized (by deligation).
Serialization
-------------
The idea is to collect all attributes of an object that can be serialized immediately and
Expand Down
11 changes: 9 additions & 2 deletions yaramo/edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,19 @@ class Edge(BaseElement):
"""This class is one of two Elements (Edge and Node) comprising the base of the yaramo Topology.
An Edge is fundamentally defined by two Nodes (a and b). It does have a list of GeoNodes and a list of Signals
that may be on that Edge. An Edge can have a length set on construction, however if that is not the case,
that may be on that Edge. An Edge can have a length set on construction, however if that is not the case,
the length can be calculated by calling update_length(). This sets the length based on the GeoNodes referred to by node_a and node_b
as well as any intermediate_geo_nodes. The maximum_speed of an Edge cannot be set on construction but will generally be determined based on the connected Topology and Signals.
"""

def __init__(self, node_a: Node, node_b: Node, vacancy_section: Optional[VacancySection] = None, length: float = None, **kwargs):
def __init__(
self,
node_a: Node,
node_b: Node,
vacancy_section: Optional[VacancySection] = None,
length: float = None,
**kwargs
):
"""
Parameters
----------
Expand Down
2 changes: 1 addition & 1 deletion yaramo/geo_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class GeoNode(ABC, BaseElement):
"""This is the baseclass of specific GeoNodes that use different coordinate systems.
A GeoNode refers to a GeoPoint as a means of location.
"""

Expand Down
2 changes: 1 addition & 1 deletion yaramo/geo_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class GeoPoint(ABC, BaseElement):
"""This is the baseclass of specific GeoPoints that use different coordinate systems.
A GeoPoint is characterized by it's x and y coordinates.
"""

Expand Down
2 changes: 1 addition & 1 deletion yaramo/model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from yaramo.edge import Edge # pylint: noqa
from yaramo.geo_node import GeoNode, Wgs84GeoNode, DbrefGeoNode # pylint: noqa
from yaramo.geo_node import DbrefGeoNode, GeoNode, Wgs84GeoNode # pylint: noqa
from yaramo.node import Node, NodeConnectionDirection # pylint: noqa
from yaramo.route import Route # pylint: noqa
from yaramo.signal import Signal, SignalDirection, SignalFunction, SignalKind # pylint: noqa
Expand Down
44 changes: 30 additions & 14 deletions yaramo/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Node(BaseElement):
We assume that there are only Nodes connected on all three or only one connection.
There can be a GeoNode associated with a Node to add a geo-location.
"""

def __init__(self, turnout_side=None, **kwargs):
"""
Parameters
Expand Down Expand Up @@ -81,8 +81,8 @@ def get_possible_followers(self, source):
return [self.connected_on_head]

def get_anschluss_of_other(self, other: "Node") -> NodeConnectionDirection:
""" Gets the Anschluss (Ende, Links, Rechts, Spitze) of other node.
"""Gets the Anschluss (Ende, Links, Rechts, Spitze) of other node.
Idea: We assume, the current node is a point and we want to estimate the Anschluss of the other node.
"""

Expand Down Expand Up @@ -111,8 +111,13 @@ def get_arc_between_nodes(_node_a: "Node", _node_b: "Node"):

return math.degrees(math.acos((_a * _a + _b * _b - _c * _c) / (2.0 * _a * _b)))

def is_above_line_between_points(head_point: GeoPoint, branching_point: GeoPoint, comparison_point: GeoPoint):
return ((branching_point.x - head_point.x)*(comparison_point.y - head_point.y) - (branching_point.y - head_point.y)*(comparison_point.x - head_point.x)) > 0
def is_above_line_between_points(
head_point: GeoPoint, branching_point: GeoPoint, comparison_point: GeoPoint
):
return (
(branching_point.x - head_point.x) * (comparison_point.y - head_point.y)
- (branching_point.y - head_point.y) * (comparison_point.x - head_point.x)
) > 0

current_max_arc = 361
other_a: "Node" = None
Expand All @@ -131,12 +136,20 @@ def is_above_line_between_points(head_point: GeoPoint, branching_point: GeoPoint
current_max_arc = cur_arc

# Check on which side of the line between the head connection and this node the other nodes are
side_a = is_above_line_between_points(self.connected_on_head.geo_node.geo_point, self.geo_node.geo_point, other_a.geo_node.geo_point)
side_b = is_above_line_between_points(self.connected_on_head.geo_node.geo_point, self.geo_node.geo_point, other_b.geo_node.geo_point)
side_a = is_above_line_between_points(
self.connected_on_head.geo_node.geo_point,
self.geo_node.geo_point,
other_a.geo_node.geo_point,
)
side_b = is_above_line_between_points(
self.connected_on_head.geo_node.geo_point,
self.geo_node.geo_point,
other_b.geo_node.geo_point,
)

# If they're on two separate sides we know which is left and right
if(side_a != side_b):
if (side_a):
if side_a != side_b:
if side_a:
self.connected_on_left, self.connected_on_right = other_a, other_b
else:
self.connected_on_right, self.connected_on_left = other_a, other_b
Expand All @@ -145,19 +158,22 @@ def is_above_line_between_points(head_point: GeoPoint, branching_point: GeoPoint
else:
arc_a = get_arc_between_nodes(self.connected_on_head, other_a)
arc_b = get_arc_between_nodes(self.connected_on_head, other_b)
if(arc_a > arc_b):
self.connected_on_right, self.connected_on_left = (other_a, other_b) if side_a else (other_b, other_a)
if arc_a > arc_b:
self.connected_on_right, self.connected_on_left = (
(other_a, other_b) if side_a else (other_b, other_a)
)
else:
self.connected_on_left, self.connected_on_right = (other_a, other_b) if side_a else (other_b, other_a)

self.connected_on_left, self.connected_on_right = (
(other_a, other_b) if side_a else (other_b, other_a)
)

def to_serializable(self):
"""See the description in the BaseElement class.
Returns:
A serializable dictionary and a dictionary with serialized objects (GeoNodes).
"""

attributes = self.__dict__
references = {
"connected_on_head": self.connected_on_head.uuid if self.connected_on_head else None,
Expand Down
10 changes: 5 additions & 5 deletions yaramo/route.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

from yaramo.base_element import BaseElement
from yaramo.edge import Edge
from yaramo.signal import Signal
from yaramo.node import Node
from yaramo.signal import Signal
from yaramo.vacancy_section import VacancySection


class Route(BaseElement):
"""A Route is a collection of edges defined by a start and end signal.
There are usally vacancy sections associated with a route.
"""

Expand All @@ -22,7 +22,7 @@ def __init__(self, start_signal: Signal, maximum_speed: Optional[int] = None, **
maximum_speed: int
The maximum allowed speed going over the whole Route.
"""

super().__init__(**kwargs)
self.maximum_speed: int = maximum_speed
self.edges: set[Edge] = set([start_signal.edge])
Expand Down Expand Up @@ -110,14 +110,14 @@ def to_serializable(self) -> Dict:
Returns:
A serializable dictionary with all attributes of the Route.
"""

attributes = self.__dict__
references = {
"maximum_speed": self.maximum_speed,
"edges": [edge.uuid for edge in self.edges],
"start_signal": self.start_signal.uuid,
"end_signal": self.end_signal.uuid if self.end_signal else None,
"vacancy_sections": self.vacancy_sections
"vacancy_sections": self.vacancy_sections,
}

return {**attributes, **references}, {}
4 changes: 3 additions & 1 deletion yaramo/signal.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from enum import Enum
from typing import Tuple, List, Set
from typing import List, Set, Tuple
from uuid import uuid4

from yaramo.additional_signal import AdditionalSignal
Expand Down Expand Up @@ -32,6 +32,7 @@ def __str__(self):

class SignalKind(Enum):
"""The SignalFunction determines the type of a Signal."""

Hauptsignal = 0
Mehrabschnittssignal = 1
Vorsignal = 2
Expand All @@ -45,6 +46,7 @@ def __str__(self):

class SignalState(Enum):
"""The SignalState determines a possible state of a Signal."""

hp0 = 0
hp1 = 1
hp2 = 2
Expand Down
4 changes: 2 additions & 2 deletions yaramo/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class Topology(BaseElement):
"""The Topology is a collection of all track elements comprising that topology.
Elements like Signals, Nodes, Edges, Routes and Vacancy Sections can be accessed by their uuid in their respective dictionary.
"""

Expand Down Expand Up @@ -74,5 +74,5 @@ def to_serializable(self):
"signals": signals,
"routes": routes,
"objects": objects,
"vacany_sections": vacancy_sections
"vacany_sections": vacancy_sections,
}, {}
1 change: 1 addition & 0 deletions yaramo/vacancy_section.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Tuple

from yaramo.base_element import BaseElement


Expand Down

0 comments on commit 3009bf4

Please sign in to comment.