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

Commit

Permalink
Release 2024-03-04 (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
tordans authored Mar 4, 2024
2 parents 04ed2a9 + a501459 commit c403760
Show file tree
Hide file tree
Showing 16 changed files with 446 additions and 13 deletions.
1 change: 0 additions & 1 deletion app/process/roads_bikelanes/bikelanes/Bikelanes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package.path = package.path .. ";/app/process/helper/?.lua"
package.path = package.path .. ";/app/process/shared/?.lua"
package.path = package.path .. ";/app/process/roads_bikelanes/bikelanes/?.lua"
require("Set")
require("HighwayClasses")
require("TimeUtils")
require("categories")
require("transformations")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function BikelanesPresence(object, cycleways)
end

-- Guard
if PathClasses[tags.highway] then
if PathClasses[tags.highway] or tags.highway == 'pedestrian' then
return nil
end
if HighwayClasses[tags.highway] then
Expand Down
7 changes: 6 additions & 1 deletion app/process/roads_bikelanes/bikelanes/transformations.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
package.path = package.path .. ";/app/process/helper/?.lua"
package.path = package.path .. ";/app/process/shared/?.lua"
require('MergeTable')
require('HighwayClasses')

-- unnest all tags from ["prefix .. side:subtag"]=val -> ["subtag"]=val
local function unnestTags(tags, prefix, side, dest)
dest = dest or {}
Expand Down Expand Up @@ -48,7 +53,7 @@ function GetTransformedObjects(tags, transformations)
local results = { center }

-- don't transform paths
if PathClasses[tags.highway] then
if PathClasses[tags.highway] or tags.highway == 'pedestrian' then
return results
end

Expand Down
31 changes: 25 additions & 6 deletions app/process/roads_bikelanes/roads_bikelanes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ local roadsTable = osm2pgsql.define_table({
}
})

local roadsPathClassesTable = osm2pgsql.define_table({
name = 'roadsPathClasses',
ids = { type = 'any', id_column = 'osm_id', type_column = 'osm_type' },
columns = {
{ column = 'tags', type = 'jsonb' },
{ column = 'meta', type = 'jsonb' },
{ column = 'geom', type = 'linestring' },
}
})

