Skip to content
This repository has been archived by the owner on Aug 8, 2024. It is now read-only.

Commit

Permalink
apply improvments to RoadsTodo and BiklanesTodo
Browse files Browse the repository at this point in the history
  • Loading branch information
rush42 committed Jul 2, 2024
1 parent 543108f commit 17545ba
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 45 deletions.
12 changes: 12 additions & 0 deletions processing/topics/helper/CreateTodoList.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require("ToMarkdownList")
function CreateTodoList(todos, tagsObject, resultTags)
local todoList = {}

for _, todo in ipairs(todos) do
local result = todo(tagsObject, resultTags)
if todo then
table.insert(todoList, result)
end
end
return ToMarkdownList(todoList)
end
53 changes: 24 additions & 29 deletions processing/topics/roads_bikelanes/bikelanes/BikelaneTodos.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,35 @@ BikelaneTodo = {}
BikelaneTodo.__index = BikelaneTodo

-- @param args table
-- @param args.key string
-- @param args.id string
-- @param args.desc string
-- @param args.conditions function
function BikelaneTodo.new(args)
local self = setmetatable({}, BikelaneTodo)
self.key = args.key
self.id = args.id
self.desc = args.desc
self.conditions = args.conditions
return self
end

function BikelaneTodo:checkCondition(objectTags, resultTags)
function BikelaneTodo:__call(objectTags, resultTags)
if self.conditions(objectTags, resultTags) then
return self.key
return self.id
else
return nil
end
end

