From 16854c0f8a335a05ba5c3269c95de0977f725d64 Mon Sep 17 00:00:00 2001 From: "Davide Gessa (dakk)" Date: Thu, 2 Jun 2022 09:12:08 +0200 Subject: [PATCH] fix linting --- tests/linearbestisorouter_test.py | 8 ++++---- weatherrouting/polar.py | 2 +- weatherrouting/routers/linearbestisorouter.py | 7 ++++--- weatherrouting/routers/shortestpathrouter.py | 6 +++--- weatherrouting/routing.py | 16 ++++++++++------ 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/tests/linearbestisorouter_test.py b/tests/linearbestisorouter_test.py index 843a72a..3a1e645 100644 --- a/tests/linearbestisorouter_test.py +++ b/tests/linearbestisorouter_test.py @@ -132,7 +132,7 @@ def test_step(self): class checkRoute_mediumWind_mockIsland_8(unittest.TestCase): def setUp(self): - grib = mock_grib(5,45,0.5) + grib = mock_grib(5,45,0.5) self.track = [(5,38),(4.6,37.6)] island_route = mock_point_validity(self.track, factor=8) self.routing_obj = weatherrouting.Routing( @@ -157,7 +157,7 @@ def test_step(self): class checkRoute_highWind_mockIsland_3(unittest.TestCase): def setUp(self): - grib = mock_grib(10,270,0.5) + grib = mock_grib(10,270,0.5) self.track = [(5,38),(5.5,38.5)] island_route = mock_point_validity(self.track, factor=3) self.routing_obj = weatherrouting.Routing( @@ -182,7 +182,7 @@ def test_step(self): class checkRoute_out_of_scope(unittest.TestCase): def setUp(self): - grib = mock_grib(10,270,0.5,out_of_scope=datetime.datetime.fromisoformat('2021-04-02T15:00:00')) + grib = mock_grib(10,270,0.5,out_of_scope=datetime.datetime.fromisoformat('2021-04-02T15:00:00')) self.track = [(5,38),(5.5,38.5)] island_route = mock_point_validity(self.track, factor=3) self.routing_obj = weatherrouting.Routing( @@ -210,7 +210,7 @@ class checkRoute_multipoint(unittest.TestCase): def setUp(self): grib = mock_grib(10,270,0.5) self.track = [(5,38),(5.3,38.3),(5.6,38.6)] - island_route = mock_point_validity(self.track, factor=3) + # island_route = mock_point_validity(self.track, factor=3) self.routing_obj = weatherrouting.Routing( LinearBestIsoRouter, polar_bavaria38, diff --git a/weatherrouting/polar.py b/weatherrouting/polar.py index 146f6ac..e75502d 100644 --- a/weatherrouting/polar.py +++ b/weatherrouting/polar.py @@ -68,7 +68,7 @@ def toString(self) -> str: sl = self.speedTable[l] for x in sl: - s += '\t{:.1f}'.format(x) + s += f'\t{x:.1f}' s += '\n' l += 1 diff --git a/weatherrouting/routers/linearbestisorouter.py b/weatherrouting/routers/linearbestisorouter.py index a9a836d..7e74c66 100644 --- a/weatherrouting/routers/linearbestisorouter.py +++ b/weatherrouting/routers/linearbestisorouter.py @@ -42,7 +42,7 @@ def generate_path(p): position = path[-1].pos if self.grib.getWindAt (time + datetime.timedelta(hours=1), end[0],end[1]): - if lastlog is None and len (lastlog.isochrones) > 0: + if lastlog is not None and len (lastlog.isochrones) > 0: isoc = isoF(time + datetime.timedelta(hours=1), lastlog.isochrones, end) else: nwdist = utils.pointDistance (end[0], end[1], start[0], start[1]) @@ -54,10 +54,11 @@ def generate_path(p): for p in isoc[-1]: distance_to_end_point = p.pointDistance (end) if distance_to_end_point < self.getParamValue('minIncrease'): - (twd,tws) = self.grib.getWindAt (time + datetime.timedelta(hours=1), p.pos[0], p.pos[1]) + # (twd,tws) = self.grib.getWindAt (time + datetime.timedelta(hours=1), p.pos[0], p.pos[1]) maxReachDistance = utils.maxReachDistance(p.pos, p.speed) if distance_to_end_point < abs(maxReachDistance*1.1): - if (not self.pointValidity or self.pointValidity(end[0],end[1])) and (not self.lineValidity or self.lineValidity(end[0],end[1], p.pos[0], p.pos[1])): + if (not self.pointValidity or self.pointValidity(end[0],end[1])) and ( + not self.lineValidity or self.lineValidity(end[0],end[1], p.pos[0], p.pos[1])): if distance_to_end_point < nearest_dist: nearest_dist = distance_to_end_point nearest_solution = p diff --git a/weatherrouting/routers/shortestpathrouter.py b/weatherrouting/routers/shortestpathrouter.py index 8196cc8..c3270da 100644 --- a/weatherrouting/routers/shortestpathrouter.py +++ b/weatherrouting/routers/shortestpathrouter.py @@ -25,6 +25,6 @@ class ShortestPathRouter (LinearBestIsoRouter): 'Set the fixed speed', default=5.0, lower=1.0, upper=60.0, step=0.1, digits=1) } - def route (self, lastlog, time, start, end) -> RoutingResult: - return self._route(lastlog, time, start, end, lambda time, isoc, - end: self.calculateShortestPathIsochrones (self.getParamValue('fixedSpeed'), time, isoc, end)) + def route (self, lastlog, t, start, end) -> RoutingResult: + return self._route(lastlog, t, start, end, lambda t, isoc, + end: self.calculateShortestPathIsochrones (self.getParamValue('fixedSpeed'), t, isoc, end)) diff --git a/weatherrouting/routing.py b/weatherrouting/routing.py index c43a355..9c31a4d 100644 --- a/weatherrouting/routing.py +++ b/weatherrouting/routing.py @@ -30,7 +30,8 @@ class Routing: Routing class """ - def __init__ (self, algorithm, polar, track, grib, startDatetime, startPosition = None, pointValidity = None, lineValidity = None, pointsValidity = None, linesValidity = None): + def __init__ (self, algorithm, polar, track, grib, startDatetime, startPosition = None, + pointValidity = None, lineValidity = None, pointsValidity = None, linesValidity = None): """ Parameters ---------- @@ -52,13 +53,16 @@ def __init__ (self, algorithm, polar, track, grib, startDatetime, startPosition A functions that receives lat and lon and returns True if the point is valid (ie: in the sea) lineValidity : function(lat1, lon1, lat2, lon2) Optional, default to None - A functions that receives a vector defined by lat1, lon1, lat2, lon2 and returns True if the line is valid (ie: completely in the sea) + A functions that receives a vector defined by lat1, lon1, lat2, lon2 and returns True if the + line is valid (ie: completely in the sea) pointsValidity : function (latlons) Optional, default to None - A functions that receives a list of latlon and returns a list of boolean with True if the point at i is valid (ie: in the sea) + A functions that receives a list of latlon and returns a list of boolean with True if the point + at i is valid (ie: in the sea) linesValidity : function(latlons) Optional, default to None - A functions that receives a list of vectors defined by lat1, lon1, lat2, lon2 and returns a list of boolean with True if the line at i is valid (ie: completely in the sea) + A functions that receives a list of vectors defined by lat1, lon1, lat2, lon2 and returns a + list of boolean with True if the line at i is valid (ie: completely in the sea) """ @@ -69,7 +73,7 @@ def __init__ (self, algorithm, polar, track, grib, startDatetime, startPosition self.path = [] self.time = startDatetime self.grib = grib - self.log = [] + self.log = [] self._startingNewPoint = True if startPosition: @@ -109,7 +113,7 @@ def step (self) -> RoutingResult: self._startingNewPoint = True np = [] - ptime = None + ptime = None for x in self.path: nt = x.time