From 1858cdac955b22b143f9342081010c083f0e39d5 Mon Sep 17 00:00:00 2001 From: Robin van der Linde Date: Mon, 17 Jul 2023 20:25:19 +0200 Subject: [PATCH] Create currency metatagger --- assets/layers/questions/questions.json | 89 +++++++------------ .../themes/elongated_coin/elongated_coin.json | 41 +++++++-- package-lock.json | 15 +++- package.json | 1 + src/Logic/SimpleMetaTagger.ts | 45 ++++++++++ 5 files changed, 125 insertions(+), 66 deletions(-) diff --git a/assets/layers/questions/questions.json b/assets/layers/questions/questions.json index 1bdd43127..58e8131c0 100644 --- a/assets/layers/questions/questions.json +++ b/assets/layers/questions/questions.json @@ -1105,26 +1105,7 @@ }, { "or": [ - "_country=at", - "_country=be", - "_country=cy", - "_country=de", - "_country=ee", - "_country=es", - "_country=fi", - "_country=fr", - "_country=gr", - "_country=hr", - "_country=ie", - "_country=it", - "_country=lt", - "_country=lu", - "_country=lv", - "_country=mt", - "_country=nl", - "_country=pt", - "_country=si", - "_country=sk" + "_currency=EUR" ] } ] @@ -1156,7 +1137,8 @@ "es": "Se aceptan monedas de 1 céntimo", "cs": "Jsou přijímány mince v hodnotě 1 centu", "id": "1 koin sen diterima" - } + }, + "hideInAnswer": "_currency!~.*EUR.*" }, { "if": "payment:coins:denominations=0.02 EUR", @@ -1172,7 +1154,8 @@ "es": "Se aceptan monedas de 2 céntimos", "cs": "Jsou přijímány mince v hodnotě 2 centů", "id": "Koin 2 sen diterima" - } + }, + "hideInAnswer": "_currency!~.*EUR.*" }, { "if": "payment:coins:denominations=0.05 EUR", @@ -1188,7 +1171,8 @@ "es": "Se aceptan monedas de 5 céntimos", "cs": "Jsou přijímány mince v hodnotě 5 centů", "id": "Koin 5 sen diterima" - } + }, + "hideInAnswer": "_currency!~.*EUR.*" }, { "if": "payment:coins:denominations=0.10 EUR", @@ -1204,7 +1188,8 @@ "es": "Se aceptan monedas de 10 céntimos", "cs": "Jsou přijímány mince v hodnotě 10 centů", "id": "Koin 10 sen diterima" - } + }, + "hideInAnswer": "_currency!~.*EUR.*" }, { "if": "payment:coins:denominations=0.20 EUR", @@ -1220,7 +1205,8 @@ "es": "Se aceptan monedas de 20 céntimos", "cs": "Jsou přijímány mince v hodnotě 20 centů", "id": "Koin 20 sen diterima" - } + }, + "hideInAnswer": "_currency!~.*EUR.*" }, { "if": "payment:coins:denominations=0.50 EUR", @@ -1236,7 +1222,8 @@ "es": "Se aceptan monedas de 50 céntimos", "cs": "Jsou přijímány mince v hodnotě 50 centů", "id": "Koin 50 sen diterima" - } + }, + "hideInAnswer": "_currency!~.*EUR.*" }, { "if": "payment:coins:denominations=1 EUR", @@ -1251,7 +1238,8 @@ "ca": "S'accepten monedes de 1 euro", "es": "Se aceptan monedas de 1 euro", "cs": "Jsou přijímány mince v hodnotě 1 eura" - } + }, + "hideInAnswer": "_currency!~.*EUR.*" }, { "if": "payment:coins:denominations=2 EUR", @@ -1266,7 +1254,8 @@ "ca": "S'accepten monedes de 2 euros", "es": "Se aceptan monedas de 2 euros", "cs": "Jsou přijímány mince v hodnotě 2 euro" - } + }, + "hideInAnswer": "_currency!~.*EUR.*" } ] }, @@ -1282,26 +1271,7 @@ }, { "or": [ - "_country=at", - "_country=be", - "_country=cy", - "_country=de", - "_country=ee", - "_country=es", - "_country=fi", - "_country=fr", - "_country=gr", - "_country=hr", - "_country=ie", - "_country=it", - "_country=lt", - "_country=lu", - "_country=lv", - "_country=mt", - "_country=nl", - "_country=pt", - "_country=si", - "_country=sk" + "_currency=EUR" ] } ] @@ -1330,7 +1300,8 @@ "cs": "Jsou přijímány bankovky v hodnotě 5 euro", "ca": "S'accepten billets de 5 euros", "fr": "Les billets de 5 euros ne sont pas acceptés" - } + }, + "hideInAnswer": "_currency!~.*EUR.*" }, { "if": "payment:notes:denominations=10 EUR", @@ -1344,7 +1315,8 @@ "cs": "Jsou přijímány bankovky v hodnotě 10 euro", "ca": "S'accepten bitllets de 10 euros", "fr": "Les billets de 10 euros sont acceptés" - } + }, + "hideInAnswer": "_currency!~.*EUR.*" }, { "if": "payment:notes:denominations=20 EUR", @@ -1358,7 +1330,8 @@ "cs": "Jsou přijímány bankovky v hodnotě 20 euro", "ca": "S'accepten bitllets de 20 euros", "fr": "Les billets de 20 euros sont acceptés" - } + }, + "hideInAnswer": "_currency!~.*EUR.*" }, { "if": "payment:notes:denominations=50 EUR", @@ -1372,7 +1345,8 @@ "cs": "Jsou přijímány bankovky v hodnotě 50 euro", "ca": "S'accepten bitllets de 50 euros", "fr": "Les billets de 50 euros sont acceptés" - } + }, + "hideInAnswer": "_currency!~.*EUR.*" }, { "if": "payment:notes:denominations=100 EUR", @@ -1386,7 +1360,8 @@ "cs": "Jsou přijímány bankovky v hodnotě 100 euro", "ca": "S'accepten bitllets de 100 euros", "fr": "Les billets de 100 euros sont acceptés" - } + }, + "hideInAnswer": "_currency!~.*EUR.*" }, { "if": "payment:notes:denominations=200 EUR", @@ -1400,7 +1375,8 @@ "cs": "Jsou přijímány bankovky v hodnotě 200 euro", "ca": "S'accepten bitllets de 200 euros", "fr": "Les billets de 200 euros sont acceptés" - } + }, + "hideInAnswer": "_currency!~.*EUR.*" }, { "if": "payment:notes:denominations=500 EUR", @@ -1414,7 +1390,8 @@ "cs": "Jsou přijímány bankovky v hodnotě 500 euro", "ca": "S'accepten bitllets de 500 euros", "fr": "Les billets de 500 euros sont acceptés" - } + }, + "hideInAnswer": "_currency!~.*EUR.*" } ] }, @@ -2175,4 +2152,4 @@ ] } ] -} +} \ No newline at end of file diff --git a/assets/themes/elongated_coin/elongated_coin.json b/assets/themes/elongated_coin/elongated_coin.json index 086a40daa..0c3d5fcf5 100644 --- a/assets/themes/elongated_coin/elongated_coin.json +++ b/assets/themes/elongated_coin/elongated_coin.json @@ -6,7 +6,6 @@ "description": { "en": "Find penny presses to create your own elongated coins." }, - "hideFromOverview": true, "icon": "./assets/themes/elongated_coin/penny.svg", "layers": [ { @@ -80,6 +79,13 @@ "question": { "en": "What coin is used for pressing?" }, + "freeform": { + "key": "coin:type", + "type": "string", + "placeholder": { + "en": "Coin type (e.g. 10cent)" + } + }, "mappings": [ { "if": "coin:type=2cent", @@ -98,14 +104,31 @@ "then": { "en": "This penny press uses a 10 cent coin for pressing." } + }, + { + "if": "coin:type=25cent", + "then": { + "en": "This penny press uses a 25 cent coin for pressing." + }, + "hideInAnswer": "_currency!~.*USD.*" + }, + { + "if": "coin:type=50cent", + "then": { + "en": "This penny press uses a 50 cent coin for pressing." + }, + "hideInAnswer": "_currency!~.*USD.*" } - ] + ], + "render": { + "en": "This penny press uses a {coin:type} coin for pressing." + } }, "website", { "id": "charge", "question": { - "en": "How much does it cost to press a penny?" + "en": "How much does it cost to press a coin?" }, "freeform": { "key": "charge", @@ -117,18 +140,20 @@ { "if": "charge=1 EUR", "then": { - "en": "It costs 1 euro to press a penny." - } + "en": "It costs 1 euro to press a coin." + }, + "hideInAnswer": "_currency!~.*EUR.*" }, { "if": "charge=2 EUR", "then": { - "en": "It costs 2 euros to press a penny." - } + "en": "It costs 2 euros to press a coin." + }, + "hideInAnswer": "_currency!~.*EUR.*" } ], "render": { - "en": "It costs {charge} to press a penny." + "en": "It costs {charge} to press a coin." } }, "denominations-coins", diff --git a/package-lock.json b/package-lock.json index 6d695a8ba..69493ba47 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "mapcomplete", - "version": "0.30.9", + "version": "0.31.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "mapcomplete", - "version": "0.30.9", + "version": "0.31.0", "license": "GPL-3.0-or-later", "dependencies": { "@rgossiaux/svelte-headlessui": "^1.0.2", @@ -21,6 +21,7 @@ "@types/showdown": "^2.0.0", "chart.js": "^3.8.0", "country-language": "^0.1.7", + "country-to-currency": "^1.0.10", "csv-parse": "^5.1.0", "doctest-ts-improved": "^0.8.8", "email-validator": "^2.0.4", @@ -4907,6 +4908,11 @@ "node": "*" } }, + "node_modules/country-to-currency": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/country-to-currency/-/country-to-currency-1.0.10.tgz", + "integrity": "sha512-M/RiNYiJ2Xp1okxqlINc/aTPXbxeYItgd0xTD4dtxREce8vjRqV3Vehrulcy8IimV/Of0wG5f//YSJp4KyGZFA==" + }, "node_modules/create-require": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", @@ -16028,6 +16034,11 @@ "underscore.deep": "~0.5.1" } }, + "country-to-currency": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/country-to-currency/-/country-to-currency-1.0.10.tgz", + "integrity": "sha512-M/RiNYiJ2Xp1okxqlINc/aTPXbxeYItgd0xTD4dtxREce8vjRqV3Vehrulcy8IimV/Of0wG5f//YSJp4KyGZFA==" + }, "create-require": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", diff --git a/package.json b/package.json index 6c36d1f20..634428003 100644 --- a/package.json +++ b/package.json @@ -73,6 +73,7 @@ "@types/showdown": "^2.0.0", "chart.js": "^3.8.0", "country-language": "^0.1.7", + "country-to-currency": "^1.0.10", "csv-parse": "^5.1.0", "doctest-ts-improved": "^0.8.8", "email-validator": "^2.0.4", diff --git a/src/Logic/SimpleMetaTagger.ts b/src/Logic/SimpleMetaTagger.ts index fa6f38dca..4b84c3013 100644 --- a/src/Logic/SimpleMetaTagger.ts +++ b/src/Logic/SimpleMetaTagger.ts @@ -14,6 +14,7 @@ import { OsmTags } from "../Models/OsmFeature" import { UIEventSource } from "./UIEventSource" import LayoutConfig from "../Models/ThemeConfig/LayoutConfig" import OsmObjectDownloader from "./Osm/OsmObjectDownloader" +import countryToCurrency from "country-to-currency" /** * All elements that are needed to perform metatagging @@ -583,6 +584,49 @@ export default class SimpleMetaTaggers { } ) + private static currency = new InlineMetaTagger( + { + keys: ["_currency"], + doc: "Adds the currency valid for the object, based on country or explicit tagging. Can be a single currency or a semicolon-separated list of currencies. Empty if no currency is found.", + isLazy: true, + }, + (feature) => { + Utils.AddLazyProperty(feature.properties, "_currency", () => { + // Initialize a list of currencies + const currencies = {} + + // Check if there are any currency:XXX tags, add them to the map + for (const key in feature.properties) { + if (key.startsWith("currency:")) { + if (feature.properties[key] === "yes") { + currencies[key.slice(9)] = true + } else { + currencies[key.slice(9)] = false + } + } + } + + // Determine the default currency for the country + const defaultCurrency = countryToCurrency[feature.properties._country.toUpperCase()] + + // If the default currency is not in the list, add it + if (defaultCurrency && !currencies[defaultCurrency]) { + currencies[defaultCurrency] = true + } + + console.log("currencyTags", currencies, defaultCurrency) + + if (currencies) { + return Object.keys(currencies) + .filter((key) => currencies[key]) + .join(";") + } + return "" + }) + return true + } + ) + public static metatags: SimpleMetaTagger[] = [ SimpleMetaTaggers.latlon, SimpleMetaTaggers.layerInfo, @@ -601,6 +645,7 @@ export default class SimpleMetaTaggers { SimpleMetaTaggers.levels, SimpleMetaTaggers.referencingWays, SimpleMetaTaggers.timeSinceLastEdit, + SimpleMetaTaggers.currency, ] /**