Update tag totals, sort title tags by popularity to give the most precise title

This commit is contained in:
Pieter Vander Vennet 2023-12-04 16:10:05 +01:00
parent baf858bc21
commit 3135b83598
7 changed files with 485 additions and 213 deletions

View file

@ -62,6 +62,7 @@
"downloadGpx": "Download your favourites as GPX", "downloadGpx": "Download your favourites as GPX",
"intro": "You marked {length} locations as a favourite location.", "intro": "You marked {length} locations as a favourite location.",
"introPrivacy": "This list is only visible to you", "introPrivacy": "This list is only visible to you",
"loginToSeeList": "Login to see the list of locations you marked as favourite",
"tab": "Your favourites", "tab": "Your favourites",
"title": "Your favourite locations" "title": "Your favourite locations"
}, },

View file

@ -13,7 +13,7 @@ import { TagConfigJson } from "../src/Models/ThemeConfig/Json/TagConfigJson"
import { TagUtils } from "../src/Logic/Tags/TagUtils" import { TagUtils } from "../src/Logic/Tags/TagUtils"
import { TagRenderingConfigJson } from "../src/Models/ThemeConfig/Json/TagRenderingConfigJson" import { TagRenderingConfigJson } from "../src/Models/ThemeConfig/Json/TagRenderingConfigJson"
import { Translatable } from "../src/Models/ThemeConfig/Json/Translatable" import { Translatable } from "../src/Models/ThemeConfig/Json/Translatable"
import icons from "../src/assets/generated/layers/icons.json"
export class GenerateFavouritesLayer extends Script { export class GenerateFavouritesLayer extends Script {
private readonly layers: LayerConfigJson[] = [] private readonly layers: LayerConfigJson[] = []
@ -40,6 +40,19 @@ export class GenerateFavouritesLayer extends Script {
} }
} }
private sortMappings(mappings: MappingConfigJson[]): MappingConfigJson[] {
const sortedMappings: MappingConfigJson[] = [...mappings]
sortedMappings.sort((a, b) => {
const aTag = TagUtils.Tag(a.if)
const bTag = TagUtils.Tag(b.if)
const aPop = TagUtils.GetPopularity(aTag)
const bPop = TagUtils.GetPopularity(bTag)
console.log("Comparing", a.if, "with", b.if, { aPop, bPop })
return aPop - bPop
})
return sortedMappings
}
private addTagRenderings(proto: LayerConfigJson) { private addTagRenderings(proto: LayerConfigJson) {
const blacklistedIds = new Set([ const blacklistedIds = new Set([
"images", "images",
@ -96,7 +109,7 @@ export class GenerateFavouritesLayer extends Script {
continue continue
} }
newTr.condition = { newTr.condition = {
and: Utils.NoNull([(newTr.condition, layerConfig.source["osmTags"])]), and: Utils.NoNull([newTr.condition, layerConfig.source["osmTags"]]),
} }
generatedTagRenderings.push(newTr) generatedTagRenderings.push(newTr)
blacklistedIds.add(newTr.id) blacklistedIds.add(newTr.id)
@ -181,7 +194,7 @@ export class GenerateFavouritesLayer extends Script {
} }
private addTitle(proto: LayerConfigJson) { private addTitle(proto: LayerConfigJson) {
const mappings: MappingConfigJson[] = [] let mappings: MappingConfigJson[] = []
for (const layer of this.layers) { for (const layer of this.layers) {
const t = layer.title const t = layer.title
const tags: TagConfigJson = layer.source["osmTags"] const tags: TagConfigJson = layer.source["osmTags"]
@ -238,6 +251,8 @@ export class GenerateFavouritesLayer extends Script {
} }
} }
mappings = this.sortMappings(mappings)
if (proto.title["mappings"]) { if (proto.title["mappings"]) {
mappings.unshift(...proto.title["mappings"]) mappings.unshift(...proto.title["mappings"])
} }
@ -248,6 +263,14 @@ export class GenerateFavouritesLayer extends Script {
}) })
} }
for (const mapping of mappings) {
const opt = TagUtils.optimzeJson(mapping.if)
if (typeof opt === "boolean") {
continue
}
mapping.if = opt
}
proto.title = { proto.title = {
mappings, mappings,
} }

