forked from MapComplete/MapComplete
Fix questions: applicable mappings are now calculated dynamically; charging station theme now only shows applicable plugs based on the allowed vehicle types
This commit is contained in:
parent
bedc576313
commit
df34239256
14 changed files with 3677 additions and 3359 deletions
|
@ -16,4 +16,20 @@ AT this point, most of the work should be done; feel free to send a PR. If you w
|
|||
- Run 'ts-node csvToJson.ts' which will generate a new charging_station.json based on the protojson
|
||||
- Run`npm run query:licenses` to get an interactive program to add the license of your artwork, followed by `npm run generate:licenses`
|
||||
- Run `npm run generate:layeroverview` to generate the layer files
|
||||
- Run `npm run start` to run the instance
|
||||
- Run `npm run start` to run the instance
|
||||
|
||||
The CSV File
|
||||
------------
|
||||
|
||||
The columns in the CSV file are:
|
||||
|
||||
- key: the key as described on the wiki, starts with `socket:`
|
||||
- image: The associated image (a .svg)
|
||||
- description:en A description in english
|
||||
- description:nl A description in english
|
||||
- countryWhiteList: Only show this plug type in these countries
|
||||
- countryBlackList: Don't show this plug type in these countries. NOt compatibel with the whiteList
|
||||
- commonVoltages, commonCurrents, commonOutputs: common values for these tags
|
||||
- associatedVehicleTypes and neverAssociatedWith: these work in tandem to hide options.
|
||||
If every associated vehicle type is `no`, then the option is hidden
|
||||
If at least one `neverAssociatedVehicleType` is `yes` and none of the associated types is yes, then the option is hidden too
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -18,7 +18,8 @@ function loadCsv(file): {
|
|||
commonVoltages?: number[],
|
||||
commonCurrents?: number[],
|
||||
commonOutputs?: string[],
|
||||
associatedVehicleTypes?:string[]
|
||||
associatedVehicleTypes?: string[],
|
||||
neverAssociatedWith?: string[]
|
||||
}[] {
|
||||
const entries: string[] = Utils.NoNull(readFileSync(file, "utf8").split("\n").map(str => str.trim()))
|
||||
const header = entries.shift().split(",")
|
||||
|
@ -30,7 +31,7 @@ function loadCsv(file): {
|
|||
}
|
||||
|
||||
const v = {}
|
||||
const colonSeperated = ["commonVoltages", "commonOutputs", "commonCurrents", "countryWhiteList","countryBlackList","associatedVehicleTypes"]
|
||||
const colonSeperated = ["commonVoltages", "commonOutputs", "commonCurrents", "countryWhiteList", "countryBlackList", "associatedVehicleTypes", "neverAssociatedWith"]
|
||||
const descriptionTranslations = new Map<string, string>()
|
||||
for (let j = 0; j < header.length; j++) {
|
||||
const key = header[j];
|
||||
|
@ -54,7 +55,7 @@ function loadCsv(file): {
|
|||
function run(file, protojson) {
|
||||
|
||||
const overview_question_answers = []
|
||||
const questions: (TagRenderingConfigJson & {"id": string})[] = []
|
||||
const questions: (TagRenderingConfigJson & { "id": string })[] = []
|
||||
const filterOptions: { question: any, osmTags?: string } [] = [
|
||||
{
|
||||
question: {
|
||||
|
@ -65,7 +66,7 @@ function run(file, protojson) {
|
|||
]
|
||||
|
||||
const entries = loadCsv(file)
|
||||
for (let i = 0; i < entries.length; i++){
|
||||
for (let i = 0; i < entries.length; i++) {
|
||||
const e = entries[i];
|
||||
const txt = {
|
||||
en: `<div class='flex'><img class='w-12 mx-4' src='./assets/layers/charging_station/${e.image}'/> <span>${e.description.get("en")}</span></div>`,
|
||||
|
@ -77,28 +78,43 @@ function run(file, protojson) {
|
|||
then: txt,
|
||||
}
|
||||
|
||||
if(e.countryWhiteList.length > 0 && e.countryBlackList.length > 0){
|
||||
throw "Error for type "+e.key+": don't defined both a whitelist and a blacklist"
|
||||
if (e.countryWhiteList.length > 0 && e.countryBlackList.length > 0) {
|
||||
throw "Error for type " + e.key + ": don't defined both a whitelist and a blacklist"
|
||||
}
|
||||
if (e.countryWhiteList.length > 0) {
|
||||
// This is a 'hideInAnswer', thus _reverse_ logic!
|
||||
const countries = e.countryWhiteList.map(country => "_country!=" + country) //HideInAnswer if it is in the wrong country
|
||||
json["hideInAnswer"] = {or: countries}
|
||||
}else if (e.countryBlackList .length > 0) {
|
||||
} else if (e.countryBlackList.length > 0) {
|
||||
const countries = e.countryBlackList.map(country => "_country=" + country) //HideInAnswer if it is in the wrong country
|
||||
json["hideInAnswer"] = {or: countries}
|
||||
}
|
||||
|
||||
if(e.associatedVehicleTypes?.length > 0 && e.associatedVehicleTypes.indexOf("*") < 0){
|
||||
|
||||
if (e.associatedVehicleTypes?.length > 0 && e.associatedVehicleTypes.indexOf("*") < 0 && e.neverAssociatedWith?.length > 0) {
|
||||
// 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
|
||||
let hideInAnswer : any = {and: [].concat(...e.associatedVehicleTypes.map(neededVehicle => [neededVehicle+"~*", neededVehicle+"!=yes"]))}
|
||||
if(json["hideInAnswer"] !== undefined){
|
||||
hideInAnswer = {or: [json["hideInAnswer"], hideInAnswer]}
|
||||
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")
|
||||
]
|
||||
}
|
||||
json["hideInAnswer"] = hideInAnswer
|
||||
|
||||
let conditions = [associatedWith, neverAssociatedIsSet]
|
||||
if (json["hideInAnswer"] !== undefined) {
|
||||
conditions.push(json["hideInAnswer"])
|
||||
}
|
||||
json["hideInAnswer"] = {or: conditions}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
overview_question_answers.push(json)
|
||||
|
||||
// We add a second time for any amount to trigger a visualisation; but this is not an answer option
|
||||
|
@ -115,7 +131,7 @@ function run(file, protojson) {
|
|||
const descrWithImage_nl = `<b>${e.description.get("nl")}</b> <img style='width:1rem;' src='./assets/layers/charging_station/${e.image}'/>`
|
||||
|
||||
questions.push({
|
||||
"id":"plugs-"+i,
|
||||
"id": "plugs-" + i,
|
||||
question: {
|
||||
en: `How much plugs of type ${descrWithImage_en} are available here?`,
|
||||
nl: `Hoeveel stekkers van type ${descrWithImage_nl} heeft dit oplaadpunt?`,
|
||||
|
@ -134,7 +150,7 @@ function run(file, protojson) {
|
|||
})
|
||||
|
||||
questions.push({
|
||||
"id":"voltage-"+i,
|
||||
"id": "voltage-" + i,
|
||||
question: {
|
||||
en: `What voltage do the plugs with ${descrWithImage_en} offer?`,
|
||||
nl: `Welke spanning levert de stekker van type ${descrWithImage_nl}`
|
||||
|
@ -163,7 +179,7 @@ function run(file, protojson) {
|
|||
|
||||
|
||||
questions.push({
|
||||
"id":"current-"+i,
|
||||
"id": "current-" + i,
|
||||
question: {
|
||||
en: `What current do the plugs with ${descrWithImage_en} offer?`,
|
||||
nl: `Welke stroom levert de stekker van type ${descrWithImage_nl}?`,
|
||||
|
@ -192,7 +208,7 @@ function run(file, protojson) {
|
|||
|
||||
|
||||
questions.push({
|
||||
"id":"power-output-"+i,
|
||||
"id": "power-output-" + i,
|
||||
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}?`,
|
||||
|
@ -229,7 +245,7 @@ function run(file, protojson) {
|
|||
}
|
||||
|
||||
const toggles = {
|
||||
"id":"Available_charging_stations (generated)",
|
||||
"id": "Available_charging_stations (generated)",
|
||||
"question": {
|
||||
"en": "Which charging stations are available here?"
|
||||
},
|
||||
|
@ -242,30 +258,29 @@ function run(file, protojson) {
|
|||
let protoString = readFileSync(protojson, "utf8")
|
||||
|
||||
protoString = protoString.replace("{\"id\": \"$$$\"}", stringified.join(",\n"))
|
||||
const proto = <LayerConfigJson> JSON.parse(protoString)
|
||||
const proto = <LayerConfigJson>JSON.parse(protoString)
|
||||
proto.tagRenderings.forEach(tr => {
|
||||
if(typeof tr === "string"){
|
||||
if (typeof tr === "string") {
|
||||
return;
|
||||
}
|
||||
if(tr["id"] === undefined || typeof tr["id"] !== "string"){
|
||||
if (tr["id"] === undefined || typeof tr["id"] !== "string") {
|
||||
console.error(tr)
|
||||
throw "Every tagrendering should have an id, acting as comment"
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
proto["filter"].push({
|
||||
id:"connection_type",
|
||||
id: "connection_type",
|
||||
options: filterOptions
|
||||
})
|
||||
|
||||
|
||||
|
||||
const extraUnits = [
|
||||
{
|
||||
appliesToKey: entries.map(e => e.key + ":voltage"),
|
||||
applicableUnits: [{
|
||||
canonicalDenomination: 'V',
|
||||
alternativeDenomination: ["v", "volt", "voltage",'V','Volt'],
|
||||
alternativeDenomination: ["v", "volt", "voltage", 'V', 'Volt'],
|
||||
human: {
|
||||
en: "Volts",
|
||||
nl: "volt"
|
||||
|
@ -277,7 +292,7 @@ function run(file, protojson) {
|
|||
appliesToKey: entries.map(e => e.key + ":current"),
|
||||
applicableUnits: [{
|
||||
canonicalDenomination: 'A',
|
||||
alternativeDenomination: ["a", "amp", "amperage",'A'],
|
||||
alternativeDenomination: ["a", "amp", "amperage", 'A'],
|
||||
human: {
|
||||
en: "A",
|
||||
nl: "A"
|
||||
|
@ -307,7 +322,7 @@ function run(file, protojson) {
|
|||
},
|
||||
];
|
||||
|
||||
if(proto["units"] == undefined){
|
||||
if (proto["units"] == undefined) {
|
||||
proto["units"] = []
|
||||
}
|
||||
proto["units"].push(...extraUnits)
|
||||
|
@ -348,22 +363,22 @@ async function queryTagInfo(file, type, clean: ((s: string) => string)) {
|
|||
* @param origPath
|
||||
* @param newConfig
|
||||
*/
|
||||
function mergeTranslations(origPath, newConfig: LayerConfigJson){
|
||||
const oldFile = <LayerConfigJson> JSON.parse(readFileSync(origPath, "utf-8"))
|
||||
const newFile =<LayerConfigJson> newConfig
|
||||
function mergeTranslations(origPath, newConfig: LayerConfigJson) {
|
||||
const oldFile = <LayerConfigJson>JSON.parse(readFileSync(origPath, "utf-8"))
|
||||
const newFile = <LayerConfigJson>newConfig
|
||||
const renderingsOld = oldFile.tagRenderings
|
||||
delete oldFile.tagRenderings
|
||||
const newRenderings = newFile.tagRenderings
|
||||
Utils.Merge(oldFile, newFile)
|
||||
|
||||
for (const oldRendering of renderingsOld) {
|
||||
|
||||
|
||||
const oldRenderingName = oldRendering["id"]
|
||||
if(oldRenderingName === undefined){
|
||||
if (oldRenderingName === undefined) {
|
||||
continue
|
||||
}
|
||||
const applicable = newRenderings.filter(r => r["id"] === oldRenderingName)[0]
|
||||
if(applicable === undefined){
|
||||
if (applicable === undefined) {
|
||||
continue;
|
||||
}
|
||||
Utils.Merge(oldRendering, applicable)
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
key,image,description:en,countryWhiteList,countryBlackList,commonVoltages,commonCurrents,commonOutputs,description:nl,associatedVehicleTypes
|
||||
socket:schuko,CEE7_4F.svg,<b>Schuko wall plug</b> without ground pin (CEE7/4 type F),be;fr;ma;tn;pl;cs;sk;mo,,230,16,3.6 kW,<b>Schuko stekker</b> zonder aardingspin (CEE7/4 type F),*
|
||||
socket:typee,TypeE.svg,<b>European wall plug</b> with ground pin (CEE7/4 type E),,,230,16,3 kW;22 kW;,<b>Europese stekker</b> met aardingspin (CEE7/4 type E),*
|
||||
socket:chademo,Chademo_type4.svg,<b>Chademo</b>,,,500,120,50 kW,<b>Chademo</b>,car;motorcar;hgv;bus
|
||||
socket:type1_cable,Type1_J1772.svg,<b>Type 1 with cable</b> (J1772),,,200;240,32,3.7 kW;7 kW,<b>Type 1 met kabel</b> (J1772),car;motorcar;hgv;bus
|
||||
socket:type1,Type1_J1772.svg,<b>Type 1 <i>without</i> cable</b> (J1772),,,200;240,32,3.7 kW;6.6 kW;7 kW;7.2 kW,<b>Type 1 <i>zonder</i> kabel</b> (J1772),car;motorcar;hgv;bus
|
||||
socket:type1_combo,Type1-ccs.svg,<b>Type 1 CCS</b> (aka Type 1 Combo),,,400;1000,50;125,50 kW;62.5 kW;150 kW;350 kW;,<b>Type 1 CCS</b> (ook gekend als Type 1 Combo),car;motorcar;hgv;bus
|
||||
socket:tesla_supercharger,Tesla-hpwc-model-s.svg,<b>Tesla Supercharger</b>,,,480,125;350,120 kW;150 kW;250 kW,<b>Tesla Supercharger</b>,car;motorcar;hgv;bus
|
||||
socket:type2,Type2_socket.svg,<b>Type 2</b> (mennekes),,,230;400,16;32,11 kW;22 kW,<b>Type 2</b> (mennekes),car;motorcar;hgv;bus
|
||||
socket:type2_combo,Type2_CCS.svg,<b>Type 2 CCS</b> (mennekes),,,500;920,125;350,50 kW,<b>Type 2 CCS</b> (mennekes),car;motorcar;hgv;bus
|
||||
socket:type2_cable,Type2_tethered.svg,<b>Type 2 with cable</b> (mennekes),,,230;400,16;32,11 kW;22 kW,<b>Type 2 met kabel</b> (J1772),car;motorcar;hgv;bus
|
||||
socket:tesla_supercharger_ccs,Type2_CCS.svg,<b>Tesla Supercharger CCS</b> (a branded type2_css),,,500;920,125;350,50 kW,<b>Tesla Supercharger CCS</b> (een type2 CCS met Tesla-logo),car;motorcar;hgv;bus
|
||||
socket:tesla_destination,Tesla-hpwc-model-s.svg,<b>Tesla Supercharger (destination)</b>,us,,480,125;350,120 kW;150 kW;250 kW,<b>Tesla Supercharger (destination)</b>,car;motorcar;hgv;bus
|
||||
socket:tesla_destination,Type2_tethered.svg,<b>Tesla supercharger (destination</b> (A Type 2 with cable branded as tesla),,us,230;400,16;32,11 kW;22 kW,<b>Tesla supercharger (destination</b> (Een Type 2 met kabel en Tesla-logo),car;motorcar;hgv;bus
|
||||
socket:USB-A,usb_port.svg,<b>USB</b> to charge phones and small electronics,,,5,1;2,5W;10W,<b>USB</b> om GSMs en kleine electronica op te laden,*
|
||||
key,image,description:en,countryWhiteList,countryBlackList,commonVoltages,commonCurrents,commonOutputs,description:nl,associatedVehicleTypes,neverAssociatedWith
|
||||
socket:schuko,CEE7_4F.svg,<b>Schuko wall plug</b> without ground pin (CEE7/4 type F),be;fr;ma;tn;pl;cs;sk;mo,,230,16,3.6 kW,<b>Schuko stekker</b> zonder aardingspin (CEE7/4 type F),*,
|
||||
socket:typee,TypeE.svg,<b>European wall plug</b> with ground pin (CEE7/4 type E),,,230,16,3 kW;22 kW;,<b>Europese stekker</b> met aardingspin (CEE7/4 type E),*,
|
||||
socket:chademo,Chademo_type4.svg,<b>Chademo</b>,,,500,120,50 kW,<b>Chademo</b>,car;motorcar;hgv;bus,bicycle;scooter
|
||||
socket:type1_cable,Type1_J1772.svg,<b>Type 1 with cable</b> (J1772),,,200;240,32,3.7 kW;7 kW,<b>Type 1 met kabel</b> (J1772),car;motorcar;hgv;bus,bicycle;scooter
|
||||
socket:type1,Type1_J1772.svg,<b>Type 1 <i>without</i> cable</b> (J1772),,,200;240,32,3.7 kW;6.6 kW;7 kW;7.2 kW,<b>Type 1 <i>zonder</i> kabel</b> (J1772),car;motorcar;hgv;bus,bicycle;scooter
|
||||
socket:type1_combo,Type1-ccs.svg,<b>Type 1 CCS</b> (aka Type 1 Combo),,,400;1000,50;125,50 kW;62.5 kW;150 kW;350 kW;,<b>Type 1 CCS</b> (ook gekend als Type 1 Combo),car;motorcar;hgv;bus,bicycle;scooter
|
||||
socket:tesla_supercharger,Tesla-hpwc-model-s.svg,<b>Tesla Supercharger</b>,,,480,125;350,120 kW;150 kW;250 kW,<b>Tesla Supercharger</b>,car;motorcar;hgv;bus,bicycle;scooter
|
||||
socket:type2,Type2_socket.svg,<b>Type 2</b> (mennekes),,,230;400,16;32,11 kW;22 kW,<b>Type 2</b> (mennekes),car;motorcar;hgv;bus,bicycle;scooter
|
||||
socket:type2_combo,Type2_CCS.svg,<b>Type 2 CCS</b> (mennekes),,,500;920,125;350,50 kW,<b>Type 2 CCS</b> (mennekes),car;motorcar;hgv;bus,bicycle;scooter
|
||||
socket:type2_cable,Type2_tethered.svg,<b>Type 2 with cable</b> (mennekes),,,230;400,16;32,11 kW;22 kW,<b>Type 2 met kabel</b> (J1772),car;motorcar;hgv;bus,bicycle;scooter
|
||||
socket:tesla_supercharger_ccs,Type2_CCS.svg,<b>Tesla Supercharger CCS</b> (a branded type2_css),,,500;920,125;350,50 kW,<b>Tesla Supercharger CCS</b> (een type2 CCS met Tesla-logo),car;motorcar;hgv;bus,bicycle;scooter
|
||||
socket:tesla_destination,Tesla-hpwc-model-s.svg,<b>Tesla Supercharger (destination)</b>,us,,480,125;350,120 kW;150 kW;250 kW,<b>Tesla Supercharger (destination)</b>,car;motorcar;hgv;bus,bicycle;scooter
|
||||
socket:tesla_destination,Type2_tethered.svg,<b>Tesla supercharger (destination</b> (A Type 2 with cable branded as tesla),,us,230;400,16;32,11 kW;22 kW,<b>Tesla supercharger (destination</b> (Een Type 2 met kabel en Tesla-logo),car;motorcar;hgv;bus,bicycle;scooter
|
||||
socket:USB-A,usb_port.svg,<b>USB</b> to charge phones and small electronics,,,5,1;2,5W;10W,<b>USB</b> om GSMs en kleine electronica op te laden,*,
|
||||
|
|
|
Loading…
Add table
Add a link
Reference in a new issue