Chore: formatting

This commit is contained in:
Pieter Vander Vennet 2024-08-09 16:58:48 +02:00
parent 6a0b77eb99
commit 4fe2df61fe
4 changed files with 359 additions and 231 deletions

16
package-lock.json generated
View file

@ -1,12 +1,12 @@
{ {
"name": "mapcomplete", "name": "mapcomplete",
"version": "0.44.11", "version": "0.44.13",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "mapcomplete", "name": "mapcomplete",
"version": "0.44.11", "version": "0.44.13",
"license": "GPL-3.0-or-later", "license": "GPL-3.0-or-later",
"dependencies": { "dependencies": {
"@comunica/core": "^3.0.1", "@comunica/core": "^3.0.1",
@ -7893,9 +7893,9 @@
} }
}, },
"node_modules/caniuse-lite": { "node_modules/caniuse-lite": {
"version": "1.0.30001642", "version": "1.0.30001651",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001642.tgz", "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001651.tgz",
"integrity": "sha512-3XQ0DoRgLijXJErLSl+bLnJ+Et4KqV1PY6JJBGAFlsNsz31zeAIncyeZfLCabHK/jtSh+671RM9YMldxjUPZtA==", "integrity": "sha512-9Cf+Xv1jJNe1xPZLGuUXLNkE1BoDkqRqYyFJ9TDYSqhduqA4hu4oR9HluGoWYQC/aj8WHjsGVV+bwkh0+tegRg==",
"dev": true, "dev": true,
"funding": [ "funding": [
{ {
@ -25250,9 +25250,9 @@
"version": "2.0.1" "version": "2.0.1"
}, },
"caniuse-lite": { "caniuse-lite": {
"version": "1.0.30001642", "version": "1.0.30001651",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001642.tgz", "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001651.tgz",
"integrity": "sha512-3XQ0DoRgLijXJErLSl+bLnJ+Et4KqV1PY6JJBGAFlsNsz31zeAIncyeZfLCabHK/jtSh+671RM9YMldxjUPZtA==", "integrity": "sha512-9Cf+Xv1jJNe1xPZLGuUXLNkE1BoDkqRqYyFJ9TDYSqhduqA4hu4oR9HluGoWYQC/aj8WHjsGVV+bwkh0+tegRg==",
"dev": true "dev": true
}, },
"canonicalize": { "canonicalize": {

View file

@ -15,12 +15,10 @@ import { TagUtils } from "../../src/Logic/Tags/TagUtils"
import { BBox } from "../../src/Logic/BBox" import { BBox } from "../../src/Logic/BBox"
export default class CleanRepair extends Script { export default class CleanRepair extends Script {
constructor() { constructor() {
super("Cleans 'repair'-tags for mass retagging") super("Cleans 'repair'-tags for mass retagging")
} }
async main(args: string[]) { async main(args: string[]) {
const path = args[0] const path = args[0]
console.log("Loading", path) console.log("Loading", path)
@ -32,141 +30,244 @@ export default class CleanRepair extends Script {
"repair!=brand", "repair!=brand",
"repair!=only", "repair!=only",
"repair!=only_sold", "repair!=only_sold",
"repair!=assisted_self_service" "repair!=assisted_self_service",
] ],
}) })
const overpass = new Overpass(criteria, [], const overpass = new Overpass(criteria, [], "https://overpass-api.de/api/interpreter")
"https://overpass-api.de/api/interpreter" const data: Feature<Geometry, Record<string, string>>[] = (
) await overpass.queryGeoJson(BBox.global)
const data: Feature<Geometry, Record<string, string>> [] = (await overpass.queryGeoJson(BBox.global))[0].features )[0].features
console.log("Got", data.length, "features; sample", data[0]) console.log("Got", data.length, "features; sample", data[0])
const changes = new Changes({ const changes = new Changes({
dryRun: new ImmutableStore(true), dryRun: new ImmutableStore(true),
osmConnection: new OsmConnection({ osmConnection: new OsmConnection({
dryRun: new ImmutableStore(true) dryRun: new ImmutableStore(true),
}) }),
}) })
const metakeys = ["id", "version", "changeset", "user", "uid", "timestamp"] const metakeys = ["id", "version", "changeset", "user", "uid", "timestamp"]
const replace = { const replace = {
"phone": "mobile_phone", phone: "mobile_phone",
"phones": "mobile_phone", phones: "mobile_phone",
"mobile": "mobile_phone", mobile: "mobile_phone",
"cellphone": "mobile_phone", cellphone: "mobile_phone",
"pc": "computers", pc: "computers",
"mobile_phones": "mobile_phone", mobile_phones: "mobile_phone",
"mobilephones": "mobile_phone", mobilephones: "mobile_phone",
"mobilephone": "mobile_phone", mobilephone: "mobile_phone",
"clocks": "clock", clocks: "clock",
"elektronik": "electronics", elektronik: "electronics",
"tires": "tyres", tires: "tyres",
"welcome": "yes", welcome: "yes",
"tyre": "tyres", tyre: "tyres",
"electronic_products": "electronics", electronic_products: "electronics",
"shoe": "shoes", shoe: "shoes",
"pc_repairs": "computer", pc_repairs: "computer",
"computers": "computer", computers: "computer",
"body_construction": "body_work", body_construction: "body_work",
"body": "body_work", body: "body_work",
"body_repairer": "body_work", body_repairer: "body_work",
"instruments": "musical_instrument", instruments: "musical_instrument",
"service": "yes", service: "yes",
"punture": "tyres", punture: "tyres",
"electricity": "electronics", electricity: "electronics",
"self_service": "assisted_self_repair", self_service: "assisted_self_repair",
"paint": "bodywork", paint: "bodywork",
"paint shop": "bodywork", "paint shop": "bodywork",
"paint_shop": "bodywork", paint_shop: "bodywork",
"lawnmower": "lawn_mower", lawnmower: "lawn_mower",
"aircon": "air_conditioning", aircon: "air_conditioning",
"*": "yes", "*": "yes",
"ammeublement": "furniture", ammeublement: "furniture",
"all": "yes", all: "yes",
"appliances": "appliance", appliances: "appliance",
"electronic": "electronics", "escooter": "electric_scooter", electronic: "electronics",
escooter: "electric_scooter",
"aviation maintenance, repair, and_overhaul": "airplane", "aviation maintenance, repair, and_overhaul": "airplane",
"aviation_maintenance": "airplanes", aviation_maintenance: "airplanes",
"bags": "bag", bags: "bag",
"boats": "boat", boats: "boat",
"boilers": "boiler", boilers: "boiler",
"breaks": "brakes", breaks: "brakes",
"car": "cars", car: "cars",
"tv": "television", tv: "television",
"clothing": "clothes", clothing: "clothes",
"coat_of_lacquer": "body_work", coat_of_lacquer: "body_work",
"cycle": "bicycle", cycle: "bicycle",
"cars": "car", cars: "car",
"blacharstwo": "tin", "lakiernictwo": "body_work", blacharstwo: "tin",
"tire": "tyres", "powder_coating": "body_work", lakiernictwo: "body_work",
"leather_products": "leather", tire: "tyres",
"motocycle": "motorcycle", powder_coating: "body_work",
"motor": "motorcycle", "motoo": "motorcycle", leather_products: "leather",
"motorbike": "motorcycle", "motorcycle_repair": "motorcycle", "motorsports": "motorcycle", motocycle: "motorcycle",
"printers": "printer", motor: "motorcycle",
"tyres24": "tyres", motoo: "motorcycle",
"paintings": "painting", motorbike: "motorcycle",
"paintwork": "body_work", motorcycle_repair: "motorcycle",
"pumps": "pump", motorsports: "motorcycle",
printers: "printer",
tyres24: "tyres",
paintings: "painting",
paintwork: "body_work",
pumps: "pump",
"shoes:yes": "shoes", "shoes:yes": "shoes",
"wheel": "tyres", wheel: "tyres",
"wheels": "tyres", wheels: "tyres",
"vacuum": "vacuum_cleaner", vacuum: "vacuum_cleaner",
"glass": "car_glassj" glass: "car_glassj",
} }
const brands = ["garage", "audi", "renault", "apple", "honda", "ducati", "ford", "mazda","garage_renault_aie"] const brands = [
"garage",
"audi",
"renault",
"apple",
"honda",
"ducati",
"ford",
"mazda",
"garage_renault_aie",
]
const valid = ["train", "tv", "jewelry", "scooter", ...Object.values(replace), "watch", "oldtimer", "car", "bicycle", "boat", "windbreaker", const valid = [
"agricultural", "alternator", "antiques", "atv", "auto", "train",
"aviation maintenance", "bag", "bags", "tv",
"battery", "bicyle", "borehole", "building", "jewelry",
"camera", "car_glass", "caravan", "scooter",
"carpenter", "coffee_machine", "construction machinery", "cycle", ...Object.values(replace),
"dentures", "ducati", "electric motor", "watch",
"electric_bike", "electric_scooter", "espresso_machines", "exhaust", "oldtimer",
"fire_extinguishers", "fountain_pen", "fridge", "car",
"garden_machinery", "gas appliances", "generator", "bicycle",
"glasses", "golfcart", "guitar", "boat",
"hammock", "hardware", "heating pumps", "windbreaker",
"hifi", "hvac", "installation", "jewellery", "keys", "kick_scooter", "agricultural",
"kitesurfing", "tools", "toys", "tractor", "alternator",
"trailer", "transformer", "truck", "antiques",
"typewriter", "sail", "sewing_machine", "ship", "picture", "pillow", "plastic", "atv",
"cash_register", "cnc", "laptop", "auto",
"aviation maintenance",
"bag",
"bags",
"battery",
"bicyle",
"borehole",
"building",
"camera",
"car_glass",
"caravan",
"carpenter",
"coffee_machine",
"construction machinery",
"cycle",
"dentures",
"ducati",
"electric motor",
"electric_bike",
"electric_scooter",
"espresso_machines",
"exhaust",
"fire_extinguishers",
"fountain_pen",
"fridge",
"garden_machinery",
"gas appliances",
"generator",
"glasses",
"golfcart",
"guitar",
"hammock",
"hardware",
"heating pumps",
"hifi",
"hvac",
"installation",
"jewellery",
"keys",
"kick_scooter",
"kitesurfing",
"tools",
"toys",
"tractor",
"trailer",
"transformer",
"truck",
"typewriter",
"sail",
"sewing_machine",
"ship",
"picture",
"pillow",
"plastic",
"cash_register",
"cnc",
"laptop",
"laundry_machines", "laundry_machines",
"photo_camera", "photocopier", "piano", "photo_camera",
"power_tools", "pressure_gauges", "printer", "photocopier",
, "snowboard", "snowmobile", "starter", "machines", "mainframe", "piano",
"power_tools",
"pressure_gauges",
"printer",
,
"snowboard",
"snowmobile",
"starter",
"machines",
"mainframe",
"outboard_motor", "outboard_motor",
"video", "washing_machine", "ski", "radiator", "video",
"radio", "refrigerator", "washing_machine",
"rv", "ski", "window", "zipper", "weighing_scale", "ski",
"small_electric_vehicle" "radiator",
"radio",
].map(s => s.replace(/ /g, "_")) "refrigerator",
"rv",
"ski",
"window",
"zipper",
"weighing_scale",
"small_electric_vehicle",
].map((s) => s.replace(/ /g, "_"))
const skip = ["yes", "no", "only", "brand", "assisted_self_repair", "only_sold"] const skip = ["yes", "no", "only", "brand", "assisted_self_repair", "only_sold"]
const dloader = new OsmObjectDownloader() const dloader = new OsmObjectDownloader()
const rm = ["50243147100015", "81342677200048", "and overhaul", "repair", "unset", "сервисный_центр", "taller_de_michu", "quitandinha_g_&_a", "mechanika"].map(v => v.replace(/ /g, "_")) const rm = [
"50243147100015",
"81342677200048",
"and overhaul",
"repair",
"unset",
"сервисный_центр",
"taller_de_michu",
"quitandinha_g_&_a",
"mechanika",
].map((v) => v.replace(/ /g, "_"))
const objects: OsmObject[] = [] const objects: OsmObject[] = []
const changesToMake: ChangeDescription [] = [] const changesToMake: ChangeDescription[] = []
const first = GeoOperations.centerpointCoordinates(data[0]) const first = GeoOperations.centerpointCoordinates(data[0])
for (const f of data) { for (const f of data) {
if (GeoOperations.distanceBetween(first, GeoOperations.centerpointCoordinates(f)) > 2500000) { if (
GeoOperations.distanceBetween(first, GeoOperations.centerpointCoordinates(f)) >
2500000
) {
continue continue
} }
let keyRaw = f.properties.repair let keyRaw = f.properties.repair
keyRaw = replace[keyRaw] ?? keyRaw keyRaw = replace[keyRaw] ?? keyRaw
if (brands.some(br => keyRaw.toLowerCase().indexOf(br.trim()) >= 0)) { if (brands.some((br) => keyRaw.toLowerCase().indexOf(br.trim()) >= 0)) {
f.properties.repair = "brand" f.properties.repair = "brand"
} if(skip.indexOf(keyRaw) >= 0){ }
if (skip.indexOf(keyRaw) >= 0) {
f.properties.repair = keyRaw f.properties.repair = keyRaw
} else { } else {
const r = keyRaw
const r = keyRaw.replace(/\/|,/g, ";").split(";").map(k => k.trim().replace(/ /g, "_").toLowerCase()) .replace(/\/|,/g, ";")
.split(";")
.map((k) => k.trim().replace(/ /g, "_").toLowerCase())
for (let key of r) { for (let key of r) {
key = replace[key] ?? key key = replace[key] ?? key
@ -177,9 +278,7 @@ export default class CleanRepair extends Script {
f.properties[key + ":repair"] = "yes" f.properties[key + ":repair"] = "yes"
delete f.properties.repair delete f.properties.repair
} }
} }
if (f.properties.service === "repair") { if (f.properties.service === "repair") {
delete f.properties.service delete f.properties.service
@ -198,34 +297,25 @@ export default class CleanRepair extends Script {
const value = f.properties[key] const value = f.properties[key]
const ct = await new ChangeTagAction(id, new Tag(key, value), f.properties, { const ct = await new ChangeTagAction(id, new Tag(key, value), f.properties, {
changeType: "fix", changeType: "fix",
theme: "script" theme: "script",
}).CreateChangeDescriptions() }).CreateChangeDescriptions()
changesToMake.push(...ct) changesToMake.push(...ct)
console.log(ct.map(cd => cd.tags)) console.log(ct.map((cd) => cd.tags))
if (f.properties.repair === undefined) { if (f.properties.repair === undefined) {
const ct = await new ChangeTagAction(id, new Tag("repair", ""), f.properties, { const ct = await new ChangeTagAction(id, new Tag("repair", ""), f.properties, {
changeType: "fix", changeType: "fix",
theme: "script" theme: "script",
}).CreateChangeDescriptions() }).CreateChangeDescriptions()
changesToMake.push(...ct) changesToMake.push(...ct)
} }
} }
} }
const const changedObjects = changes.CreateChangesetObjects(changesToMake, objects)
changedObjects = changes.CreateChangesetObjects(changesToMake, objects)
const const osc = Changes.createChangesetFor("", changedObjects)
osc = Changes.createChangesetFor("", changedObjects)
writeFileSync(
"Cleanup.osc"
,
osc
,
"utf8"
)
writeFileSync("Cleanup.osc", osc, "utf8")
} }
} }

View file

@ -213,7 +213,7 @@ class IdThief {
continue continue
} }
if(preset.tags["shop"] === "vacant") { if (preset.tags["shop"] === "vacant") {
console.log("Skipping 'vacant'") console.log("Skipping 'vacant'")
continue continue
} }
@ -282,15 +282,15 @@ class IdThief {
} }
} }
class ReadIdPresets extends Script {
class ReadIdPresets extends Script{
constructor() { constructor() {
super("Reads the id-tagging-schema repository and steals the presets; which will be written into 'id_presets.json'\n\nArguments: [path-to-repository] [path-to-target]\n" + super(
"Note that default arguments are used") "Reads the id-tagging-schema repository and steals the presets; which will be written into 'id_presets.json'\n\nArguments: [path-to-repository] [path-to-target]\n" +
"Note that default arguments are used"
)
} }
async main(args: string[]): Promise<void> { async main(args: string[]): Promise<void> {
const targetDir = args[1] ?? "./assets/layers/id_presets/" const targetDir = args[1] ?? "./assets/layers/id_presets/"
const makiThief = new MakiThief( const makiThief = new MakiThief(
@ -345,9 +345,7 @@ class ReadIdPresets extends Script{
] ]
console.log("Writing id presets to", id_presets_path) console.log("Writing id presets to", id_presets_path)
writeFileSync(id_presets_path, JSON.stringify(idPresets, null, " "), "utf8") writeFileSync(id_presets_path, JSON.stringify(idPresets, null, " "), "utf8")
} }
} }
new ReadIdPresets().run() new ReadIdPresets().run()

View file

@ -31,7 +31,7 @@ describe("Tag optimalization", () => {
const t = new And([ const t = new And([
new Tag("foo", "bar"), new Tag("foo", "bar"),
new Or([new Tag("x", "y"), new Tag("a", "b")]), new Or([new Tag("x", "y"), new Tag("a", "b")]),
new Or([new Tag("x", "y"), new Tag("c", "d")]) new Or([new Tag("x", "y"), new Tag("c", "d")]),
]) ])
const opt = <TagsFilter>t.optimize() const opt = <TagsFilter>t.optimize()
expect(TagUtils.toString(opt)).toBe("foo=bar& (x=y| (a=b&c=d) )") expect(TagUtils.toString(opt)).toBe("foo=bar& (x=y| (a=b&c=d) )")
@ -42,7 +42,7 @@ describe("Tag optimalization", () => {
const t = new And([ const t = new And([
new Tag("foo", "bar"), new Tag("foo", "bar"),
new Or([new RegexTag("x", "y"), new RegexTag("a", "b")]), new Or([new RegexTag("x", "y"), new RegexTag("a", "b")]),
new Or([new RegexTag("x", "y"), new RegexTag("c", "d")]) new Or([new RegexTag("x", "y"), new RegexTag("c", "d")]),
]) ])
const opt = <TagsFilter>t.optimize() const opt = <TagsFilter>t.optimize()
expect(TagUtils.toString(opt)).toBe("foo=bar& ( (a=b&c=d) |x=y)") expect(TagUtils.toString(opt)).toBe("foo=bar& ( (a=b&c=d) |x=y)")
@ -53,7 +53,7 @@ describe("Tag optimalization", () => {
const t = new And([ const t = new And([
new Tag("foo", "bar"), new Tag("foo", "bar"),
new Or([new RegexTag("x", "y"), new RegexTag("a", "b")]), new Or([new RegexTag("x", "y"), new RegexTag("a", "b")]),
new Or([new RegexTag("x", "y", true), new RegexTag("c", "d")]) new Or([new RegexTag("x", "y", true), new RegexTag("c", "d")]),
]) ])
const opt = <TagsFilter>t.optimize() const opt = <TagsFilter>t.optimize()
expect(TagUtils.toString(opt)).toBe("foo=bar& (a=b|x=y) & (c=d|x!=y)") expect(TagUtils.toString(opt)).toBe("foo=bar& (a=b|x=y) & (c=d|x!=y)")
@ -86,12 +86,12 @@ describe("Tag optimalization", () => {
{ {
and: [ and: [
{ {
or: ["X=Y", "FOO=BAR"] or: ["X=Y", "FOO=BAR"],
}, },
"bicycle=yes" "bicycle=yes",
] ],
} },
] ],
}) })
// (X=Y | FOO=BAR | (bicycle=yes & (X=Y | FOO=BAR)) ) // (X=Y | FOO=BAR | (bicycle=yes & (X=Y | FOO=BAR)) )
// This is equivalent to (X=Y | FOO=BAR) // This is equivalent to (X=Y | FOO=BAR)
@ -109,11 +109,11 @@ describe("Tag optimalization", () => {
"amenity=charging_station", "amenity=charging_station",
"disused:amenity=charging_station", "disused:amenity=charging_station",
"planned:amenity=charging_station", "planned:amenity=charging_station",
"construction:amenity=charging_station" "construction:amenity=charging_station",
] ],
}, },
"bicycle=yes" "bicycle=yes",
] ],
}, },
{ {
and: [ and: [
@ -122,19 +122,19 @@ describe("Tag optimalization", () => {
"amenity=charging_station", "amenity=charging_station",
"disused:amenity=charging_station", "disused:amenity=charging_station",
"planned:amenity=charging_station", "planned:amenity=charging_station",
"construction:amenity=charging_station" "construction:amenity=charging_station",
] ],
} },
] ],
}, },
"amenity=toilets", "amenity=toilets",
"amenity=bench", "amenity=bench",
"leisure=picnic_table", "leisure=picnic_table",
{ {
and: ["tower:type=observation"] and: ["tower:type=observation"],
}, },
{ {
and: ["amenity=bicycle_repair_station"] and: ["amenity=bicycle_repair_station"],
}, },
{ {
and: [ and: [
@ -143,16 +143,16 @@ describe("Tag optimalization", () => {
"amenity=bicycle_rental", "amenity=bicycle_rental",
"bicycle_rental~*", "bicycle_rental~*",
"service:bicycle:rental=yes", "service:bicycle:rental=yes",
"rental~.*bicycle.*" "rental~.*bicycle.*",
] ],
}, },
"bicycle_rental!=docking_station" "bicycle_rental!=docking_station",
] ],
}, },
{ {
and: ["leisure=playground", "playground!=forest"] and: ["leisure=playground", "playground!=forest"],
} },
] ],
}) })
const opt = <TagsFilter>filter.optimize() const opt = <TagsFilter>filter.optimize()
const expected = [ const expected = [
@ -166,7 +166,7 @@ describe("Tag optimalization", () => {
"planned:amenity=charging_station", "planned:amenity=charging_station",
"tower:type=observation", "tower:type=observation",
"(amenity=bicycle_rental|service:bicycle:rental=yes|bicycle_rental~.+|rental~^(.*bicycle.*)$) &bicycle_rental!=docking_station", "(amenity=bicycle_rental|service:bicycle:rental=yes|bicycle_rental~.+|rental~^(.*bicycle.*)$) &bicycle_rental!=docking_station",
"leisure=playground&playground!=forest" "leisure=playground&playground!=forest",
] ]
expect((<Or>opt).or.map((f) => TagUtils.toString(f))).toEqual(expected) expect((<Or>opt).or.map((f) => TagUtils.toString(f))).toEqual(expected)
@ -184,22 +184,16 @@ describe("Tag optimalization", () => {
it("should optimize comparing tags", () => { it("should optimize comparing tags", () => {
const spec = TagUtils.Tag({ const spec = TagUtils.Tag({
and:[ and: ["x=5", "x>5"],
"x=5",
"x>5"
]
}) })
const opt = spec.optimize() const opt = spec.optimize()
expect(opt).to.eq(false) expect(opt).to.eq(false)
}) })
it("should optimize regexes in the key", () => { it("should optimize regexes in the key", () => {
const spec = TagUtils.Tag({ const spec = TagUtils.Tag({
and: [ and: ["service:bicycle:retail=yes", "service:bicycle:.+~~yes"],
"service:bicycle:retail=yes",
"service:bicycle:.+~~yes"
]
}) })
const tag = <TagsFilter> spec.optimize() const tag = <TagsFilter>spec.optimize()
expect(tag.asJson()).to.eq("service:bicycle:retail=yes") expect(tag.asJson()).to.eq("service:bicycle:retail=yes")
}) })
}) })
@ -208,7 +202,7 @@ describe("Tag optimalization", () => {
it("with nested And which has a common property should be dropped", () => { it("with nested And which has a common property should be dropped", () => {
const t = new Or([ const t = new Or([
new Tag("foo", "bar"), new Tag("foo", "bar"),
new And([new Tag("foo", "bar"), new Tag("x", "y")]) new And([new Tag("foo", "bar"), new Tag("x", "y")]),
]) ])
const opt = <TagsFilter>t.optimize() const opt = <TagsFilter>t.optimize()
expect(TagUtils.toString(opt)).toBe("foo=bar") expect(TagUtils.toString(opt)).toBe("foo=bar")
@ -233,14 +227,14 @@ describe("Tag optimalization", () => {
and: [ and: [
"sport=climbing", "sport=climbing",
{ {
or: ["office~*", "club~*"] or: ["office~*", "club~*"],
} },
] ],
} },
] ],
}) })
const gym_tags = TagUtils.Tag({ const gym_tags = TagUtils.Tag({
and: ["sport=climbing", "leisure=sports_centre"] and: ["sport=climbing", "leisure=sports_centre"],
}) })
const other_climbing = TagUtils.Tag({ const other_climbing = TagUtils.Tag({
and: [ and: [
@ -248,8 +242,8 @@ describe("Tag optimalization", () => {
"climbing!~route", "climbing!~route",
"leisure!~sports_centre", "leisure!~sports_centre",
"climbing!=route_top", "climbing!=route_top",
"climbing!=route_bottom" "climbing!=route_bottom",
] ],
}) })
const together = new Or([club_tags, gym_tags, other_climbing]) const together = new Or([club_tags, gym_tags, other_climbing])
const opt = together.optimize() const opt = together.optimize()
@ -291,7 +285,7 @@ describe("Tag optimalization", () => {
or: [ or: [
"club=climbing", "club=climbing",
{ {
and: ["sport=climbing", { or: ["club~*", "office~*"] }] and: ["sport=climbing", { or: ["club~*", "office~*"] }],
}, },
{ {
and: [ and: [
@ -304,63 +298,109 @@ describe("Tag optimalization", () => {
"climbing!~route", "climbing!~route",
"climbing!=route_top", "climbing!=route_top",
"climbing!=route_bottom", "climbing!=route_bottom",
"leisure!~sports_centre" "leisure!~sports_centre",
] ],
} },
] ],
} },
] ],
} },
] ],
}) })
) )
}) })
it("should optimize a complicated nested case", () => { it("should optimize a complicated nested case", () => {
const spec = { const spec = {
"and": and: [
["service:bicycle:retail=yes", "service:bicycle:retail=yes",
{ {
"or": [ or: [
{ {
"and": [ and: [
{ "or": ["shop=outdoor", "shop=sport", "shop=diy", "shop=doityourself"] }, {
{ or: [
"or": ["service:bicycle:repair=yes", "shop=bicycle", "shop=outdoor",
{ "shop=sport",
"and": ["shop=sports", "shop=diy",
{ "or": ["sport=bicycle", "sport=cycling", "sport="] }, "shop=doityourself",
"service:bicycle:retail!=no", ],
"service:bicycle:repair!=no"] },
}] {
}] or: [
}, { "service:bicycle:repair=yes",
"and": "shop=bicycle",
[
{ {
"or": and: [
["shop=outdoor", "shop=sport", "shop=diy", "shop=doityourself"] "shop=sports",
},
{
"or": ["service:bicycle:repair=yes", "shop=bicycle",
{ {
"and": ["shop=sports", or: [
{ "or": ["sport=bicycle", "sport=cycling", "sport="] }, "sport=bicycle",
"service:bicycle:retail!=no", "service:bicycle:repair!=no"] "sport=cycling",
}] "sport=",
}] ],
}, { },
"and": "service:bicycle:retail!=no",
[{ "service:bicycle:repair!=no",
"or": ],
["craft=shoe_repair", "craft=key_cutter", "shop~.+"] },
}, ],
{ "or": ["shop=outdoor", "shop=sport", "shop=diy", "shop=doityourself"] }, },
"shop!=mall"] ],
}, },
"service:bicycle:retail~.+", {
"service:bicycle:retail~.+"] and: [
}] {
or: [
"shop=outdoor",
"shop=sport",
"shop=diy",
"shop=doityourself",
],
},
{
or: [
"service:bicycle:repair=yes",
"shop=bicycle",
{
and: [
"shop=sports",
{
or: [
"sport=bicycle",
"sport=cycling",
"sport=",
],
},
"service:bicycle:retail!=no",
"service:bicycle:repair!=no",
],
},
],
},
],
},
{
and: [
{
or: ["craft=shoe_repair", "craft=key_cutter", "shop~.+"],
},
{
or: [
"shop=outdoor",
"shop=sport",
"shop=diy",
"shop=doityourself",
],
},
"shop!=mall",
],
},
"service:bicycle:retail~.+",
"service:bicycle:retail~.+",
],
},
],
} }
const tag = TagUtils.Tag(spec) const tag = TagUtils.Tag(spec)