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

Commit

Permalink
Move *_age tags to meta to exclude them from Diffs. (#147)
Browse files Browse the repository at this point in the history
The `*_age` tags change everyday even without updating the osm file or
code. That happens due to the dependence on todays date. This can be
very misleading when expecting the diffs. To avoid this behaviour we
move them to the `meta` object which is not included in the diffing
system.
  • Loading branch information
rush42 authored Jul 15, 2024
2 parents 13ece26 + a55ad8b commit 92fa48e
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 48 deletions.
40 changes: 23 additions & 17 deletions processing/topics/bicycleParking/bicycleParking.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ require("Set")
require("Sanitize")
require("DefaultId")
require("SanitizeTrafficSign")
require("MergeTable")
require("ExtractPublicTags")

local nodeTable = osm2pgsql.define_table({
name = 'bicycleParking_points',
Expand Down Expand Up @@ -67,13 +69,14 @@ end
local function processTags(tags)
-- this is the list of tags found in the wiki: https://wiki.openstreetmap.org/wiki/Tag:amenity%3Dbicycle_parking
-- also https://wiki.openstreetmap.org/wiki/Berlin/Verkehrswende/Fahrradparkpl%C3%A4tze
local results = capacityNormalization(tags)
local result_tags = {_meta = {}}
local binary = { "yes", "no" }
results.access = Sanitize(tags.access, { "yes", "private", "permissive", "customers" })
results.covered = Sanitize(tags.covered, binary, "implicit_no")
results.fee = Sanitize(tags.fee, binary, "implicit_no")
results.access_cargo_bike = Sanitize(tags.cargo_bike, binary, "implicit_no")
results.bicycle_parking = Sanitize(
MergeTable(result_tags, capacityNormalization(tags))
result_tags.access = Sanitize(tags.access, { "yes", "private", "permissive", "customers" })
result_tags.covered = Sanitize(tags.covered, binary, "implicit_no")
result_tags.fee = Sanitize(tags.fee, binary, "implicit_no")
result_tags.access_cargo_bike = Sanitize(tags.cargo_bike, binary, "implicit_no")
result_tags.bicycle_parking = Sanitize(
tags.bicycle_parking,
{ "stands", "wide_stands", "bollard", "wall_loops", "shed", "two-tier", "lockers" }
)
Expand All @@ -92,21 +95,23 @@ local function processTags(tags)
"mapillary",
"description",
}
CopyTags(results, tags, allowed_tags)
CopyTags(results, tags, tags_cc, "osm_")
results.traffic_sign = SanitizeTrafficSign(tags.traffic_sign)
CopyTags(result_tags, tags, allowed_tags)
CopyTags(result_tags, tags, tags_cc, "osm_")
result_tags.traffic_sign = SanitizeTrafficSign(tags.traffic_sign)

results.age = AgeInDays(ParseCheckDate(tags["check_date"]))
return results
result_tags._age = AgeInDays(ParseCheckDate(tags["check_date"]))
return result_tags
end

function osm2pgsql.process_node(object)
if exitProcessing(object) then return end
local tags = processTags(object.tags)
local result_tags = processTags(object.tags)
local meta = Metadata(object)
meta.age = result_tags._age

nodeTable:insert({
tags = tags,
meta = Metadata(object),
tags = ExtractPublicTags(result_tags),
meta = meta,
geom = object:as_point(),
minzoom = 0,
id = DefaultId(object)
Expand All @@ -115,12 +120,13 @@ end

function osm2pgsql.process_way(object)
if exitProcessing(object) then return end
local tags = processTags(object.tags)
local result_tags = processTags(object.tags)
local meta = Metadata(object)
meta.age = result_tags._age

-- convert bicycle parking mapped as lines or areas to points by taking the centroid
nodeTable:insert({
tags = tags,
tags = ExtractPublicTags(result_tags),
meta = meta,
geom = object:as_polygon():centroid(),
minzoom = 0,
Expand All @@ -129,7 +135,7 @@ function osm2pgsql.process_way(object)

if not object.is_closed then return end
areaTable:insert({
tags = tags,
tags = ExtractPublicTags(result_tags),
meta = meta,
geom = object:as_polygon(),
minzoom = 0,
Expand Down
12 changes: 0 additions & 12 deletions processing/topics/helper/RemoveNilValues.lua

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package.path = package.path .. ";/processing/topics/helper/?.lua"
require('RemoveNilValues')
BikelaneTodo = {}
BikelaneTodo.__index = BikelaneTodo

Expand Down
5 changes: 2 additions & 3 deletions processing/topics/roads_bikelanes/bikelanes/Bikelanes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function Bikelanes(object)
MergeTable(result_tags, {
_id = DefaultId(object),
_infrastructureExists = true,
age = AgeInDays(ParseCheckDate(tags["check_date"])),
_age = AgeInDays(ParseCheckDate(tags["check_date"])),
prefix = transformedTags._prefix,
width = ParseLength(transformedTags.width),
oneway = DeriveOneway(transformedTags, category.id),
Expand All @@ -78,7 +78,6 @@ function Bikelanes(object)
MergeTable(result_tags, DeriveSmoothness(transformedTags))
MergeTable(result_tags, DeriveSurface(transformedTags))
CopyTags(result_tags, transformedTags, tags_prefixed, 'osm_')

-- copy original tags
CopyTags(result_tags, tags, tags_copied)

Expand All @@ -87,7 +86,7 @@ function Bikelanes(object)
result_tags._id = DefaultId(object) .. '/' .. transformedTags._prefix .. '/' .. transformedTags._side
result_tags._parent_highway = transformedTags._parent_highway
result_tags.offset = sideSignMap[transformedTags._side] * RoadWidth(tags) / 2
result_tags.age = AgeInDays(ParseCheckDate(tags["check_date:" .. transformedTags._prefix]))
result_tags._age = AgeInDays(ParseCheckDate(tags["check_date:" .. transformedTags._prefix]))
end

result_tags.todos = CreateTodoList(BikelaneTodos, transformedTags, result_tags)
Expand Down
4 changes: 2 additions & 2 deletions processing/topics/roads_bikelanes/lit/Lit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ local tags_prefixed = {}

function Lit(object)
local tags = object.tags
local result_tags = {}
local result_tags = {_meta = {}}

-- Categorize the data in three groups: "lit", "unlit", "special"
if tags.lit ~= nil then
Expand All @@ -19,7 +19,7 @@ function Lit(object)
end
end

result_tags.lit_age = AgeInDays(ParseCheckDate(tags["check_date:lit"]))
result_tags._lit_age = AgeInDays(ParseCheckDate(tags["check_date:lit"]))

CopyTags(result_tags, tags, tags_copied)
CopyTags(result_tags, tags, tags_prefixed, "osm_")
Expand Down
2 changes: 1 addition & 1 deletion processing/topics/roads_bikelanes/maxspeed/Maxspeed.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function Maxspeed(object)
-- Freshness of data
-- 700+ https://taginfo.openstreetmap.org/keys/check_date%3Amaxspeed

result_tags.maxspeed_age = AgeInDays(ParseCheckDate(tags["check_date:maxspeed"]))
result_tags._maxspeed_age = AgeInDays(ParseCheckDate(tags["check_date:maxspeed"]))

CopyTags(result_tags, tags, tags_copied)
CopyTags(result_tags, tags, tags_prefixed, "osm_")
Expand Down
1 change: 0 additions & 1 deletion processing/topics/roads_bikelanes/roads/RoadTodos.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package.path = package.path .. ";/processing/topics/helper/?.lua"
require('RemoveNilValues')
RoadTodo = {}
RoadTodo.__index = RoadTodo

Expand Down
30 changes: 21 additions & 9 deletions processing/topics/roads_bikelanes/roads_bikelanes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,23 @@ function osm2pgsql.process_way(object)
MergeTable(results, SurfaceQuality(object))

local cycleways = Bikelanes(object)
local road_info = {
name = results.name,
length = length,
road = results.road,
}
for _, cycleway in ipairs(cycleways) do
if cycleway._infrastructureExists then
local publicTags = ExtractPublicTags(cycleway)
publicTags.name = results.name
publicTags.length = length
publicTags.road = results.road
publicTags._parent_highway = cycleway._parent_highway
local meta = Metadata(object)
meta.age = cycleway._age

cycleway.segregated = nil -- no idea why that is present in the inspector frontend for way 9717355
bikelanesTable:insert({
id = cycleway._id,
tags = publicTags,
meta = Metadata(object),
tags = MergeTable(publicTags, road_info),
meta = meta,
geom = object:as_linestring(),
minzoom = 0
})
Expand All @@ -140,10 +144,18 @@ function osm2pgsql.process_way(object)

-- We need sidewalk for Biklanes(), but not for `roads`
if not IsSidepath(tags) then
local meta = Metadata(object)
MergeTable(meta, {
age = AgeInDays(ParseCheckDate(tags["check_date"])),
surface_age = results._surface_age,
smoothness_age = results._smoothness_age,
maxspeed_age = results._maxspeed_age,
lit_age = results._lit_age
})
if PathClasses[tags.highway] then
roadsPathClassesTable:insert({
tags = results,
meta = Metadata(object),
tags = ExtractPublicTags(results),
meta = meta,
geom = object:as_linestring(),
minzoom = PathsGeneralization(tags, results),
id = DefaultId(object)
Expand All @@ -152,8 +164,8 @@ function osm2pgsql.process_way(object)
-- The `ref` (e.g. "B 264") is used in your map style and only relevant for higher road classes.
results.name_ref = tags.ref
roadsTable:insert({
tags = results,
meta = Metadata(object),
tags = ExtractPublicTags(results),
meta = meta,
geom = object:as_linestring(),
minzoom = RoadGeneralization(tags, results),
id = DefaultId(object)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ function SurfaceQuality(object)
MergeTable(result_tags, DeriveSmoothness(tags))

-- 77,000+ https://taginfo.openstreetmap.org/keys/check_date%3Asurface
result_tags.surface_age = AgeInDays(ParseCheckDate(tags["check_date:surface"]))
result_tags._surface_age = AgeInDays(ParseCheckDate(tags["check_date:surface"]))
-- 4,000+ https://taginfo.openstreetmap.org/keys/check_date%3Asmoothness
result_tags.smoothness_age = AgeInDays(ParseCheckDate(tags["check_date:smoothness"]))
result_tags._smoothness_age = AgeInDays(ParseCheckDate(tags["check_date:smoothness"]))

CopyTags(result_tags, tags, tags_copied)
CopyTags(result_tags, tags, tags_prefixed, "osm_")
Expand Down

0 comments on commit 92fa48e

Please sign in to comment.