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

Replaced f-strings in logging calls #50

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions openlr_dereferencer/decoding/candidate_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def make_candidate(
f"Bearing difference = {bear_diff} greater than max. bearing deviation = {config.max_bear_deviation}",
)
debug(
f"Not considering {candidate} because the bearing difference is {bear_diff} °.",
f"bear: {bearing}. lrp bear: {lrp.bear}",
"Not considering %s because the bearing difference is %.02f°. (bear: %.02f. lrp bear: %.02f)",
candidate, bear_diff, bearing, lrp.bear
)
return
candidate.score = score_lrp_candidate(lrp, candidate, config, is_last_lrp)
Expand Down Expand Up @@ -91,7 +91,7 @@ def nominate_candidates(
) -> Iterable[Candidate]:
"Yields candidate lines for the LRP along with their score."
debug(
f"Finding candidates for LRP {lrp} at {coords(lrp)} in radius {config.search_radius}"
"Finding candidates for LRP %s at %s within radius %.02f m", lrp, coords(lrp), config.search_radius
)
for line in reader.find_lines_close_to(coords(lrp), config.search_radius):
candidate = make_candidate(lrp, line, config, observer, is_last_lrp)
Expand Down Expand Up @@ -123,21 +123,21 @@ def get_candidate_route(
The returned path excludes the lines the candidate points are on.
If there is no matching path found, None is returned.
"""
debug(f"Try to find path between {start, dest}")
debug("Try to find path between %s,%s",start, dest)
if start.line.line_id == dest.line.line_id:
return Route(start, [], dest)
debug(
f"Finding path between nodes {start.line.end_node.node_id, dest.line.start_node.node_id}"
"Finding path between nodes %d,%d",start.line.end_node.node_id, dest.line.start_node.node_id
)
linefilter = lambda line: line.frc <= lfrc
try:
path = shortest_path(
start.line.end_node, dest.line.start_node, linefilter, maxlen=maxlen
)
debug(f"Returning {path}")
debug("Returning %s", path)
return Route(start, path, dest)
except LRPathNotFoundError:
debug(f"No path found between these nodes")
debug("No path found between these nodes")
return None


Expand Down Expand Up @@ -258,15 +258,15 @@ def handleCandidatePair(
if observer is not None:
observer.on_route_success(current, next_lrp, source, dest, route)

debug(f"DNP should be {current.dnp} m, is {length} m.")
debug("DNP should be %.02fm, is %.02fm.", current.dnp, length)
# If the path does not match DNP, continue with the next candidate pair
if length < minlen or length > maxlen:
debug("Shortest path deviation from DNP is too large")
if observer is not None:
observer.on_route_fail(current, next_lrp, source, dest, "Shortest path deviation from DNP is too large")
return None

debug(f"Taking route {route}.")
debug("Taking route %s.", route)

return route

Expand Down
12 changes: 5 additions & 7 deletions openlr_dereferencer/decoding/path_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,21 @@

def remove_offsets(path: Route, p_off: float, n_off: float) -> Route:
"""Remove start+end offsets, measured in meters, from a route and return the result"""
debug(f"Will consider positive offset = {p_off} m and negative offset {n_off} m.")
debug("Will consider positive offset = %.02fm and negative offset %.02fm.", p_off, n_off)
lines = path.lines
debug(f"This routes consists of {lines} and is {path.length()} m long.")
debug("This route consists of %s and is %.02fm long.", lines, path.length())
# Remove positive offset
debug(f"first line's offset is {path.absolute_start_offset}")
debug("first line's offset is %.02f",path.absolute_start_offset)
remaining_poff = p_off + path.absolute_start_offset
while remaining_poff >= lines[0].length:
debug(f"Remaining positive offset {remaining_poff} is greater than "
f"the first line. Removing it.")
debug("Remaining positive offset %.02f is greater than the first line. Removing it.", remaining_poff)
remaining_poff -= lines.pop(0).length
if not lines:
raise LRDecodeError("Offset is bigger than line location path")
# Remove negative offset
remaining_noff = n_off + path.absolute_end_offset
while remaining_noff >= lines[-1].length:
debug(f"Remaining negative offset {remaining_noff} is greater than "
f"the last line. Removing it.")
debug("Remaining negative offset %.02f is greater than the last line. Removing it.", remaining_noff)
remaining_noff -= lines.pop().length
if not lines:
raise LRDecodeError("Offset is bigger than line location path")
Expand Down
8 changes: 4 additions & 4 deletions openlr_dereferencer/decoding/scoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def score_geolocation(wanted: LocationReferencePoint, actual: PointOnLine, radiu
"""Scores the geolocation of a candidate.

A distance of `radius` or more will result in a 0.0 score."""
debug(f"Candidate coords are {actual.position()}")
debug("Candidate coords are %s", actual.position())
dist = distance(coords(wanted), actual.position())
if dist < radius:
return 1.0 - dist / radius
Expand Down Expand Up @@ -118,13 +118,13 @@ def score_lrp_candidate(
"""Scores the candidate (line) for the LRP.

This is the average of fow, frc, geo and bearing score."""
debug(f"scoring {candidate} with config {config}")
debug("scoring %s with config %s", candidate, config)
geo_score = config.geo_weight * score_geolocation(wanted, candidate, config.search_radius)
fow_score = config.fow_weight * config.fow_standin_score[wanted.fow][candidate.line.fow]
frc_score = config.frc_weight * score_frc(wanted.frc, candidate.line.frc)
bear_score = score_bearing(wanted, candidate, is_last_lrp, config.bear_dist)
bear_score *= config.bear_weight
score = fow_score + frc_score + geo_score + bear_score
debug(f"Score: geo {geo_score} + fow {fow_score} + frc {frc_score} "
f"+ bear {bear_score} = {score}")
debug("Score: geo(%.02f) + fow(%.02f) + frc(%.02f) + bear(%.02f) = %.02f", geo_score, fow_score, frc_score, bear_score, score
)
return score
Loading