mirror of
https://forge.chapril.org/tykayn/wololo
synced 2025-06-20 01:34:42 +02:00
109 lines
No EOL
3.6 KiB
TypeScript
109 lines
No EOL
3.6 KiB
TypeScript
import config from "../config";
|
|
import custom_utils from "./utils";
|
|
|
|
const { debugLog, find_max_in_string, boolToAddable } = custom_utils
|
|
|
|
|
|
function detectSocketOutputFromFeaturePoint(options: {
|
|
pointKeyName: string,
|
|
mappingKeys: any,
|
|
featurePoint: any,
|
|
newProperties: any,
|
|
originalValue: string
|
|
}) {
|
|
|
|
const { pointKeyName, mappingKeys, featurePoint, newProperties, originalValue } = options
|
|
let intOriginalValue = parseInt(originalValue)
|
|
|
|
// 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: boolean = custom_utils.isTruthyValue(featurePoint.properties.prise_type_2) || false
|
|
let has_prise_type_combo_ccs: boolean = custom_utils.isTruthyValue(featurePoint.properties.prise_type_combo_ccs) || false
|
|
let prise_type_chademo: boolean = custom_utils.isTruthyValue(featurePoint.properties.prise_type_chademo) || false
|
|
let prise_type_ef: boolean = custom_utils.isTruthyValue(featurePoint.properties.prise_type_ef) || false
|
|
let prise_type_e: boolean = custom_utils.isTruthyValue(featurePoint.properties.prise_type_e) || false
|
|
let prise_type_autre: boolean = custom_utils.isTruthyValue(featurePoint.properties.prise_type_autre) || false
|
|
|
|
let countOfSockets = (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)
|
|
);
|
|
if (countOfSockets > 0) {
|
|
we_use_max_output = true;
|
|
}
|
|
// ajouter les tags de socket newProperties
|
|
// certains producteurs de données donnent des énumérations de puissances
|
|
// on prend la valeur max
|
|
let converted_value = find_max_in_string(originalValue.replaceAll('.00', '').replaceAll(',', '.'))
|
|
|
|
// do not limit accepted values
|
|
let out = ''
|
|
let out_number = 0
|
|
|
|
if (intOriginalValue < config.irve_max_output) {
|
|
// rajouter l'unité de puissance kW dans la valeur
|
|
out_number = converted_value
|
|
out = converted_value + ' kW'
|
|
|
|
} else {
|
|
// prise en charge des valeurs en Watts et non en kW.
|
|
debugLog('too high kW value detected', originalValue)
|
|
if (intOriginalValue > 1000 && intOriginalValue < (config.irve_max_output * 1000)) {
|
|
|
|
let kilowatts = (converted_value / 1000).toFixed(2);
|
|
out = ('' + kilowatts + ' kW').replaceAll('.00', '')
|
|
debugLog('valeurs en Watts out', out, 'original:', originalValue)
|
|
|
|
}
|
|
}
|
|
out = (out).replaceAll('.0', '')
|
|
|
|
|
|
if (has_prise_type_combo_ccs && countOfSockets === 1) {
|
|
newProperties['socket:type2_combo:output'] = out;
|
|
|
|
}
|
|
|
|
if (we_use_max_output) {
|
|
newProperties['charging_station:output'] = out;
|
|
} else {
|
|
if (has_prise_type_2 && prise_type_e) {
|
|
newProperties['socket:type_2:output'] = out;
|
|
|
|
debugLog('2 prises, attribuer la plus haute valeur à la type 2', out)
|
|
}
|
|
// deviner les décomptes de sockets
|
|
if (countOfSockets === 1) {
|
|
|
|
if (has_prise_type_2) {
|
|
newProperties['socket:type_2:output'] = out;
|
|
newProperties['socket:type_2'] = 1;
|
|
|
|
|
|
}
|
|
if (has_prise_type_combo_ccs) {
|
|
newProperties['socket:type2_combo:output'] = out;
|
|
newProperties['socket:type2_combo'] = 1;
|
|
|
|
|
|
}
|
|
if (prise_type_chademo) {
|
|
newProperties['socket:chademo:output'] = out;
|
|
newProperties['socket:chademo'] = 1;
|
|
|
|
}
|
|
if (prise_type_e) {
|
|
newProperties['socket:typee:output'] = out;
|
|
newProperties['socket:typee'] = 1;
|
|
|
|
}
|
|
} else {
|
|
debugLog('no sockets')
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
export {
|
|
detectSocketOutputFromFeaturePoint
|
|
} |