detect max socket ouput

This commit is contained in:
Tykayn 2023-10-01 12:53:08 +02:00 committed by tykayn
parent 0db9565935
commit af1a649dc2
6 changed files with 128895 additions and 65172 deletions

View File

@ -52,6 +52,9 @@ const MappingIRVE: MappingConfigType = {
// id_station_itinerance: 'ref:EU:EVSE', // id_station_itinerance: 'ref:EU:EVSE',
id_station_local: 'ref', id_station_local: 'ref',
/**
* l'info de gratuité a été mal renseignée par les opérateurs, ils mettent TRÈS souvent que c'est gratuit alors que ce n'est pas vrai.
*/
// gratuit: { // gratuit: {
// key_converted: 'fee', // key_converted: 'fee',
// convert_to_boolean_value: true, // convert_to_boolean_value: true,
@ -65,7 +68,7 @@ const MappingIRVE: MappingConfigType = {
convert_to_boolean_value: true, // convertit en yes ou no convert_to_boolean_value: true, // convertit en yes ou no
}, },
// observations: 'note', // observations: 'note',
// nom_station: 'name', nom_station: 'name',
nom_enseigne: 'network', nom_enseigne: 'network',
// ******* dates // ******* dates
@ -150,17 +153,10 @@ const MappingIRVE: MappingConfigType = {
}, },
puissance_nominale: { puissance_nominale: {
key_converted: 'socket:max:output', key_converted: 'socket:max:output',
conditionnal_values: { socket_output_find_correspondances: true,
transform_function: (original_value:string) => { // transform_function: (original_value:string) => {
let converted_value = parseInt(original_value) //
let accepted_values = [3, 7, 22, 50, 150, 300] // },
if (accepted_values.includes(converted_value)) {
return converted_value+ ' kW'
} else {
return null
}
},
}
} }
// TODO gestion des puissances de bornes // TODO gestion des puissances de bornes
// avec une fonction de transformation des valeurs // avec une fonction de transformation des valeurs

View File

