mirror of
https://forge.chapril.org/tykayn/wololo
synced 2025-06-20 01:34:42 +02:00
add tests and utils : limit values, get max in enums
This commit is contained in:
parent
aa35803a0b
commit
b4c28335b2
10 changed files with 153 additions and 43 deletions
|
@ -2,7 +2,7 @@ import custom_utils from './utils'
|
|||
import MappingConfigType from "./mapping-config.type";
|
||||
import Formatters from "./formatters";
|
||||
|
||||
const {debugLog} = custom_utils
|
||||
const { debugLog, find_max_in_string, truncate_enums_to_limit } = custom_utils
|
||||
|
||||
let listOfBooleanKeys = [
|
||||
"prise_type_ef",
|
||||
|
@ -57,7 +57,7 @@ export default class {
|
|||
let geoJSONConvertedPoint: any = {}
|
||||
|
||||
|
||||
geoJSONConvertedPoint.properties = {...this.mapping_config.default_properties_of_point}
|
||||
geoJSONConvertedPoint.properties = { ...this.mapping_config.default_properties_of_point }
|
||||
geoJSONConvertedPoint.type = featurePointGeoJson.type
|
||||
geoJSONConvertedPoint.geometry = featurePointGeoJson.geometry
|
||||
|
||||
|
@ -130,7 +130,7 @@ export default class {
|
|||
return newList;
|
||||
}
|
||||
|
||||
filterListOfPointsByExcludingIfColumnBeforeSomeYear(year: number, column:string, list_of_points: any[]): any[] {
|
||||
filterListOfPointsByExcludingIfColumnBeforeSomeYear(year: number, column: string, list_of_points: any[]): any[] {
|
||||
let newList: any[] = []
|
||||
list_of_points.forEach((geojsonPoint: any) => {
|
||||
let pointProperties = Object.keys(geojsonPoint.properties)
|
||||
|
@ -138,7 +138,7 @@ export default class {
|
|||
|
||||
// on inclut les points dont la date de création est de l'année demandée ou supérieure
|
||||
if (pointProperties.includes(column) &&
|
||||
(geojsonPoint.properties[column].substring(0,4) * 1) >= year
|
||||
(geojsonPoint.properties[column].substring(0, 4) * 1) >= year
|
||||
) {
|
||||
newList.push(geojsonPoint)
|
||||
}
|
||||
|
@ -155,9 +155,12 @@ export default class {
|
|||
// trouver la valeur
|
||||
// socket_output_find_correspondances
|
||||
if (pointProperties.includes('puissance_nominale') &&
|
||||
1 * (geojsonPoint.properties['puissance_nominale'].replace(' kW', '')) > minValue
|
||||
1 * (geojsonPoint.properties['puissance_nominale'].replaceAll(' kW', '')) > minValue
|
||||
) {
|
||||
newList.push(geojsonPoint)
|
||||
let max_power = find_max_in_string(geojsonPoint.properties['puissance_nominale'])
|
||||
if (max_power >= minValue) {
|
||||
newList.push(geojsonPoint)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -176,28 +179,25 @@ export default class {
|
|||
|
||||
debugLog('mapElementFromConf: config_name', this.mapping_config.config_name)
|
||||
let mappingKeys = Object.keys(this.mapping_config.tags)
|
||||
let featurePointPropertiesKeys = []
|
||||
let featurePointPropertiesKeys: string[] = [];
|
||||
if (this.mapping_config.osmose) {
|
||||
// only creation of new points are handled by now [2023-10-07]
|
||||
featurePointPropertiesKeys = Object.keys(featurePoint.properties.fixes[0][0].create)
|
||||
// debugLog('featurePointPropertiesKeys', featurePointPropertiesKeys)
|
||||
|
||||
featurePointPropertiesKeys = Object.keys(featurePoint.properties.fixes[0][0].create);
|
||||
} else {
|
||||
featurePointPropertiesKeys = Object.keys(featurePoint.properties)
|
||||
featurePointPropertiesKeys = Object.keys(featurePoint.properties);
|
||||
}
|
||||
|
||||
|
||||
debugLog('mapElementFromConf: ============= keys mappingKeys:', this.mapping_config.tags.length, mappingKeys.length)
|
||||
debugLog('mapElementFromConf: ============= keys featurePointPropertiesKeys :', featurePoint.properties.length, featurePointPropertiesKeys.length)
|
||||
|
||||
let newProperties = {...this.mapping_config.default_properties_of_point}
|
||||
let newProperties = { ...this.mapping_config.default_properties_of_point }
|
||||
|
||||
|
||||
// reinit properties of current point
|
||||
let basePoint = Object.create(featurePoint)
|
||||
basePoint.type = featurePoint.type
|
||||
basePoint.geometry = featurePoint.geometry
|
||||
basePoint.properties = {...this.mapping_config.default_properties_of_point}
|
||||
basePoint.properties = { ...this.mapping_config.default_properties_of_point }
|
||||
|
||||
// apply new properties if found in mapping config
|
||||
featurePointPropertiesKeys.forEach(pointKeyName => {
|
||||
|
@ -279,6 +279,7 @@ export default class {
|
|||
let keyConvertedFromMapping = mappingKeys[mappingKeys.indexOf(pointKeyName)]
|
||||
let mappingConfigOfTag = this.mapping_config.tags[pointKeyName]
|
||||
|
||||
|
||||
debugLog('========== mappingConfigOfTag', mappingConfigOfTag)
|
||||
debugLog('convertProperty: found element', pointKeyName, '=>', keyConvertedFromMapping, 'value : ', valueConvertedFromMapping)
|
||||
let convertedValue = originalValue
|
||||
|
@ -387,13 +388,12 @@ export default class {
|
|||
}
|
||||
// ajouter les tags de socket newProperties
|
||||
|
||||
let converted_value = originalValue.replace(/[^\d\.\,]/g, '').replace(',', '.')
|
||||
let converted_value = find_max_in_string(originalValue.replaceAll('.00', '').replaceAll(',', '.'))
|
||||
let max_output = 401
|
||||
// do not limit accepted values
|
||||
let out = ''
|
||||
|
||||
if (intOriginalValue < max_output) {
|
||||
|
||||
// rajouter l'unité de puissance kW dans la valeur
|
||||
out = converted_value + ' kW'
|
||||
|
||||
|
@ -402,13 +402,13 @@ export default class {
|
|||
debugLog('too high kW value detected', originalValue)
|
||||
if (intOriginalValue > 1000 && intOriginalValue < 401000) {
|
||||
|
||||
let kilowatts = (parseFloat(converted_value) / 1000).toFixed(2).replace('.00', '');
|
||||
out = ('' + kilowatts + ' kW').replace('.00', '')
|
||||
let kilowatts = (converted_value / 1000).toFixed(2);
|
||||
out = ('' + kilowatts + ' kW').replaceAll('.00', '')
|
||||
debugLog('valeurs en Watts out', out, 'original:', originalValue)
|
||||
this.stats.power_output++
|
||||
}
|
||||
}
|
||||
out = (out).replace('.00', '')
|
||||
out = (out).replaceAll('.00', '')
|
||||
|
||||
// debug land
|
||||
if (has_prise_type_combo_ccs) {
|
||||
|
@ -453,6 +453,7 @@ export default class {
|
|||
debugLog('no sockets', this.current_geojson_point.properties.ref)
|
||||
}
|
||||
}
|
||||
convertedValue = out;
|
||||
return out
|
||||
|
||||
|
||||
|
@ -462,7 +463,8 @@ export default class {
|
|||
debugLog('invert boolean', convertedValue, originalValue)
|
||||
}
|
||||
if (configObject.remove_stars) {
|
||||
convertedValue = originalValue.replace('*', '')
|
||||
// Remplace toutes les occurrences de * de manière greedy
|
||||
convertedValue = originalValue.replaceAll('*', '')
|
||||
debugLog('remove_stars', convertedValue, originalValue)
|
||||
}
|
||||
|
||||
|
@ -490,6 +492,13 @@ export default class {
|
|||
if (configObject.ignore_if_truthy && this.truthyValues.indexOf(originalValue) !== -1) {
|
||||
remove_original_key = true
|
||||
}
|
||||
|
||||
if (configObject.truncate_enums_to_limit) {
|
||||
// console.log('configObject.truncate_enums_to_limit', configObject)
|
||||
convertedValue = custom_utils.truncate_enums_to_limit(convertedValue, configObject.truncate_enums_to_limit)
|
||||
debugLog('truncate_enums_to_limit => ', convertedValue)
|
||||
}
|
||||
|
||||
/**
|
||||
* config pour une clé
|
||||
* nous pouvons renseigner une string ou un objet décrivant les transformations à réaliser
|
||||
|
@ -570,7 +579,7 @@ export default class {
|
|||
debugLog('convertProperty: convertedValue ==========> {', newKey, ':', convertedValue, '}')
|
||||
debugLog(' =============== remove_original_key', newKey, remove_original_key)
|
||||
|
||||
let keysOfConfigObject = [];
|
||||
let keysOfConfigObject: string[] = [];
|
||||
let hasKeyIgnoreThisData = false;
|
||||
if (configObject) {
|
||||
keysOfConfigObject = Object.keys(configObject)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue