Skip to content

Commit

Permalink
cleanup by flake8 (#64)
Browse files Browse the repository at this point in the history
* cleanup according to flake8 rules
  • Loading branch information
AndGem authored Dec 15, 2019
1 parent a206ce3 commit 9a61be6
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pythonapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ jobs:
pip install flake8
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
# exit-zero treats all errors as warnings.
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=160 --statistics
- name: Test with pytest
run: |
pip install pytest
Expand Down
44 changes: 31 additions & 13 deletions configuration.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,42 @@
class Configuration(object):

accepted_highways = dict()
accepted_highways['pedestrian'] = set(["primary", "secondary", "tertiary", "unclassified", "residential", "service", "primary_link", "secondary_link", "tertiary_link", "living_street", "pedestrian", "track", "road", "footway", "steps", "path"])
accepted_highways['bicycle'] = set(["primary", "secondary", "tertiary", "unclassified", "residential", "service", "primary_link", "secondary_link", "tertiary_link", "living_street", "track", "road", "path", "cycleway"])
accepted_highways['car'] = set(["motorway", "trunk", "primary", "secondary", "tertiary", "unclassified", "residential", "service", "motorway_link", "trunk_link", "primary_link", "secondary_link", "tertiary_link", "living_street"])
accepted_highways['pedestrian'] = set(["primary", "secondary", "tertiary", "unclassified", "residential", "service", "primary_link",
"secondary_link", "tertiary_link", "living_street", "pedestrian", "track", "road", "footway", "steps", "path"])
accepted_highways['bicycle'] = set(["primary", "secondary", "tertiary", "unclassified", "residential", "service",
"primary_link", "secondary_link", "tertiary_link", "living_street", "track", "road", "path", "cycleway"])
accepted_highways['car'] = set(["motorway", "trunk", "primary", "secondary", "tertiary", "unclassified", "residential",
"service", "motorway_link", "trunk_link", "primary_link", "secondary_link", "tertiary_link", "living_street"])

speed_limits = {"motorway" :120, "trunk" :120, "primary" :100,
"secondary" :100, "tertiary" : 70, "unclassified" : 50,
"residential" : 30, "service" : 10, "motorway_link" : 60,
"trunk_link" : 60, "primary_link" : 60, "secondary_link": 60,
"tertiary_link": 35, "living_street": 5, "pedestrian" : 5,
"track" : 5, "road" : 5, "footway" : 5,
"steps" : 5, "path" : 5, "cycleway" : 5,
"pedestrian_indoor": 5
}
speed_limits = {
"motorway": 120,
"trunk": 120,
"primary": 100,
"secondary": 100,
"tertiary": 70,
"motorway_link": 60,
"trunk_link": 60,
"primary_link": 60,
"secondary_link": 60,
"unclassified": 50,
"tertiary_link": 35,
"residential": 30,
"service": 10,
"living_street": 5,
"pedestrian": 5,
"track": 5,
"road": 5,
"footway": 5,
"steps": 5,
"path": 5,
"cycleway": 5,
"pedestrian_indoor": 5
}

walking_speed = 5
max_highway_speed = 120

extension = {"pedestrian":"pypgr", "car":"pycgr", "bicycle":"pybgr"}
extension = {"pedestrian": "pypgr", "car": "pycgr", "bicycle": "pybgr"}
network_type = None

def __init__(self, network_type="pedestrian"):
Expand Down
3 changes: 2 additions & 1 deletion graph/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import graph.graphfactory as graphfactory
import utils.timer as timer


from graph.graph import Graph
from typing import Set


def BFS(graph: Graph, s: int) -> Set[int]:
seen_nodes = set([s])
unvisited_nodes = deque([s])
Expand Down
3 changes: 2 additions & 1 deletion graph/contract_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
import graph.graph_types as graph_types
import utils.timer as timer


from graph.graph import Graph
from graph.graph_types import Edge, SimpleEdge, Vertex
from typing import Dict, List, Optional, Set, Tuple


@timer.timer
def contract(graph):
all_new_edges = find_new_edges(graph)
Expand Down
3 changes: 2 additions & 1 deletion graph/graph.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

from graph.graph_types import Edge, SimpleEdge, Vertex
from typing import List, Union


class Graph(object):

def __init__(self) -> None:
Expand Down
1 change: 1 addition & 0 deletions osm/osm_types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from typing import Optional


class OSMWay:
__slots__ = ["osm_id", "nodes", "highway", "area", "max_speed", "direction", "forward", "backward", "name"]

Expand Down
2 changes: 0 additions & 2 deletions osm/read_osm.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,3 @@ def _read_nodes(osm_file, found_nodes):
parser.parse(osm_file)

return n_handler.nodes


1 change: 0 additions & 1 deletion osm/xml_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ def endElement(self, tag: str) -> None:
if tag == "way":
self.start_tag_found = False

# check if way is acceptable
if not self.parser_helper.is_way_acceptable(self.current_way):
self.current_way = None
return
Expand Down
1 change: 0 additions & 1 deletion output/write_graph.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import codecs
import utils.timer as timer


def write_to_file(graph, filename_base, filename_ext):
Expand Down
3 changes: 2 additions & 1 deletion run.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def convert_osm_to_roadgraph(filename, network_type, options):
if __name__ == "__main__":
parser = OptionParser()
parser.add_option("-f", "--file", dest="filename", action="store", type="string")
parser.add_option("-n", "--networkType", dest="network_type", action="store", default="pedestrian", help="(p)edestrian, (b)icycle, (c)ar, [default: pedestrian]")
parser.add_option("-n", "--networkType", dest="network_type", action="store", default="pedestrian",
help="(p)edestrian, (b)icycle, (c)ar, [default: pedestrian]")
parser.add_option("-l", "--nolcc", dest="lcc", action="store_true", default=False)
parser.add_option("-c", "--contract", dest="contract", action="store_true")
(options, args) = parser.parse_args()
Expand Down
2 changes: 1 addition & 1 deletion utils/geo_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ def distance(lat1: float, lon1: float, lat2: float, lon2: float) -> float:
cos_val = min(1, cos_val)
arc_val = acos(cos_val)

return arc_val * 6373000 # distance in meters
return arc_val * 6373000 # distance in meters
3 changes: 2 additions & 1 deletion utils/timer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import time


from typing import Callable


def timer(function: Callable) -> Callable:
def wrapper(*args, **kwargs):
start_time = time.time()
Expand Down

0 comments on commit 9a61be6

Please sign in to comment.