local bikelanesTable = osm2pgsql.define_table({
name = '_bikelanes_temp',
ids = { type = 'any', id_column = 'osm_id', type_column = 'osm_type' },
Expand Down Expand Up @@ -126,6 +136,7 @@ function osm2pgsql.process_way(object)
result.sign = nil -- not used in atlas-app
result.side = nil -- not used in atlas-app
result.offset = nil -- not used in atlas-app
result.parent = nil -- not used in atlas-app
-- Note: `_parent_highway` is used in atlas-app (but should be migrated to something documented)
-- Note: `prefix` is used in atlas-app (but should be migrated to something documented)

Expand All @@ -137,18 +148,26 @@ function osm2pgsql.process_way(object)
end
end

if not PathClasses[tags.highway] then
if not (PathClasses[tags.highway] or tags.highway == 'pedestrian') then
MergeTable(results, Maxspeed(object))
end
MergeTable(results, BikelanesPresence(object, cycleways))

-- We need sidewalk for Biklanes(), but not for `roads`
if not IsSidepath(tags) then
roadsTable:insert({
tags = results,
meta = Metadata(object),
geom = object:as_linestring()
})
if PathClasses[tags.highway] then
roadsPathClassesTable:insert({
tags = results,
meta = Metadata(object),
geom = object:as_linestring()
})
else
roadsTable:insert({
tags = results,
meta = Metadata(object),
geom = object:as_linestring()
})
end
end
end

Expand Down
6 changes: 3 additions & 3 deletions app/process/shared/HighwayClasses.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ MinorRoadClasses = Set({
"residential", -- "Straße an und in Wohngebieten"
"road", -- Ohne Klassifizierung
"living_street", -- "Verkehrsberuhigter Bereich", "Spielstraße" traffic_sign=325.1 (Beginn), 326 (Ende)
"pedestrian", -- "Fußgängerzone"
"service", -- "Zufahrtswege", aber auch "Grundstückszufahrt", Wege auf Parkplätzen, "Drive trough", "Gassen", "Feuerwehzufahrt"
})

PathClasses = Set({
"pedestrian", -- "Fußgängerzone"
"track", -- "Wirtschaftswege", "Wald- und Feldwege"
"track", -- "Wirtschaftswege", "Wald- und Feldwege"
"bridleway", -- Reitweg
"path",
"footway",
"cycleway",
"bridleway", -- Reitweg
"steps",
})
1 change: 1 addition & 0 deletions cache-warming/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TILES_URL=staging-tiles.radverkehrsatlas.de
3 changes: 3 additions & 0 deletions cache-warming/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
src
*.log
.env.local
13 changes: 13 additions & 0 deletions cache-warming/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# About


## Run locally

1. Edit [`.env`](.env)
2. Run…

```
cd ./cache-warming
time node ./warmCache.js
```
26 changes: 26 additions & 0 deletions cache-warming/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"viewport": {
"width": 800,
"height": 600
},
"map": {
"lat": 52.3968,
"lng": 13.0342,
"zoomFrom": 8,
"zoomTo": 11
},
"urls": [
"/roads/{z}/{x}/{y}",
"/roadsPathClasses/{z}/{x}/{y}",
"/bikelanes_verified/{z}/{x}/{y}",
"/poiClassification/{z}/{x}/{y}",
"/boundaries,boundaryLabels/{z}/{x}/{y}",
"/boundaryStats/{z}/{x}/{y}",
"/publicTransport/{z}/{x}/{y}",
"/places/{z}/{x}/{y}",
"/barrierAreas,barrierLines/{z}/{x}/{y}",
"/landuse/{z}/{x}/{y}",
"/bicycleParking_points,bicycleParking_areas/{z}/{x}/{y}",
"/trafficSigns/{z}/{x}/{y}"
]
}
46 changes: 46 additions & 0 deletions cache-warming/createConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bun

import { sources } from '../../atlas-app/src/app/regionen/[regionSlug]/_mapData/mapDataSources/sources.const'
import { staticRegion } from '../../atlas-app/src/app/regionen/(index)/_data/regions.const'
import { getTilesUrl } from '../../atlas-app/src/app/_components/utils/getTilesUrl'


const regionSlug = 'bb'
const cacheWarmingConfigPath = 'config.json'

const viewport = {
width: 800,
height: 600,
}

const zoomOutLevels = 0
const zoomInLevels = 0

const region = staticRegion.find((region) => region.slug === regionSlug)

const tilesUrl = getTilesUrl()
const urls = sources
.map((source) => {
return source.tiles
})
.filter((url) => url.startsWith(tilesUrl) && url.endsWith('{z}/{x}/{y}'))
.map((url) => {
return url.replace(tilesUrl, '')
})

const data = {
viewport,
map: {
lat: region!.map.lat,
lng: region!.map.lng,
zoomFrom: region!.map.zoom - zoomOutLevels,
zoomTo: region!.map.zoom + zoomInLevels
},
urls,
}

const config = JSON.stringify(data, null, 2)
Bun.write(cacheWarmingConfigPath, config)

console.log(`${cacheWarmingConfigPath} saved.`)
console.log(config)
100 changes: 100 additions & 0 deletions cache-warming/filterLog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/usr/bin/env bun

import { parseArgs } from 'node:util'
import fs from 'node:fs'
import chalk from 'chalk'
import { parseSize, parseTime, displayHelp } from './util'

function error(message) {
console.error(message)
process.exit()
}

let parsed: any
try {
parsed = parseArgs({
options: {
help: { type: 'boolean', default: false },
'size': { type: 'string', short: 's' },
'time': { type: 'string', short: 't' },
grep: { type: 'string', short: 'g' },
'skip-errors': { type: 'boolean', short: 'e', default: false },
hit: { type: 'boolean', short: 'h', default: false },
miss: { type: 'boolean', short: 'm', default: false },
},
strict: true,
allowPositionals: true,
})
} catch (e) {
error(e.message)
}

const { values, positionals } = parsed

const args = {
help: values.help,
skipErrors: values['skip-errors'],
minSize: 'size' in values ? parseSize(values.size) : null,
minTime: 'time' in values ? parseTime(values.time) : null,
grep: values.grep || null,
hit: values.hit,
miss: values.miss,
}

if (values.help) {
displayHelp()
process.exit(0)
}

if (positionals.length === 0) error('Logfile argument is missing.')
if (positionals.length > 1) error('Too many arguments.')
const filename = positionals[0]
if (!fs.existsSync(filename)) error(`File "${filename}" not found.`)
if (args.hit && args.miss) error('Supply only one of "hit" or "miss"')

const logData = (await Bun.file(filename).text()).split('\n')
let i = 0
while (i < logData.length) {
const line = logData[i]!
if (!'🡇✓⚠'.split('').includes(line[0]!)) {
console.log(line)
i++
continue
}
let request = line
if (args.grep) {
const f0 = request.search(args.grep)
if (f0 === -1) {
i += 2
continue
} else {
const f1 = f0 + args.grep.length
request = request.slice(0, f0) + chalk.red(request.slice(f0, f1)) + request.slice(f1)
}
}
const response = logData[i + 1]!
if (!response) break

let [cacheStatus, timeFormatted, sizeFormatted] = response.slice(2).split(' - ')
if (response.startsWith('⚠')) {
if (!args.skipErrors) {
console.log(request)
console.log(response)
}
} else if (args.hit && cacheStatus !== 'HIT') {
// don't log
} else if (args.miss && cacheStatus !== 'MISS') {
// don't log
} else if (args.minSize === null && args.minTime === null) {
// don't log if neither minSize nor minTime is given
} else {
let [cacheStatus, timeFormatted, sizeFormatted] = response.slice(2).split(' - ')
const logSize = args.minSize === null ? false : parseSize(sizeFormatted) >= args.minSize
const logTime = args.minTime === null ? false : parseTime(timeFormatted) >= args.minTime
if (logSize || logTime) {
console.log(request)
console.log(response)
}
}
i += 2
}
38 changes: 38 additions & 0 deletions cache-warming/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions cache-warming/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "cachewarming",
"version": "1.0.0",
"main": "warmCache.js",
"type": "module",
"dependencies": {
"chalk": "^5.3.0",
"dotenv": "^16.4.5"
}
}
Loading

0 comments on commit c403760

Please sign in to comment.