| 
									
										
										
										
											2021-09-06 01:35:08 +02:00
										 |  |  | import {readFileSync, writeFileSync} from "fs"; | 
					
						
							|  |  |  | import {Utils} from "../../../Utils"; | 
					
						
							| 
									
										
										
										
											2021-09-13 01:21:25 +02:00
										 |  |  | import {TagRenderingConfigJson} from "../../../Models/ThemeConfig/Json/TagRenderingConfigJson"; | 
					
						
							|  |  |  | import ScriptUtils from "../../../scripts/ScriptUtils"; | 
					
						
							| 
									
										
										
										
											2021-09-22 20:12:53 +02:00
										 |  |  | import {LayerConfigJson} from "../../../Models/ThemeConfig/Json/LayerConfigJson"; | 
					
						
							| 
									
										
										
										
											2022-02-01 13:16:38 +01:00
										 |  |  | import FilterConfigJson from "../../../Models/ThemeConfig/Json/FilterConfigJson"; | 
					
						
							| 
									
										
										
										
											2021-09-13 01:21:25 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function colonSplit(value: string): string[] { | 
					
						
							|  |  |  |     return value.split(";").map(v => v.replace(/"/g, '').trim().toLowerCase()).filter(s => s !== ""); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function loadCsv(file): { | 
					
						
							|  |  |  |     key: string, | 
					
						
							|  |  |  |     image: string, | 
					
						
							|  |  |  |     description: Map<string, string>, | 
					
						
							|  |  |  |     countryWhiteList?: string[], | 
					
						
							| 
									
										
										
										
											2021-09-22 20:12:53 +02:00
										 |  |  |     countryBlackList?: string[], | 
					
						
							| 
									
										
										
										
											2021-09-13 01:21:25 +02:00
										 |  |  |     commonVoltages?: number[], | 
					
						
							|  |  |  |     commonCurrents?: number[], | 
					
						
							| 
									
										
										
										
											2021-09-30 18:50:08 +02:00
										 |  |  |     commonOutputs?: string[], | 
					
						
							| 
									
										
										
										
											2021-10-02 15:16:41 +02:00
										 |  |  |     associatedVehicleTypes?: string[], | 
					
						
							| 
									
										
										
										
											2021-12-10 14:29:12 +01:00
										 |  |  |     neverAssociatedWith?: string[], | 
					
						
							|  |  |  |     extraVisualisationCondition: string | 
					
						
							| 
									
										
										
										
											2021-09-13 01:21:25 +02:00
										 |  |  | }[] { | 
					
						
							|  |  |  |     const entries: string[] = Utils.NoNull(readFileSync(file, "utf8").split("\n").map(str => str.trim())) | 
					
						
							|  |  |  |     const header = entries.shift().split(",") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return Utils.NoNull(entries.map(entry => { | 
					
						
							|  |  |  |         const values = entry.split(",").map(str => str.trim()) | 
					
						
							|  |  |  |         if (values[0] === undefined || values[0] === "") { | 
					
						
							|  |  |  |             return undefined; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const v = {} | 
					
						
							| 
									
										
										
										
											2021-10-02 15:16:41 +02:00
										 |  |  |         const colonSeperated = ["commonVoltages", "commonOutputs", "commonCurrents", "countryWhiteList", "countryBlackList", "associatedVehicleTypes", "neverAssociatedWith"] | 
					
						
							| 
									
										
										
										
											2021-09-13 01:21:25 +02:00
										 |  |  |         const descriptionTranslations = new Map<string, string>() | 
					
						
							|  |  |  |         for (let j = 0; j < header.length; j++) { | 
					
						
							|  |  |  |             const key = header[j]; | 
					
						
							|  |  |  |             if (key.startsWith("description")) { | 
					
						
							|  |  |  |                 const language = key.substring("description:".length) | 
					
						
							|  |  |  |                 descriptionTranslations.set(language, values[j]) | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (colonSeperated.indexOf(key) >= 0) { | 
					
						
							|  |  |  |                 v[key] = colonSplit(values[j]) | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 v[key] = values[j] | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         v["description"] = descriptionTranslations | 
					
						
							|  |  |  |         return <any>v; | 
					
						
							|  |  |  |     })) | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2021-09-06 01:35:08 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | // SMall script to output the properties of the types.csv as json to add in the tagRenderingGroup. Should be copied manually
 | 
					
						
							| 
									
										
										
										
											2021-09-06 02:17:28 +02:00
										 |  |  | function run(file, protojson) { | 
					
						
							| 
									
										
										
										
											2021-09-06 01:35:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-07 21:03:29 +02:00
										 |  |  |     const overview_question_answers = [] | 
					
						
							| 
									
										
										
										
											2021-10-02 15:16:41 +02:00
										 |  |  |     const questions: (TagRenderingConfigJson & { "id": string })[] = [] | 
					
						
							| 
									
										
										
										
											2021-10-25 22:43:25 +02:00
										 |  |  |     const technicalQuestions: (TagRenderingConfigJson & { "id": string })[] = [] | 
					
						
							| 
									
										
										
										
											2021-09-13 01:21:25 +02:00
										 |  |  |     const filterOptions: { question: any, osmTags?: string } [] = [ | 
					
						
							| 
									
										
										
										
											2021-09-06 21:56:48 +02:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2021-09-13 01:21:25 +02:00
										 |  |  |             question: { | 
					
						
							|  |  |  |                 en: "All connectors", | 
					
						
							|  |  |  |                 nl: "Alle types" | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2021-09-06 21:56:48 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |     ] | 
					
						
							| 
									
										
										
										
											2021-09-06 01:35:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-13 01:21:25 +02:00
										 |  |  |     const entries = loadCsv(file) | 
					
						
							| 
									
										
										
										
											2021-10-02 15:16:41 +02:00
										 |  |  |     for (let i = 0; i < entries.length; i++) { | 
					
						
							| 
									
										
										
										
											2021-09-22 20:12:53 +02:00
										 |  |  |         const e = entries[i]; | 
					
						
							| 
									
										
										
										
											2021-09-13 01:21:25 +02:00
										 |  |  |         const txt = { | 
					
						
							| 
									
										
										
										
											2022-02-17 23:58:03 +01:00
										 |  |  |             en: e.description.get("en"), | 
					
						
							|  |  |  |             nl: e.description.get("nl") | 
					
						
							| 
									
										
										
										
											2021-09-06 01:35:08 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         const json = { | 
					
						
							| 
									
										
										
										
											2021-09-13 01:21:25 +02:00
										 |  |  |             if: `${e.key}=1`, | 
					
						
							|  |  |  |             ifnot: `${e.key}=`, | 
					
						
							| 
									
										
										
										
											2021-09-07 21:03:29 +02:00
										 |  |  |             then: txt, | 
					
						
							| 
									
										
										
										
											2022-02-17 23:58:03 +01:00
										 |  |  |             icon:{ | 
					
						
							|  |  |  |                 path:"./assets/layers/charging_station/" + e.image, | 
					
						
							|  |  |  |                 class:"medium" | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2021-09-06 01:35:08 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-02 15:16:41 +02:00
										 |  |  |         if (e.countryWhiteList.length > 0 && e.countryBlackList.length > 0) { | 
					
						
							|  |  |  |             throw "Error for type " + e.key + ": don't defined both a whitelist and a blacklist" | 
					
						
							| 
									
										
										
										
											2021-09-22 20:12:53 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (e.countryWhiteList.length > 0) { | 
					
						
							| 
									
										
										
										
											2021-09-30 18:50:08 +02:00
										 |  |  |             // This is a 'hideInAnswer', thus _reverse_ logic!
 | 
					
						
							| 
									
										
										
										
											2021-09-13 01:21:25 +02:00
										 |  |  |             const countries = e.countryWhiteList.map(country => "_country!=" + country) //HideInAnswer if it is in the wrong country
 | 
					
						
							| 
									
										
										
										
											2021-09-06 21:56:48 +02:00
										 |  |  |             json["hideInAnswer"] = {or: countries} | 
					
						
							| 
									
										
										
										
											2021-10-02 15:16:41 +02:00
										 |  |  |         } else if (e.countryBlackList.length > 0) { | 
					
						
							| 
									
										
										
										
											2021-09-22 20:12:53 +02:00
										 |  |  |             const countries = e.countryBlackList.map(country => "_country=" + country) //HideInAnswer if it is in the wrong country
 | 
					
						
							|  |  |  |             json["hideInAnswer"] = {or: countries} | 
					
						
							| 
									
										
										
										
											2021-09-06 01:35:08 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-10-02 15:16:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (e.associatedVehicleTypes?.length > 0 && e.associatedVehicleTypes.indexOf("*") < 0 && e.neverAssociatedWith?.length > 0) { | 
					
						
							| 
									
										
										
										
											2021-09-30 18:50:08 +02:00
										 |  |  |             // This plug only occurs if some vehicle specific vehicle type is present.
 | 
					
						
							|  |  |  |             // IF all of the needed vehicle types are explicitly NO, then we hide this type as well
 | 
					
						
							| 
									
										
										
										
											2021-10-02 15:16:41 +02:00
										 |  |  |             let associatedWith = {and: [].concat(...e.associatedVehicleTypes.map(neededVehicle => [neededVehicle + "=no"]))} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             // We also hide if:
 | 
					
						
							|  |  |  |             // - One of the neverAssociatedVehiclesTYpes is set to 'yes' AND none of the associated types are set/yes
 | 
					
						
							|  |  |  |             let neverAssociatedIsSet = { | 
					
						
							|  |  |  |                 and: [{ | 
					
						
							|  |  |  |                     or: e.neverAssociatedWith.map(vehicleType => vehicleType + "=yes") | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |                     ...e.associatedVehicleTypes.map(associated => associated + "!=yes") | 
					
						
							|  |  |  |                 ] | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             let conditions = [associatedWith, neverAssociatedIsSet] | 
					
						
							|  |  |  |             if (json["hideInAnswer"] !== undefined) { | 
					
						
							|  |  |  |                 conditions.push(json["hideInAnswer"]) | 
					
						
							| 
									
										
										
										
											2021-09-30 18:50:08 +02:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2021-10-02 15:16:41 +02:00
										 |  |  |             json["hideInAnswer"] = {or: conditions} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-06 01:35:08 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-02 15:16:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-07 21:03:29 +02:00
										 |  |  |         overview_question_answers.push(json) | 
					
						
							| 
									
										
										
										
											2021-09-06 01:35:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-07 21:03:29 +02:00
										 |  |  |         // We add a second time for any amount to trigger a visualisation; but this is not an answer option
 | 
					
						
							|  |  |  |         const no_ask_json = { | 
					
						
							| 
									
										
										
										
											2021-09-09 00:05:51 +02:00
										 |  |  |             if: { | 
					
						
							| 
									
										
										
										
											2021-12-10 15:51:32 +01:00
										 |  |  |                 and:Utils.NoEmpty( [`${e.key}~*`, `${e.key}!=1`, ...e.extraVisualisationCondition.split(";")]) | 
					
						
							| 
									
										
										
										
											2021-09-07 21:03:29 +02:00
										 |  |  |             }, | 
					
						
							|  |  |  |             then: txt, | 
					
						
							| 
									
										
										
										
											2022-02-17 23:58:03 +01:00
										 |  |  |             hideInAnswer: true, | 
					
						
							|  |  |  |             icon:{ | 
					
						
							|  |  |  |                 path: e.image, | 
					
						
							|  |  |  |                 class:"medium" | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2021-09-07 21:03:29 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         overview_question_answers.push(no_ask_json) | 
					
						
							| 
									
										
										
										
											2021-09-09 00:05:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-05 12:18:19 +02:00
										 |  |  |         const descrWithImage_en = `<div style='display: inline-block'><b>${e.description.get("en")}</b> <img style='width:1rem; display: inline-block' src='./assets/layers/charging_station/${e.image}'/></div>` | 
					
						
							|  |  |  |         const descrWithImage_nl = `<div style='display: inline-block'><b>${e.description.get("nl")}</b> <img style='width:1rem; display: inline-block' src='./assets/layers/charging_station/${e.image}'/></div>` | 
					
						
							| 
									
										
										
										
											2021-09-06 01:35:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-13 01:21:25 +02:00
										 |  |  |         questions.push({ | 
					
						
							| 
									
										
										
										
											2021-10-02 15:16:41 +02:00
										 |  |  |             "id": "plugs-" + i, | 
					
						
							| 
									
										
										
										
											2021-09-06 01:35:08 +02:00
										 |  |  |             question: { | 
					
						
							| 
									
										
										
										
											2021-09-13 01:21:25 +02:00
										 |  |  |                 en: `How much plugs of type ${descrWithImage_en} are available here?`, | 
					
						
							|  |  |  |                 nl: `Hoeveel stekkers van type  ${descrWithImage_nl} heeft dit oplaadpunt?`, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             render: { | 
					
						
							| 
									
										
										
										
											2021-10-06 00:31:47 +02:00
										 |  |  |                 en: `There are <b class='text-xl'>{${e.key}}</b> plugs of type ${descrWithImage_en} available here`, | 
					
						
							|  |  |  |                 nl: `Hier zijn <b class='text-xl'>{${e.key}}</b> stekkers van het type ${descrWithImage_nl}` | 
					
						
							| 
									
										
										
										
											2021-09-06 01:35:08 +02:00
										 |  |  |             }, | 
					
						
							|  |  |  |             freeform: { | 
					
						
							| 
									
										
										
										
											2021-09-13 01:21:25 +02:00
										 |  |  |                 key: e.key, | 
					
						
							| 
									
										
										
										
											2021-09-06 01:35:08 +02:00
										 |  |  |                 type: "pnat" | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2021-09-13 01:21:25 +02:00
										 |  |  |             condition: { | 
					
						
							|  |  |  |                 and: [`${e.key}~*`, `${e.key}!=0`] | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2021-09-06 01:35:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-25 22:43:25 +02:00
										 |  |  |         technicalQuestions.push({ | 
					
						
							| 
									
										
										
										
											2021-10-02 15:16:41 +02:00
										 |  |  |             "id": "voltage-" + i, | 
					
						
							| 
									
										
										
										
											2021-11-10 08:51:24 +01:00
										 |  |  |             group: "technical", | 
					
						
							| 
									
										
										
										
											2021-09-13 01:21:25 +02:00
										 |  |  |             question: { | 
					
						
							|  |  |  |                 en: `What voltage do the plugs with ${descrWithImage_en} offer?`, | 
					
						
							|  |  |  |                 nl: `Welke spanning levert de stekker van type ${descrWithImage_nl}` | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             render: { | 
					
						
							|  |  |  |                 en: `${descrWithImage_en} outputs {${e.key}:voltage} volt`, | 
					
						
							|  |  |  |                 nl: `${descrWithImage_nl} heeft een spanning van {${e.key}:voltage} volt` | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             freeform: { | 
					
						
							|  |  |  |                 key: `${e.key}:voltage`, | 
					
						
							|  |  |  |                 type: "pfloat" | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             mappings: e.commonVoltages.map(voltage => { | 
					
						
							|  |  |  |                 return { | 
					
						
							|  |  |  |                     if: `socket:${e.key}:voltage=${voltage} V`, | 
					
						
							|  |  |  |                     then: { | 
					
						
							| 
									
										
										
										
											2022-02-17 23:58:03 +01:00
										 |  |  |                         en: `${e.description.get("en")} outputs ${voltage} volt`, | 
					
						
							|  |  |  |                         nl: `${e.description.get("nl")} heeft een spanning van ${voltage} volt` | 
					
						
							|  |  |  |                     }, | 
					
						
							|  |  |  |                     icon: { | 
					
						
							|  |  |  |                         path: `./assets/layers/charging_station/${e.image}`, | 
					
						
							|  |  |  |                         class:"medium" | 
					
						
							| 
									
										
										
										
											2021-09-13 01:21:25 +02:00
										 |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             }), | 
					
						
							|  |  |  |             condition: { | 
					
						
							|  |  |  |                 and: [`${e.key}~*`, `${e.key}!=0`] | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2021-09-06 01:35:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-13 01:21:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-25 22:43:25 +02:00
										 |  |  |         technicalQuestions.push({ | 
					
						
							| 
									
										
										
										
											2021-10-02 15:16:41 +02:00
										 |  |  |             "id": "current-" + i, | 
					
						
							| 
									
										
										
										
											2021-11-10 08:51:24 +01:00
										 |  |  |             group:"technical", | 
					
						
							| 
									
										
										
										
											2021-09-13 01:21:25 +02:00
										 |  |  |             question: { | 
					
						
							|  |  |  |                 en: `What current do the plugs with ${descrWithImage_en} offer?`, | 
					
						
							|  |  |  |                 nl: `Welke stroom levert de stekker van type ${descrWithImage_nl}?`, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             render: { | 
					
						
							|  |  |  |                 en: `${descrWithImage_en} outputs at most {${e.key}:current}A`, | 
					
						
							|  |  |  |                 nl: `${descrWithImage_nl} levert een stroom van maximaal {${e.key}:current}A` | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             freeform: { | 
					
						
							|  |  |  |                 key: `${e.key}:current`, | 
					
						
							|  |  |  |                 type: "pfloat" | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             mappings: e.commonCurrents.map(current => { | 
					
						
							|  |  |  |                 return { | 
					
						
							|  |  |  |                     if: `socket:${e.key}:current=${current} A`, | 
					
						
							|  |  |  |                     then: { | 
					
						
							| 
									
										
										
										
											2022-02-17 23:58:03 +01:00
										 |  |  |                         en: `${e.description.get("en")} outputs at most ${current} A`, | 
					
						
							|  |  |  |                         nl: `${e.description.get("nl")} levert een stroom van maximaal ${current} A` | 
					
						
							|  |  |  |                     }, | 
					
						
							|  |  |  |                     icon: { | 
					
						
							|  |  |  |                         path: `./assets/layers/charging_station/${e.image}`, | 
					
						
							|  |  |  |                         class:"medium" | 
					
						
							| 
									
										
										
										
											2021-09-13 01:21:25 +02:00
										 |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             }), | 
					
						
							|  |  |  |             condition: { | 
					
						
							|  |  |  |                 and: [`${e.key}~*`, `${e.key}!=0`] | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-25 22:43:25 +02:00
										 |  |  |         technicalQuestions.push({ | 
					
						
							| 
									
										
										
										
											2021-10-02 15:16:41 +02:00
										 |  |  |             "id": "power-output-" + i, | 
					
						
							| 
									
										
										
										
											2021-11-10 08:51:24 +01:00
										 |  |  |             group:"technical", | 
					
						
							| 
									
										
										
										
											2021-09-13 01:21:25 +02:00
										 |  |  |             question: { | 
					
						
							|  |  |  |                 en: `What power output does a single plug of type ${descrWithImage_en} offer?`, | 
					
						
							|  |  |  |                 nl: `Welk vermogen levert een enkele stekker van type ${descrWithImage_nl}?`, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             render: { | 
					
						
							|  |  |  |                 en: `${descrWithImage_en} outputs at most {${e.key}:output}`, | 
					
						
							|  |  |  |                 nl: `${descrWithImage_nl} levert een vermogen van maximaal {${e.key}:output}` | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             freeform: { | 
					
						
							|  |  |  |                 key: `${e.key}:output`, | 
					
						
							|  |  |  |                 type: "pfloat" | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             mappings: e.commonOutputs.map(output => { | 
					
						
							|  |  |  |                 return { | 
					
						
							|  |  |  |                     if: `socket:${e.key}:output=${output}`, | 
					
						
							|  |  |  |                     then: { | 
					
						
							| 
									
										
										
										
											2022-02-17 23:58:03 +01:00
										 |  |  |                         en: `${e.description.get("en")} outputs at most ${output} A`, | 
					
						
							|  |  |  |                         nl: `${e.description.get("nl")} levert een vermogen van maximaal ${output} A` | 
					
						
							|  |  |  |                     }, | 
					
						
							|  |  |  |                     icon: { | 
					
						
							|  |  |  |                         path: `./assets/layers/charging_station/${e.image}`, | 
					
						
							|  |  |  |                         class:"medium" | 
					
						
							| 
									
										
										
										
											2021-09-13 01:21:25 +02:00
										 |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             }), | 
					
						
							|  |  |  |             condition: { | 
					
						
							|  |  |  |                 and: [`${e.key}~*`, `${e.key}!=0`] | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2021-09-06 21:56:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         filterOptions.push({ | 
					
						
							| 
									
										
										
										
											2021-09-13 01:21:25 +02:00
										 |  |  |             question: { | 
					
						
							|  |  |  |                 en: `Has a ${descrWithImage_en} connector`, | 
					
						
							|  |  |  |                 nl: `Heeft een ${descrWithImage_nl}` | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             osmTags: `${e.key}~*` | 
					
						
							| 
									
										
										
										
											2021-09-06 21:56:48 +02:00
										 |  |  |         }) | 
					
						
							| 
									
										
										
										
											2021-09-06 01:35:08 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const toggles = { | 
					
						
							| 
									
										
										
										
											2021-10-02 15:16:41 +02:00
										 |  |  |         "id": "Available_charging_stations (generated)", | 
					
						
							| 
									
										
										
										
											2021-09-06 01:35:08 +02:00
										 |  |  |         "question": { | 
					
						
							| 
									
										
										
										
											2021-10-25 22:43:25 +02:00
										 |  |  |             "en": "Which charging connections are available here?", | 
					
						
							|  |  |  |             "nl": "Welke aansluitingen zijn hier beschikbaar?" | 
					
						
							| 
									
										
										
										
											2021-09-06 01:35:08 +02:00
										 |  |  |         }, | 
					
						
							|  |  |  |         "multiAnswer": true, | 
					
						
							| 
									
										
										
										
											2021-09-07 21:03:29 +02:00
										 |  |  |         "mappings": overview_question_answers | 
					
						
							| 
									
										
										
										
											2021-09-06 01:35:08 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     questions.unshift(toggles) | 
					
						
							| 
									
										
										
										
											2021-11-10 08:51:24 +01:00
										 |  |  |     questions.push(...technicalQuestions) | 
					
						
							| 
									
										
										
										
											2021-09-06 01:35:08 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     const stringified = questions.map(q => JSON.stringify(q, null, "  ")) | 
					
						
							| 
									
										
										
										
											2021-09-22 20:12:53 +02:00
										 |  |  |     let protoString = readFileSync(protojson, "utf8") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-26 01:14:22 +02:00
										 |  |  |     protoString = protoString.replace(/{[ \t\n]*"id"[ \t\n]*:[ \t\n]*"\$\$\$"[ \t\n]*}/, stringified.join(",\n")) | 
					
						
							| 
									
										
										
										
											2021-10-02 15:16:41 +02:00
										 |  |  |     const proto = <LayerConfigJson>JSON.parse(protoString) | 
					
						
							| 
									
										
										
										
											2022-02-01 13:16:38 +01:00
										 |  |  |     if(typeof proto.filter === "string"){ | 
					
						
							|  |  |  |         throw "Filters of a the protojson should be a list of FilterConfigJsons" | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     proto.filter = <FilterConfigJson[]> proto.filter; | 
					
						
							| 
									
										
										
										
											2021-09-22 20:12:53 +02:00
										 |  |  |     proto.tagRenderings.forEach(tr => { | 
					
						
							| 
									
										
										
										
											2021-10-02 15:16:41 +02:00
										 |  |  |         if (typeof tr === "string") { | 
					
						
							| 
									
										
										
										
											2021-09-22 20:12:53 +02:00
										 |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-10-02 15:16:41 +02:00
										 |  |  |         if (tr["id"] === undefined || typeof tr["id"] !== "string") { | 
					
						
							| 
									
										
										
										
											2021-09-22 20:12:53 +02:00
										 |  |  |             console.error(tr) | 
					
						
							|  |  |  |             throw "Every tagrendering should have an id, acting as comment" | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     }) | 
					
						
							| 
									
										
										
										
											2021-10-02 15:16:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-01 13:16:38 +01:00
										 |  |  |     proto.filter.push({ | 
					
						
							| 
									
										
										
										
											2021-10-02 15:16:41 +02:00
										 |  |  |         id: "connection_type", | 
					
						
							| 
									
										
										
										
											2021-09-06 21:56:48 +02:00
										 |  |  |         options: filterOptions | 
					
						
							|  |  |  |     }) | 
					
						
							| 
									
										
										
										
											2021-09-13 01:21:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-30 20:09:09 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-13 02:38:20 +02:00
										 |  |  |     const extraUnits = [ | 
					
						
							| 
									
										
										
										
											2021-09-13 01:21:25 +02:00
										 |  |  |         { | 
					
						
							|  |  |  |             appliesToKey: entries.map(e => e.key + ":voltage"), | 
					
						
							|  |  |  |             applicableUnits: [{ | 
					
						
							|  |  |  |                 canonicalDenomination: 'V', | 
					
						
							| 
									
										
										
										
											2021-10-02 15:16:41 +02:00
										 |  |  |                 alternativeDenomination: ["v", "volt", "voltage", 'V', 'Volt'], | 
					
						
							| 
									
										
										
										
											2021-09-13 01:21:25 +02:00
										 |  |  |                 human: { | 
					
						
							|  |  |  |                     en: "Volts", | 
					
						
							|  |  |  |                     nl: "volt" | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             }], | 
					
						
							|  |  |  |             eraseInvalidValues: true | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             appliesToKey: entries.map(e => e.key + ":current"), | 
					
						
							|  |  |  |             applicableUnits: [{ | 
					
						
							|  |  |  |                 canonicalDenomination: 'A', | 
					
						
							| 
									
										
										
										
											2021-10-02 15:16:41 +02:00
										 |  |  |                 alternativeDenomination: ["a", "amp", "amperage", 'A'], | 
					
						
							| 
									
										
										
										
											2021-09-13 01:21:25 +02:00
										 |  |  |                 human: { | 
					
						
							|  |  |  |                     en: "A", | 
					
						
							|  |  |  |                     nl: "A" | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             }], | 
					
						
							|  |  |  |             eraseInvalidValues: true | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             appliesToKey: entries.map(e => e.key + ":output"), | 
					
						
							|  |  |  |             applicableUnits: [{ | 
					
						
							|  |  |  |                 canonicalDenomination: 'kW', | 
					
						
							|  |  |  |                 alternativeDenomination: ["kilowatt"], | 
					
						
							|  |  |  |                 human: { | 
					
						
							|  |  |  |                     en: "kilowatt", | 
					
						
							|  |  |  |                     nl: "kilowatt" | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     canonicalDenomination: 'mW', | 
					
						
							|  |  |  |                     alternativeDenomination: ["megawatt"], | 
					
						
							|  |  |  |                     human: { | 
					
						
							|  |  |  |                         en: "megawatt", | 
					
						
							|  |  |  |                         nl: "megawatt" | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 }], | 
					
						
							|  |  |  |             eraseInvalidValues: true | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |     ]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-02 15:16:41 +02:00
										 |  |  |     if (proto["units"] == undefined) { | 
					
						
							| 
									
										
										
										
											2021-09-13 02:38:20 +02:00
										 |  |  |         proto["units"] = [] | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     proto["units"].push(...extraUnits) | 
					
						
							| 
									
										
										
										
											2021-09-06 21:56:48 +02:00
										 |  |  |     writeFileSync("charging_station.json", JSON.stringify(proto, undefined, "  ")) | 
					
						
							| 
									
										
										
										
											2021-09-06 01:35:08 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-13 01:21:25 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | async function queryTagInfo(file, type, clean: ((s: string) => string)) { | 
					
						
							|  |  |  |     for (const e of loadCsv(file)) { | 
					
						
							|  |  |  |         const value = await ScriptUtils.TagInfoHistogram(e.key + ":" + type) | 
					
						
							|  |  |  |         const result = value.data | 
					
						
							|  |  |  |         const counts = new Map<string, number>() | 
					
						
							|  |  |  |         //  console.log(result)
 | 
					
						
							|  |  |  |         for (const r of result) { | 
					
						
							|  |  |  |             let key = r.value; | 
					
						
							|  |  |  |             key = clean(key) | 
					
						
							|  |  |  |             key.trim(); | 
					
						
							|  |  |  |             if (key.indexOf('-') >= 0) { | 
					
						
							|  |  |  |                 continue | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if (r.fraction < 0.05) { | 
					
						
							|  |  |  |                 continue | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if (counts.has(key)) { | 
					
						
							|  |  |  |                 counts.set(key, counts.get(key) + r.count) | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 counts.set(key, r.count) | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         const countsArray = Array.from(counts.keys()) | 
					
						
							|  |  |  |         countsArray.sort() | 
					
						
							| 
									
										
										
										
											2021-09-22 20:12:53 +02:00
										 |  |  |         console.log(`${e.key}:${type} = ${countsArray.join(";")}`) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Adds the translations into the 'newConfig' object | 
					
						
							|  |  |  |  * @param origPath | 
					
						
							|  |  |  |  * @param newConfig | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2021-10-02 15:16:41 +02:00
										 |  |  | function mergeTranslations(origPath, newConfig: LayerConfigJson) { | 
					
						
							|  |  |  |     const oldFile = <LayerConfigJson>JSON.parse(readFileSync(origPath, "utf-8")) | 
					
						
							|  |  |  |     const newFile = <LayerConfigJson>newConfig | 
					
						
							| 
									
										
										
										
											2021-09-22 20:12:53 +02:00
										 |  |  |     const renderingsOld = oldFile.tagRenderings | 
					
						
							|  |  |  |     delete oldFile.tagRenderings | 
					
						
							|  |  |  |     const newRenderings = newFile.tagRenderings | 
					
						
							|  |  |  |     Utils.Merge(oldFile, newFile) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (const oldRendering of renderingsOld) { | 
					
						
							| 
									
										
										
										
											2021-10-02 15:16:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-26 21:06:37 +02:00
										 |  |  |         const oldRenderingName = oldRendering["id"] | 
					
						
							| 
									
										
										
										
											2021-10-02 15:16:41 +02:00
										 |  |  |         if (oldRenderingName === undefined) { | 
					
						
							| 
									
										
										
										
											2021-09-22 20:12:53 +02:00
										 |  |  |             continue | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-09-26 21:06:37 +02:00
										 |  |  |         const applicable = newRenderings.filter(r => r["id"] === oldRenderingName)[0] | 
					
						
							| 
									
										
										
										
											2021-10-02 15:16:41 +02:00
										 |  |  |         if (applicable === undefined) { | 
					
						
							| 
									
										
										
										
											2021-09-22 20:12:53 +02:00
										 |  |  |             continue; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         Utils.Merge(oldRendering, applicable) | 
					
						
							| 
									
										
										
										
											2021-09-13 01:21:25 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-06 01:35:08 +02:00
										 |  |  | try { | 
					
						
							| 
									
										
										
										
											2021-09-30 18:50:08 +02:00
										 |  |  |     console.log("Generating the charging_station.json file") | 
					
						
							| 
									
										
										
										
											2021-09-06 21:56:48 +02:00
										 |  |  |     run("types.csv", "charging_station.protojson") | 
					
						
							| 
									
										
										
										
											2021-09-22 20:12:53 +02:00
										 |  |  |     /*/ | 
					
						
							|  |  |  |     queryTagInfo("types.csv","voltage", s => s.trim()) | 
					
						
							|  |  |  |     queryTagInfo("types.csv", "current", s => s.trim()) | 
					
						
							|  |  |  |     queryTagInfo("types.csv", "output", s => { | 
					
						
							| 
									
										
										
										
											2021-09-13 01:21:25 +02:00
										 |  |  |          if(s.endsWith("kW")){ | 
					
						
							|  |  |  |              s = s.substring(0, s.length - 2) | 
					
						
							|  |  |  |          } | 
					
						
							|  |  |  |          s = s.trim() | 
					
						
							|  |  |  |          return s + " kW" | 
					
						
							| 
									
										
										
										
											2021-09-22 20:12:53 +02:00
										 |  |  |      }) | 
					
						
							|  |  |  |      //*/
 | 
					
						
							| 
									
										
										
										
											2021-09-13 01:21:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-06 01:35:08 +02:00
										 |  |  | } catch (e) { | 
					
						
							|  |  |  |     console.error(e) | 
					
						
							|  |  |  | } |