-- === Fahrradstraßen ===
local missing_traffic_sign_244 = BikelaneTodo.new({
key = "missing_traffic_sign_244",
id = "missing_traffic_sign_244",
desc = "Expecting tag `traffic_sign=DE:244.1` or similar.",
conditions = function(tagsObject, _)
return tagsObject.bicycle_road == "yes" and not IsTermInString('DE:244.1', tagsObject.traffic_sign)
end
})
local missing_traffic_sign_vehicle_destination = BikelaneTodo.new({
key = "missing_traffic_sign_vehicle_destination",
id = "missing_traffic_sign_vehicle_destination",
desc = "Expecting tag traffic_sign 'Anlieger frei' `traffic_sign=DE:244.1,1020-30` or similar.",
conditions = function(tagsObject, _)
return tagsObject.bicycle_road == "yes"
Expand All @@ -41,7 +41,7 @@ local missing_traffic_sign_vehicle_destination = BikelaneTodo.new({
end
})
local missing_acccess_tag_bicycle_road = BikelaneTodo.new({
key = "missing_acccess_tag_bicycle_road",
id = "missing_acccess_tag_bicycle_road",
desc = "Expected access tag `bicycle=designated` that is required for routing.",
conditions = function(tagsObject, _)
return tagsObject.bicycle_road == "yes"
Expand All @@ -52,28 +52,28 @@ local missing_acccess_tag_bicycle_road = BikelaneTodo.new({

-- === Verkehrszeichen ===
local missing_traffic_sign = BikelaneTodo.new({
key = "missing_traffic_sign",
id = "missing_traffic_sign",
desc = "Expected tag `traffic_sign=DE:*` or `traffic_sign=none`.",
conditions = function(tagsObject, _)
return tagsObject.traffic_sign == nil
and not (
missing_traffic_sign_244:checkCondition(tagsObject) or
missing_traffic_sign_vehicle_destination:checkCondition(tagsObject)
missing_traffic_sign_244(tagsObject) or
missing_traffic_sign_vehicle_destination(tagsObject)
)
end
})

-- === Fuß- und Radweg ===
local missing_access_tag_240 = BikelaneTodo.new({
key = "missing_access_tag_240",
id = "missing_access_tag_240",
desc = "Expected tag `bicycle=designated` and `foot=designated`.",
conditions = function(tagsObject, _)
return (IsTermInString('DE:240', tagsObject.traffic_sign) or IsTermInString('DE:241', tagsObject.traffic_sign))
and tagsObject.bicycle ~= 'designated' and tagsObject.foot ~= "designated"
end
})
local missing_segregated = BikelaneTodo.new({
key = "missing_segregated",
id = "missing_segregated",
desc = "Expected tag `segregated=yes` or `segregated=no`.",
conditions = function(tagsObject, resultTags)
return resultTags.category == "needsClarification"
Expand All @@ -86,7 +86,7 @@ local missing_segregated = BikelaneTodo.new({

-- === Sidepath ===
local missing_sidepath = BikelaneTodo.new({
key = "missing_sidepath",
id = "missing_sidepath",
desc = "Expected tag `is_sidepath=yes` or `is_sidepath=no`.",
conditions = function(_, resultTags)
return resultTags.category == "footAndCyclewayShared_adjoiningOrIsolated"
Expand All @@ -98,26 +98,21 @@ local missing_sidepath = BikelaneTodo.new({

-- === cycleway:side=lane subcategory ===
local missing_cycleway_lane = BikelaneTodo.new({
key = "missing_cycleway_lane",
id = "missing_cycleway_lane",
desc = "Expected tag `cycleway:lane=advisory` or `cycleway:lane=exclusive`.",
conditions = function(_, resultTags)
return resultTags.category == "cyclewayOnHighway_advisoryOrExclusive"
end
})


-- Public funtion
function BikelaneTodos(tagsObject, resultTags)
local todos = {}

todos[#todos + 1] = missing_traffic_sign:checkCondition(tagsObject, resultTags)
todos[#todos + 1] = missing_traffic_sign_244:checkCondition(tagsObject, resultTags)
todos[#todos + 1] = missing_traffic_sign_vehicle_destination:checkCondition(tagsObject, resultTags)
todos[#todos + 1] = missing_acccess_tag_bicycle_road:checkCondition(tagsObject, resultTags)
todos[#todos + 1] = missing_access_tag_240:checkCondition(tagsObject, resultTags)
todos[#todos + 1] = missing_segregated:checkCondition(tagsObject, resultTags)
todos[#todos + 1] = missing_sidepath:checkCondition(tagsObject, resultTags)
todos[#todos + 1] = missing_cycleway_lane:checkCondition(tagsObject, resultTags)

return RemoveNilValues(todos)
end
BikelaneTodos = {
missing_traffic_sign,
missing_traffic_sign_244,
missing_traffic_sign_vehicle_destination,
missing_acccess_tag_bicycle_road,
missing_access_tag_240,
missing_segregated,
missing_sidepath,
missing_cycleway_lane
}
4 changes: 2 additions & 2 deletions processing/topics/roads_bikelanes/bikelanes/Bikelanes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ require("BikelaneCategories")
require("transformations")
require("CopyTags")
require("RoadWidth")
require("ToMarkdownList")
require("DeriveSurface")
require("DeriveSmoothness")
require("BikelaneTodos")
require("Sanitize")
require("DeriveOneway")
require("DefaultId")
require("DeriveTrafficSigns")
require("CreateTodoList")

local tags_copied = {
"mapillary",
Expand Down Expand Up @@ -90,7 +90,7 @@ function Bikelanes(object)
result_tags.age = AgeInDays(ParseCheckDate(tags["check_date:" .. transformedTags._prefix]))
end

result_tags.todos = ToMarkdownList(BikelaneTodos(transformedTags, result_tags))
result_tags.todos = CreateTodoList(BikelaneTodos, transformedTags, result_tags)
end
table.insert(result_bikelanes, result_tags)
end
Expand Down
18 changes: 5 additions & 13 deletions processing/topics/roads_bikelanes/roads/RoadTodos.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,27 @@ RoadTodo.__index = RoadTodo
-- @param args.conditions function
function RoadTodo.new(args)
local self = setmetatable({}, RoadTodo)
self.key = args.key
self.id = args.id
self.desc = args.desc
self.conditions = args.conditions
return self
end

function RoadTodo:checkCondition(objectTags, resultTags)
function RoadTodo:__call(objectTags, resultTags)
if self.conditions(objectTags, resultTags) then
return self.key
return self.id
else
return nil
end
end

-- === Fahrradstraßen ===
local check_cycleway_shared = RoadTodo.new({
key = "check_cycleway_shared",
id = "check_cycleway_shared",
desc = "Tagging `cycleway=shared` is very old tagging and should be checked an maybe removed.",
conditions = function(tagsObject, _)
return tagsObject.cycleway == "shared"
end
})


-- Public funtion
function RoadTodos(tagsObject, resultTags)
local todos = {}

todos[#todos + 1] = check_cycleway_shared:checkCondition(tagsObject, resultTags)

return RemoveNilValues(todos)
end
RoadTodos = {check_cycleway_shared}
3 changes: 2 additions & 1 deletion processing/topics/roads_bikelanes/roads_bikelanes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ require("Round")
require("DefaultId")
require("PathsGeneralization")
require("RoadTodos")
require("CreateTodoList")

local roadsTable = osm2pgsql.define_table({
name = 'roads',
Expand Down Expand Up @@ -135,7 +136,7 @@ function osm2pgsql.process_way(object)
MergeTable(results, Maxspeed(object))
end
MergeTable(results, BikelanesPresence(object, cycleways))
results.todos = ToMarkdownList(RoadTodos(tags, results))
results.todos = CreateTodoList(RoadTodos, tags, results)

-- We need sidewalk for Biklanes(), but not for `roads`
if not IsSidepath(tags) then
Expand Down

0 comments on commit 17545ba

Please sign in to comment.