@ -14,16 +14,24 @@ let listOfBooleanKeys = [
"cable_t2_attache" "cable_t2_attache"
] ]
function boolToAddable(someBooleanValue: boolean) {
return someBooleanValue ? 1 : 0
}
export default class { export default class {
mapping_config: any = {} mapping_config: any = {}
private jardinage = true; private jardinage = true;
public stats: any; public stats: any;
private current_converted_geojson_point: any;
private current_geojson_point: any;
constructor(mappingConfig: MappingConfigType) { constructor(mappingConfig: MappingConfigType) {
this.setConfig(mappingConfig) this.setConfig(mappingConfig)
this.stats = { this.stats = {
phones_updated: 0, phones_updated: 0,
power_output: 0,
phones_updated_list: [], phones_updated_list: [],
phones_not_updated: 0 phones_not_updated: 0
} }
@ -47,12 +55,7 @@ export default class {
geoJSONConvertedPoint.type = featurePointGeoJson.type geoJSONConvertedPoint.type = featurePointGeoJson.type
geoJSONConvertedPoint.geometry = featurePointGeoJson.geometry geoJSONConvertedPoint.geometry = featurePointGeoJson.geometry
this.current_converted_geojson_point = geoJSONConvertedPoint
// let props = featurePointGeoJson.properties
// props.forEach((key, value) => {
//
// })
return geoJSONConvertedPoint return geoJSONConvertedPoint
} }
@ -143,6 +146,8 @@ export default class {
* @param newProperties * @param newProperties
*/ */
convertProperty(pointKeyName: string, mappingKeys: any, featurePoint: any, newProperties: any) { convertProperty(pointKeyName: string, mappingKeys: any, featurePoint: any, newProperties: any) {
this.current_geojson_point = featurePoint
let originalValue = featurePoint.properties[pointKeyName] let originalValue = featurePoint.properties[pointKeyName]
let mappingValueObject: any = ''; let mappingValueObject: any = '';
@ -227,6 +232,14 @@ export default class {
newKey = configObject.key_converted newKey = configObject.key_converted
} }
if (configObject.transform_function) {
// une transformation de la valeur
// apply transformation to value
convertedValue = configObject.transform_function(originalValue)
// console.log('transform_function: originalValue', originalValue, convertedValue)
// this.stats.power_output++
}
if (configObject.truthy_value) { if (configObject.truthy_value) {
// convertir la valeur, si elle est truthy, la transformer en ce que donne la propriété truthy_value // convertir la valeur, si elle est truthy, la transformer en ce que donne la propriété truthy_value
@ -249,20 +262,63 @@ export default class {
*/ */
if (mappingValueObject.convert_to_boolean_value) { if (mappingValueObject.convert_to_boolean_value) {
debugLog('convertProperty: is boolean_value_conversion') debugLog('convertProperty: is boolean_value_conversion')
debugLog('convertProperty: ==========> original value', originalValue)
if (this.truthyValues.indexOf(originalValue) !== -1) { convertedValue = this.convertToBooleanValue(originalValue)
convertedValue = 'yes'
} else {
debugLog('convertProperty: ==========> !!! NOT in truthy values', originalValue)
}
if (this.falsyValues.indexOf(originalValue) !== -1) {
convertedValue = 'no'
} else {
debugLog('convertProperty: ==========> !!! NOT in falsy values', originalValue)
}
} else { } else {
debugLog('convertProperty: is NOT having boolean_value_conversion', mappingValueObject) debugLog('convertProperty: is NOT having boolean_value_conversion', mappingValueObject)
} }
if (configObject.socket_output_find_correspondances) {
// this.current_geojson_point
// trouver à quel socket ça correspond
// si y'a plusieurs sockets, utiliser socket:max:output
let we_use_max_output = false;
let has_prise_type_2 = this.isTruthyValue(this.current_geojson_point.properties.prise_type_2)
let has_prise_type_combo_ccs = this.isTruthyValue(this.current_geojson_point.properties.prise_type_combo_ccs)
let prise_type_chademo = this.isTruthyValue(this.current_geojson_point.properties.prise_type_chademo)
let prise_type_ef = this.isTruthyValue(this.current_geojson_point.properties.prise_type_ef)
let prise_type_e = this.isTruthyValue(this.current_geojson_point.properties.prise_type_e)
let prise_type_autre = this.isTruthyValue(this.current_geojson_point.properties.prise_type_autre)
if ((boolToAddable(has_prise_type_2) + boolToAddable(has_prise_type_combo_ccs) + boolToAddable(prise_type_chademo) +
boolToAddable(prise_type_ef) + boolToAddable(prise_type_autre) + boolToAddable(prise_type_e)
) > 0) {
we_use_max_output = true;
}
// ajouter les tags de socket newProperties
let converted_value = originalValue.replace(/[^\d\.\,]/g, '').replace(',', '.')
let max_output = 400
// do not limit accepted values
// let accepted_values = [3, 7, 22, 50, 150, 300]
// if (accepted_values.includes(converted_value)) {
if (originalValue < max_output) {
// enlever les lettres dans la valeur
let out = converted_value + ' kW'
if (we_use_max_output) {
newProperties['socket:max:output'] = out;
} else {
if (has_prise_type_2) {
newProperties['socket:type_2:output'] = out;
}
if (has_prise_type_combo_ccs) {
newProperties['socket:type_2_combo:output'] = out;
}
if (prise_type_chademo) {
newProperties['socket:chademo:output'] = out;
}
if (prise_type_e) {
newProperties['socket:typee:output'] = out;
}
}
return out
} else {
return null
}
}
if (configObject.convert_to_phone) { if (configObject.convert_to_phone) {
@ -396,12 +452,7 @@ export default class {
convertedValue = conditionnalConfig.falsy_value convertedValue = conditionnalConfig.falsy_value
} }
} }
if (conditionnalConfig.transform_function) {
// une transformation de la valeur
// apply transformation to value
convertedValue = conditionnalConfig.transform_function(originalValue)
console.log('transform_function: originalValue', originalValue, convertedValue)
}
// use the value converted // use the value converted
else if (conditionnalConfig.value_converted) { else if (conditionnalConfig.value_converted) {
convertedValue = conditionnalConfig.value_converted convertedValue = conditionnalConfig.value_converted
@ -429,4 +480,24 @@ export default class {
return newProperties; return newProperties;
} }
private isTruthyValue(someValue: string) {
return this.truthyValues.includes(someValue)
}
private convertToBooleanValue(originalValue: any) {
debugLog('convertProperty: ==========> original value', originalValue)
let convertedValue = '';
if (this.truthyValues.indexOf(originalValue) !== -1) {
convertedValue = 'yes'
} else {
debugLog('convertProperty: ==========> !!! NOT in truthy values', originalValue)
}
if (this.falsyValues.indexOf(originalValue) !== -1) {
convertedValue = 'no'
} else {
debugLog('convertProperty: ==========> !!! NOT in falsy values', originalValue)
}
return convertedValue;
}
} }

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -12,7 +12,7 @@
"scripts": { "scripts": {
"start": "ts-node convert_to_osm_tags.ts --engine", "start": "ts-node convert_to_osm_tags.ts --engine",
"departments": "ts-node build_departments.ts", "departments": "ts-node build_departments.ts",
"variance": "ts-node make_variance_from_csv.ts --source=data_other/irve_osm_2023-08-30.csv", "variance": "ts-node make_variance_from_csv.ts --source=data_other/irve_latest.csv",
"example": "ts-node convert_to_osm_tags.ts --engine=true --department=974 --source=\"./etalab_data/irve_bornes_recharge/all.json\"", "example": "ts-node convert_to_osm_tags.ts --engine=true --department=974 --source=\"./etalab_data/irve_bornes_recharge/all.json\"",
"irve": "ts-node convert_to_osm_tags.ts --engine=true --source=\"./etalab_data/irve_bornes_recharge/all.json\"", "irve": "ts-node convert_to_osm_tags.ts --engine=true --source=\"./etalab_data/irve_bornes_recharge/all.json\"",
"irve:up": "bash update_scripts/get_irve.sh", "irve:up": "bash update_scripts/get_irve.sh",

View File

@ -8,8 +8,10 @@ overpass_website="https://overpass-api.de/api/interpreter"
output_file_name='irve_osm_latest' output_file_name='irve_osm_latest'
# récupérer le jeu de données étalab le plus récent # récupérer le jeu de données geojson étalab le plus récent
wget https://www.data.gouv.fr/fr/datasets/r/7eee8f09-5d1b-4f48-a304-5e99e8da1e26 -O ../etalab_data/irve_bornes_recharge/latest.json wget https://www.data.gouv.fr/fr/datasets/r/7eee8f09-5d1b-4f48-a304-5e99e8da1e26 -O ../etalab_data/irve_bornes_recharge/latest.json
# récupérer la version csv pour établir la variance
#irve_latest.csv
# récupérer les données présentes dans osm # récupérer les données présentes dans osm
#curl --header "Content-Type: plain/text" --data @content_irve_geojson.txt --trace-ascii website-data.log "$overpass_website" > "../data_other/$output_file_name.geojson" #curl --header "Content-Type: plain/text" --data @content_irve_geojson.txt --trace-ascii website-data.log "$overpass_website" > "../data_other/$output_file_name.geojson"