View file

@ -4,6 +4,8 @@ import { TagUtils } from "../src/Logic/Tags/TagUtils"
import { Utils } from "../src/Utils" import { Utils } from "../src/Utils"
import { writeFileSync } from "fs" import { writeFileSync } from "fs"
import ScriptUtils from "./ScriptUtils" import ScriptUtils from "./ScriptUtils"
import TagRenderingConfig from "../src/Models/ThemeConfig/TagRenderingConfig"
import { And } from "../src/Logic/Tags/And"
/* Downloads stats on osmSource-tags and keys from tagInfo */ /* Downloads stats on osmSource-tags and keys from tagInfo */
@ -21,7 +23,12 @@ async function main(includeTags = true) {
continue continue
} }
const sources = TagUtils.Tag(layer.source["osmTags"]) const sourcesList = [TagUtils.Tag(layer.source["osmTags"])]
if (layer?.title) {
sourcesList.push(...new TagRenderingConfig(layer.title).usedTags())
}
const sources = new And(sourcesList)
const allKeys = sources.usedKeys() const allKeys = sources.usedKeys()
for (const key of allKeys) { for (const key of allKeys) {
if (!keysAndTags.has(key)) { if (!keysAndTags.has(key)) {
@ -68,6 +75,8 @@ async function main(includeTags = true) {
"./src/assets/key_totals.json", "./src/assets/key_totals.json",
JSON.stringify( JSON.stringify(
{ {
"#": "Generated with generateStats.ts",
date: new Date().toISOString(),
keys: Utils.MapToObj(keyTotal, (t) => t), keys: Utils.MapToObj(keyTotal, (t) => t),
tags: Utils.MapToObj(tagTotal, (v) => Utils.MapToObj(v, (t) => t)), tags: Utils.MapToObj(tagTotal, (v) => Utils.MapToObj(v, (t) => t)),
}, },

View file

@ -298,7 +298,7 @@ export class RegexTag extends TagsFilter {
if (typeof this.key === "string") { if (typeof this.key === "string") {
return [this.key] return [this.key]
} }
throw "Key cannot be determined as it is a regex" return []
} }
usedTags(): { key: string; value: string }[] { usedTags(): { key: string; value: string }[] {

View file

@ -869,6 +869,27 @@ export class TagUtils {
return TagUtils.keyCounts.keys[key] return TagUtils.keyCounts.keys[key]
} }
public static GetPopularity(tag: TagsFilter): number | undefined {
if (tag instanceof And) {
return Math.min(...Utils.NoNull(tag.and.map((t) => TagUtils.GetPopularity(t))))
}
if (tag instanceof Or) {
return Math.max(...Utils.NoNull(tag.or.map((t) => TagUtils.GetPopularity(t))))
}
if (tag instanceof Tag) {
return TagUtils.GetCount(tag.key, tag.value)
}
if (tag instanceof RegexTag) {
const key = tag.key
if (key instanceof RegExp || tag.invert || tag.isNegative()) {
return undefined
}
return TagUtils.GetCount(key)
}
return undefined
}
private static order(a: TagsFilter, b: TagsFilter, usePopularity: boolean): number { private static order(a: TagsFilter, b: TagsFilter, usePopularity: boolean): number {
const rta = a instanceof RegexTag const rta = a instanceof RegexTag
const rtb = b instanceof RegexTag const rtb = b instanceof RegexTag

View file

@ -16,10 +16,10 @@ import {
} from "./Json/QuestionableTagRenderingConfigJson" } from "./Json/QuestionableTagRenderingConfigJson"
import { FixedUiElement } from "../../UI/Base/FixedUiElement" import { FixedUiElement } from "../../UI/Base/FixedUiElement"
import { Paragraph } from "../../UI/Base/Paragraph" import { Paragraph } from "../../UI/Base/Paragraph"
import Svg from "../../Svg"
import Validators, { ValidatorType } from "../../UI/InputElement/Validators" import Validators, { ValidatorType } from "../../UI/InputElement/Validators"
import { TagRenderingConfigJson } from "./Json/TagRenderingConfigJson" import { TagRenderingConfigJson } from "./Json/TagRenderingConfigJson"
import Constants from "../Constants" import Constants from "../Constants"
import { RegexTag } from "../../Logic/Tags/RegexTag"
export interface Icon {} export interface Icon {}
@ -800,4 +800,25 @@ export default class TagRenderingConfig {
labels, labels,
]).SetClass("flex flex-col") ]).SetClass("flex flex-col")
} }
public usedTags(): TagsFilter[] {
const tags: TagsFilter[] = []
tags.push(
this.metacondition,
this.condition,
this.freeform?.key ? new RegexTag(this.freeform?.key, /.*/) : undefined,
this.invalidValues
)
for (const m of this.mappings ?? []) {
tags.push(m.if)
tags.push(m.priorityIf)
tags.push(...(m.addExtraTags ?? []))
if (typeof m.hideInAnswer !== "boolean") {
tags.push(m.hideInAnswer)
}
tags.push(m.ifnot)
}
return Utils.NoNull(tags)
}
} }

View file

@ -1,229 +1,426 @@
{ {
"#": "Generated with generateStats.ts",
"date": "2023-12-04T14:42:01.299Z",
"keys": { "keys": {
"addr:street": 117211930, "FIXME": 119237,
"addr:housenumber": 125040768, "access": 20023328,
"emergency": 1939478, "addr:housenumber": 146524978,
"barrier": 18424246, "addr:street": 137485111,
"tourism": 2683525, "advertising": 158347,
"amenity": 20541353, "amenity": 25340913,
"bench": 894256, "area": 1803451,
"rental": 8838, "association": 757,
"bicycle_rental": 7447, "barrier": 23634152,
"vending": 206755, "bench": 1300789,
"service:bicycle:rental": 3570, "bicycle": 7507086,
"pub": 316, "bicycle_rental": 26948,
"theme": 426, "boundary": 2366033,
"service:bicycle:.*": 0, "brand": 2317628,
"service:bicycle:cleaning": 807, "building": 585543589,
"shop": 5062252, "camera:direction": 61201,
"service:bicycle:retail": 9162, "climbing": 9051,
"network": 2181336, "club": 53046,
"sport": 2194801, "construction:amenity": 1943,
"service:bicycle:repair": 11381, "conveying": 27311,
"association": 369, "craft": 296376,
"ngo": 42, "crossing": 8736722,
"leisure": 7368076, "cyclestreet": 12505,
"club": 38429, "cycleway": 1016837,
"disused:amenity": 40880, "direction": 2978834,
"planned:amenity": 205, "disused:amenity": 63413,
"tileId": 0, "dog": 95086,
"construction:amenity": 1206, "door": 280843,
"cycleway": 906487, "drinking_water": 136067,
"highway": 218189453, "emergency": 2542692,
"bicycle": 6218071, "entrance": 3769592,
"cyclestreet": 8185, "fixme": 1746318,
"camera:direction": 40676, "footway": 7540651,
"direction": 1896015, "generator:source": 2387982,
"access": 16030036, "healthcare": 790125,
"entrance": 2954076, "highway": 249307936,
"name:etymology": 24485, "indoor": 562051,
"memorial": 132172, "information": 1073014,
"indoor": 353116, "isced:2011:level": 27,
"name:etymology:wikidata": 285224, "isced:level:2011": 74,
"landuse": 35524214, "landuse": 41730047,
"name": 88330405, "leisure": 8955744,
"protect_class": 73801, "man_made": 6799900,
"information": 831513, "memorial": 209327,
"man_made": 5116088, "motorcar": 621864,
"boundary": 2142378, "name": 98684655,
"tower:type": 451658, "name:etymology": 56375,
"playground": 109175, "name:etymology:wikidata": 1174439,
"route": 939184, "name:nl": 80468,
"surveillance:type": 116760, "natural": 64176097,
"natural": 52353504, "ngo": 57,
"building": 500469053 "office": 1092855,
"parking_space": 600707,
"planned:amenity": 237,
"playground": 182188,
"post_office": 16379,
"protect_class": 83815,
"pub": 324,
"public_transport": 5111577,
"railway": 7068070,
"recycling_type": 385569,
"ref": 18607577,
"rental": 13611,
"route": 1075802,
"service:bicycle:cleaning": 1179,
"service:bicycle:pump": 14053,
"service:bicycle:pump:operational_status": 344,
"service:bicycle:rental": 4599,
"service:bicycle:repair": 15470,
"service:bicycle:retail": 11467,
"service:bicycle:tools": 6227,
"shelter": 1647743,
"shop": 5860878,
"species": 1656206,
"species:wikidata": 107778,
"sport": 2580042,
"subject": 40076,
"surface:colour": 17851,
"surveillance:type": 171923,
"theme": 906,
"toilets": 90842,
"tourism": 3211694,
"tower:type": 596349,
"type": 11757856,
"vending": 252016
}, },
"tags": { "tags": {
"emergency": { "advertising": {
"defibrillator": 51273, "billboard": 76420,
"ambulance_station": 11047, "board": 15040,
"fire_extinguisher": 7355, "column": 21212,
"fire_hydrant": 1598739 "flag": 4264,
}, "poster_box": 22932,
"barrier": { "screen": 1352,
"cycle_barrier": 104166, "sculpture": 145,
"bollard": 502220, "sign": 6172,
"wall": 3535056 "tarp": 407,
}, "totem": 7097,
"tourism": { "wall_painting": 132
"artwork": 187470,
"map": 51,
"viewpoint": 191765
}, },
"amenity": { "amenity": {
"bench": 1736979, "animal_shelter": 6056,
"bicycle_library": 36, "atm": 207899,
"bicycle_rental": 49082, "bank": 389470,
"vending_machine": 201871, "bar": 219208,
"bar": 199662, "bench": 2313183,
"pub": 174979, "bicycle_library": 46,
"cafe": 467521, "bicycle_parking": 616881,
"restaurant": 1211671, "bicycle_rental": 63710,
"bicycle_wash": 44, "bicycle_repair_station": 14026,
"bike_wash": 0, "bicycle_wash": 79,
"bicycle_repair_station": 9247, "biergarten": 10323,
"bicycle_parking": 435959, "bike_wash": 1,
"binoculars": 479, "binoculars": 1109,
"biergarten": 10309, "cafe": 530066,
"charging_station": 65402, "car_rental": 26726,
"drinking_water": 250463, "charging_station": 111996,
"fast_food": 460079, "childcare": 50390,
"fire_station": 122200, "clinic": 179739,
"parking": 4255206, "clock": 25274,
"public_bookcase": 13120, "college": 64379,
"toilets": 350648, "dentist": 122076,
"recycling": 333925, "doctors": 166850,
"waste_basket": 550357, "drinking_water": 294750,
"waste_disposal": 156765 "fast_food": 533335,
}, "fire_station": 131842,
"bench": { "hospital": 204756,
"stand_up_bench": 87, "ice_cream": 48853,
"yes": 524993 "kindergarten": 294441,
}, "nightclub": 22779,
"service:bicycle:rental": { "parcel_locker": 44270,
"yes": 3054 "parking": 5158899,
}, "parking_space": 2292063,
"pub": { "pharmacy": 383181,
"cycling": 9, "post_box": 370286,
"bicycle": 0 "post_office": 198908,
}, "pub": 185475,
"theme": { "public_bookcase": 21608,
"cycling": 8, "reception_desk": 2426,
"bicycle": 16 "recycling": 417512,
}, "restaurant": 1346895,
"service:bicycle:cleaning": { "school": 1286594,
"yes": 607, "shelter": 494594,
"diy": 0 "shower": 27029,
}, "ticket_validator": 7730,
"shop": { "toilets": 417991,
"bicycle": 46488, "university": 54299,
"sports": 37024 "vending_machine": 247257,
}, "veterinary": 52813,
"sport": { "waste_basket": 759718,
"cycling": 6045, "waste_disposal": 219245
"bicycle": 96
}, },
"association": { "association": {
"cycling": 5, "bicycle": 47,
"bicycle": 20 "cycling": 5
}, },
"ngo": { "barrier": {
"cycling": 0, "bollard": 668017,
"bicycle": 0 "cycle_barrier": 122201,
"kerb": 1178769,
"retaining_wall": 472454,
"wall": 4448788
}, },
"leisure": { "bench": {
"bird_hide": 5669, "stand_up_bench": 212,
"nature_reserve": 117016, "yes": 778144
"picnic_table": 206322,
"pitch": 1990293,
"playground": 705102
},
"club": {
"cycling": 3,
"bicycle": 49
},
"disused:amenity": {
"charging_station": 164
},
"planned:amenity": {
"charging_station": 115
},
"construction:amenity": {
"charging_station": 221
},
"cycleway": {
"lane": 314576,
"track": 86541,
"shared_lane": 60824
},
"highway": {
"residential": 61321708,
"crossing": 6119521,
"cycleway": 1423789,
"traffic_signals": 1512639,
"tertiary": 7051727,
"unclassified": 15756878,
"secondary": 4486617,
"primary": 3110552,
"footway": 16496620,
"path": 11438303,
"steps": 1327396,
"corridor": 27051,
"pedestrian": 685989,
"bridleway": 102280,
"track": 22670967,
"living_street": 1519108,
"street_lamp": 2811705
}, },
"bicycle": { "bicycle": {
"designated": 1110839 "designated": 1499247,
}, "no": 1614544,
"cyclestreet": { "yes": 3753651
"yes": 8164
},
"access": {
"public": 6222,
"yes": 1363526
},
"memorial": {
"ghost_bike": 503
},
"indoor": {
"door": 9722
},
"landuse": {
"grass": 4898559,
"village_green": 104681
},
"name": {
"Park Oude God": 1
},
"information": {
"board": 242007,
"map": 85912,
"office": 24139,
"visitor_centre": 285
},
"man_made": {
"surveillance": 148172,
"watermill": 9699
}, },
"boundary": { "boundary": {
"protected_area": 97075 "protected_area": 111282
}, },
"tower:type": { "climbing": {
"observation": 19654 "area": 191,
"crag": 2873,
"route": 1040,
"site": 14
}, },
"playground": { "club": {
"forest": 56 "bicycle": 60,
"climbing": 1,
"cycling": 7
}, },
"surveillance:type": { "construction:amenity": {
"camera": 112963, "charging_station": 259
"ALPR": 2522, },
"ANPR": 3 "conveying": {
"yes": 12153
},
"craft": {
"key_cutter": 3711,
"shoe_repair": 64
},
"crossing": {
"traffic_signals": 1408141
},
"cyclestreet": {
"yes": 12480
},
"cycleway": {
"lane": 300810,
"shared_lane": 71051,
"track": 77166
},
"disused:amenity": {
"charging_station": 289,
"drinking_water": 2758
},
"dog": {
"unleashed": 727
},
"drinking_water": {
"yes": 74561
},
"emergency": {
"ambulance_station": 13020,
"defibrillator": 80699,
"fire_extinguisher": 11605,
"fire_hydrant": 1928477
},
"footway": {
"crossing": 3111184
},
"generator:source": {
"wind": 390537
},
"healthcare": {
"physiotherapist": 17548
},
"highway": {
"bridleway": 107507,
"bus_stop": 3459595,
"corridor": 46847,
"crossing": 8505991,
"cycleway": 1693405,
"elevator": 39221,
"footway": 21573091,
"living_street": 1753722,
"motorway": 1182914,
"motorway_link": 829035,
"path": 13690001,
"pedestrian": 767066,
"primary": 3462637,
"primary_link": 433106,
"residential": 65553821,
"secondary": 5008689,
"secondary_link": 340521,
"service": 54202864,
"speed_camera": 61915,
"speed_display": 2621,
"steps": 1618344,
"street_lamp": 3879570,
"tertiary": 7809143,
"tertiary_link": 245867,
"track": 25718176,
"traffic_signals": 1709993,
"trunk": 1679773,
"trunk_link": 519826,
"unclassified": 16914480
},
"indoor": {
"area": 25332,
"corridor": 17609,
"door": 19157,
"level": 4253,
"room": 157006,
"wall": 32366
},
"information": {
"board": 321201,
"guidepost": 520873,
"map": 108166,
"office": 27749,
"route_marker": 59596,
"visitor_centre": 523
},
"isced:level:2011": {
"early_childhood": 0
},
"landuse": {
"village_green": 102589
},
"leisure": {
"bird_hide": 6607,
"dog_park": 21993,
"fitness_centre": 72920,
"fitness_station": 62923,
"hackerspace": 1537,
"nature_reserve": 129575,
"park": 1168747,
"picnic_table": 302582,
"pitch": 2307262,
"playground": 821692,
"sports_centre": 231823,
"track": 124600
},
"man_made": {
"surveillance": 205953
},
"memorial": {
"ghost_bike": 748,
"plaque": 45536
},
"motorcar": {
"no": 270350,
"yes": 190966
}, },
"natural": { "natural": {
"tree": 18245059 "cliff": 761375,
"rock": 229114,
"stone": 52141,
"tree": 23309774
},
"ngo": {
"bicycle": 0,
"cycling": 0
},
"office": {
"government": 250353
},
"parking_space": {
"disabled": 161162
},
"planned:amenity": {
"charging_station": 72
},
"playground": {
"forest": 77
},
"post_office": {
"post_partner": 7560
},
"pub": {
"bicycle": 0,
"cycling": 12
},
"public_transport": {
"platform": 3254387
},
"railway": {
"platform": 167408
},
"recycling_type": {
"centre": 29508,
"container": 355016
},
"route": {
"bus": 272174
},
"service:bicycle:cleaning": {
"diy": 4,
"yes": 909
},
"service:bicycle:pump": {
"no": 1548,
"yes": 12452
},
"service:bicycle:pump:operational_status": {
"broken": 122
},
"service:bicycle:rental": {
"yes": 3902
},
"service:bicycle:repair": {
"yes": 15134
},
"service:bicycle:tools": {
"no": 354,
"yes": 5872
},
"shelter": {
"yes": 884942
},
"shop": {
"bicycle": 51336,
"bicycle_rental": 1,
"rental": 5206,
"sports": 40802
},
"sport": {
"bicycle": 114,
"climbing": 29028,
"cycling": 8225
},
"surface:colour": {
"rainbow": 217
},
"surveillance:type": {
"ALPR": 4424,
"ANPR": 3,
"camera": 165247
},
"theme": {
"bicycle": 16,
"cycling": 7
},
"toilets": {
"yes": 70811
},
"tourism": {
"artwork": 245861,
"hotel": 407208,
"map": 51,
"viewpoint": 219932
},
"tower:type": {
"observation": 23057
},
"type": {
"route": 1005677
},
"vending": {
"elongated_coin": 816,
"parcel_pickup;parcel_mail_in": 522,
"parking_tickets": 70753,
"public_transport_tickets": 26895
} }
} }
} }