This repository has been archived by the owner on Aug 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
833 additions
and
466 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Check PR | ||
on: [pull_request] | ||
jobs: | ||
run-ci: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Build Image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
file: ./processing.Dockerfile | ||
tags: test_img | ||
target: lua | ||
push: false | ||
load: true | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
|
||
- name: Run Tests | ||
run: | | ||
docker run -v ./processing:/processing test_img busted /processing/topics/ -p %.test%.lua$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package.path = package.path .. ";/processing/topics/helper/?.lua" | ||
|
||
require("SanitizeTrafficSign") | ||
|
||
function DeriveTrafficSigns(tags) | ||
local results = { | ||
['traffic_sign'] = SanitizeTrafficSign(tags.traffic_sign) or SanitizeTrafficSign(tags['traffic_sign:both']), | ||
['traffic_sign:forward'] = SanitizeTrafficSign(tags['traffic_sign:forward']), | ||
['traffic_sign:backward'] = SanitizeTrafficSign(tags['traffic_sign:backward']) | ||
} | ||
return results | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- Remove table entries where the value is `nil` | ||
---@param inputTable table | ||
---@return table | ||
function RemoveNilValues(inputTable) | ||
local cleanTable = {} | ||
for _, v in ipairs(inputTable) do | ||
if v ~= nil then | ||
cleanTable[#cleanTable + 1] = v | ||
end | ||
end | ||
return cleanTable | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
-- Remove all whitespaces after delimeters | ||
local function stripWhitespaces(traffic_sign) | ||
local stripped = string.gsub(traffic_sign, ', ', ',') | ||
stripped = string.gsub(stripped, '; ', ';') | ||
return stripped | ||
end | ||
|
||
--- Cleanup the `traffic_sign=*` tag | ||
--- @param traffic_sign string | ||
--- @returns string | ||
function SanitizeTrafficSign(traffic_sign) | ||
if traffic_sign == nil then | ||
return nil | ||
end | ||
if traffic_sign == "no" or traffic_sign == 'none' then | ||
return "none" | ||
end | ||
|
||
-- Docs: patterns with "^" target beginning of string | ||
|
||
-- This is the correct tagging, all traffic signs should start with DE: | ||
if string.find(traffic_sign, '^DE:%S') then | ||
return stripWhitespaces(traffic_sign) | ||
end | ||
|
||
local substitutions = { | ||
['^DE: '] = 'DE:', | ||
['^DE%.'] = 'DE:', | ||
['^D:'] = 'DE:', | ||
['^D%.'] = 'DE:', | ||
['^de:'] = 'DE:', | ||
['^DE1'] = 'DE:1', | ||
['^DE2'] = 'DE:2', | ||
['^2'] = 'DE:2', | ||
['^1'] = 'DE:1', | ||
-- These patterns could handle all the above in a more generalized way | ||
-- ['^DE?[:.]%s?'] = 'DE:', | ||
-- ['^de?[:.]%s?'] = 'DE:' | ||
-- ['^DE(%d)'] = 'DE:%1' | ||
-- ['^(%d)'] = 'DE:%1' | ||
} | ||
for pattern, substitude in pairs(substitutions) do | ||
local val, n = string.gsub(traffic_sign, pattern, substitude) | ||
if n > 0 then | ||
-- TODO: add to todo list | ||
return stripWhitespaces(val) | ||
end | ||
end | ||
|
||
-- Discard everything else | ||
return nil | ||
end |
73 changes: 73 additions & 0 deletions
73
processing/topics/helper/__tests__/SanitizeTrafficSign.test.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
require("osm2pgsql") | ||
|
||
describe("SanitizeTrafficSign", function() | ||
package.path = package.path .. ";/processing/topics/helper/?.lua" | ||
require("SanitizeTrafficSign") | ||
|
||
-- Cleanup | ||
it('renames `no` to `none`', function() | ||
assert.are.same(SanitizeTrafficSign("no"), "none") | ||
end) | ||
|
||
it('renames `DE:SPACE` to `DE:`', function() | ||
assert.are.same(SanitizeTrafficSign("DE: 123"), "DE:123") | ||
end) | ||
|
||
it('renames `DE234` to `DE:234`', function() | ||
assert.are.same(SanitizeTrafficSign("DE234"), "DE:234") | ||
end) | ||
|
||
it('renames `DE1010` to `DE:1010`', function() | ||
assert.are.same(SanitizeTrafficSign("DE1010"), "DE:1010") | ||
end) | ||
|
||
it('renames `D:234` to `DE:234`', function() | ||
assert.are.same(SanitizeTrafficSign("D:234"), "DE:234") | ||
end) | ||
|
||
it('renames `de:234` to `DE:234`', function() | ||
assert.are.same(SanitizeTrafficSign("de:234"), "DE:234") | ||
end) | ||
|
||
it('renames `234` to `DE:234`', function() | ||
assert.are.same(SanitizeTrafficSign("234"), "DE:234") | ||
end) | ||
|
||
it('renames `1010` to `DE:1010`', function() | ||
assert.are.same(SanitizeTrafficSign("1010"), "DE:1010") | ||
end) | ||
|
||
it('renames `DE.234` to `DE:234`', function() | ||
assert.are.same(SanitizeTrafficSign("DE.234"), "DE:234") | ||
end) | ||
|
||
it('cleans spaces `DE:123, 1010; 234` to `DE:123,1010;234`', function() | ||
assert.are.same(SanitizeTrafficSign("DE:123, 1010; 234"), "DE:123,1010;234") | ||
end) | ||
|
||
-- Allow | ||
it('allows `DE:234`', function() | ||
assert.are.same(SanitizeTrafficSign("DE:234"), "DE:234") | ||
end) | ||
|
||
it('allows `DE:1010`', function() | ||
assert.are.same(SanitizeTrafficSign("DE:1010"), "DE:1010") | ||
end) | ||
|
||
it('allows `none` as value', function() | ||
assert.are.same(SanitizeTrafficSign("none"), "none") | ||
end) | ||
|
||
-- Disallow | ||
it('handles nil', function() | ||
assert.are.same(SanitizeTrafficSign(nil), nil) | ||
end) | ||
it('disallows everything else', function() | ||
assert.are.same(SanitizeTrafficSign("foobar"), nil) | ||
assert.are.same(SanitizeTrafficSign("yes"), nil) | ||
assert.are.same(SanitizeTrafficSign("unkown"), nil) | ||
assert.are.same(SanitizeTrafficSign("AT:foobar"), nil) | ||
assert.are.same(SanitizeTrafficSign("pictogram"), nil) | ||
assert.are.same(SanitizeTrafficSign("(comment)"), nil) | ||
end) | ||
end) |
Oops, something went wrong.