Skip to content

Commit

Permalink
add some check on the diagram curve pq (#2432)
Browse files Browse the repository at this point in the history
Signed-off-by: Rehili Ghazwa <ghazwarhili@gmail.com>
  • Loading branch information
ghazwarhili authored Dec 20, 2024
1 parent dd28fd0 commit 48e431e
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 251 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,8 @@ import {
getReactiveLimitsSchema,
} from '../../../reactive-limits/reactive-limits-utils';
import {
calculateCurvePointsToStore,
completeReactiveCapabilityCurvePointsData,
getRowEmptyFormData,
insertEmptyRowAtSecondToLastIndex,
REMOVE,
setCurrentReactiveCapabilityCurveTable,
} from '../../../reactive-limits/reactive-capability-curve/reactive-capability-utils';
import { useOpenShortWaitFetching } from '../../../commons/handle-modification-form';
import { EQUIPMENT_INFOS_TYPES, EQUIPMENT_TYPES } from 'components/utils/equipment-types';
Expand All @@ -73,6 +70,7 @@ import {
getConnectivityWithPositionEmptyFormData,
getConnectivityWithPositionValidationSchema,
} from '../../../connectivity/connectivity-form-utils';
import { isNodeBuilt } from '../../../../graph/util/model-functions';

const emptyFormData = {
[EQUIPMENT_NAME]: '',
Expand Down Expand Up @@ -156,10 +154,7 @@ const BatteryModificationDialog = ({
reactiveCapabilityCurveChoice: editData?.reactiveCapabilityCurve?.value ? 'CURVE' : 'MINMAX',
maximumReactivePower: editData?.maxQ?.value ?? null,
minimumReactivePower: editData?.minQ?.value ?? null,
reactiveCapabilityCurveTable:
editData?.reactiveCapabilityCurvePoints?.length > 0
? completeReactiveCapabilityCurvePointsData(editData?.reactiveCapabilityCurvePoints)
: [getRowEmptyFormData(), getRowEmptyFormData()],
reactiveCapabilityCurveTable: editData?.reactiveCapabilityCurvePoints ?? null,
}),
...getPropertiesFromModification(editData.properties),
});
Expand Down Expand Up @@ -203,43 +198,23 @@ const BatteryModificationDialog = ({
setDataFetchStatus(FetchStatus.RUNNING);
fetchNetworkElementInfos(
studyUuid,
currentNodeUuid,
currentNode.id,
EQUIPMENT_TYPES.BATTERY,
EQUIPMENT_INFOS_TYPES.FORM.type,
equipmentId,
true
)
.then((value) => {
if (value) {
// when editing modification form, first render should not trigger this reset
// which would empty the form instead of displaying data of existing form
const previousReactiveCapabilityCurveTable = value.reactiveCapabilityCurvePoints;
// on first render, we need to adjust the UI for the reactive capability curve table
// we need to check if the battery we fetch has reactive capability curve table
const previousReactiveCapabilityCurveTable = value?.reactiveCapabilityCurvePoints;
if (previousReactiveCapabilityCurveTable) {
const currentReactiveCapabilityCurveTable = getValues(
`${REACTIVE_LIMITS}.${REACTIVE_CAPABILITY_CURVE_TABLE}`
setCurrentReactiveCapabilityCurveTable(
previousReactiveCapabilityCurveTable,
`${REACTIVE_LIMITS}.${REACTIVE_CAPABILITY_CURVE_TABLE}`,
getValues,
setValue,
isNodeBuilt(currentNode)
);

const sizeDiff =
previousReactiveCapabilityCurveTable.length -
currentReactiveCapabilityCurveTable.length;

// if there are more values in previousValues table, we need to insert rows to current tables to match the number of previousValues table rows
if (sizeDiff > 0) {
for (let i = 0; i < sizeDiff; i++) {
insertEmptyRowAtSecondToLastIndex(currentReactiveCapabilityCurveTable);
}
setValue(
`${REACTIVE_LIMITS}.${REACTIVE_CAPABILITY_CURVE_TABLE}`,
currentReactiveCapabilityCurveTable
);
} else if (sizeDiff < 0) {
// if there are more values in current table, we need to add rows to previousValues tables to match the number of current table rows
for (let i = 0; i > sizeDiff; i--) {
insertEmptyRowAtSecondToLastIndex(previousReactiveCapabilityCurveTable);
}
}
}
setValue(
`${REACTIVE_LIMITS}.${REACTIVE_CAPABILITY_CURVE_CHOICE}`,
Expand Down Expand Up @@ -270,7 +245,7 @@ const BatteryModificationDialog = ({
setBatteryToModify(null);
}
},
[studyUuid, currentNodeUuid, getValues, setValue, setValuesAndEmptyOthers, reset, editData]
[studyUuid, currentNode, getValues, setValue, setValuesAndEmptyOthers, reset, editData]
);

useEffect(() => {
Expand All @@ -282,11 +257,6 @@ const BatteryModificationDialog = ({
const onSubmit = useCallback(
(battery) => {
const reactiveLimits = battery[REACTIVE_LIMITS];
const buildCurvePointsToStore = calculateCurvePointsToStore(
reactiveLimits[REACTIVE_CAPABILITY_CURVE_TABLE],
batteryToModify
);

const isReactiveCapabilityCurveOn = reactiveLimits[REACTIVE_CAPABILITY_CURVE_CHOICE] === 'CURVE';

modifyBattery({
Expand All @@ -310,7 +280,9 @@ const BatteryModificationDialog = ({
isReactiveCapabilityCurveOn: isReactiveCapabilityCurveOn,
maxQ: isReactiveCapabilityCurveOn ? null : reactiveLimits[MAXIMUM_REACTIVE_POWER],
minQ: isReactiveCapabilityCurveOn ? null : reactiveLimits[MINIMUM_REACTIVE_POWER],
reactiveCapabilityCurve: isReactiveCapabilityCurveOn ? buildCurvePointsToStore : null,
reactiveCapabilityCurve: isReactiveCapabilityCurveOn
? reactiveLimits[REACTIVE_CAPABILITY_CURVE_TABLE]
: null,
properties: toModificationProperties(battery),
}).catch((error) => {
snackError({
Expand All @@ -319,7 +291,7 @@ const BatteryModificationDialog = ({
});
});
},
[selectedId, batteryToModify, studyUuid, currentNodeUuid, editData?.uuid, snackError]
[selectedId, studyUuid, currentNodeUuid, editData?.uuid, snackError]
);

const open = useOpenShortWaitFetching({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,16 @@ export const FIELD_OPTIONS = {
label: 'sectionCount',
dataType: DataType.INTEGER,
},
MAXIMUM_SUSCEPTANCE: {
id: FieldType.MAXIMUM_SUSCEPTANCE,
MAX_SUSCEPTANCE: {
id: FieldType.MAX_SUSCEPTANCE,
label: 'maxSusceptance',
unit: MICRO_SIEMENS,
dataType: DataType.DOUBLE,
outputConverter: (value) => microUnitToUnit(value),
inputConverter: (value) => unitToMicroUnit(value),
},
MAXIMUM_Q_AT_NOMINAL_VOLTAGE: {
id: FieldType.MAXIMUM_Q_AT_NOMINAL_VOLTAGE,
MAX_Q_AT_NOMINAL_V: {
id: FieldType.MAX_Q_AT_NOMINAL_V,
label: 'maxQAtNominalV',
unit: MICRO_SIEMENS,
dataType: DataType.DOUBLE,
Expand Down Expand Up @@ -314,8 +314,8 @@ export const EQUIPMENTS_FIELDS = {
FIELD_OPTIONS.PROPERTY,
FIELD_OPTIONS.MAXIMUM_SECTION_COUNT,
FIELD_OPTIONS.SECTION_COUNT,
FIELD_OPTIONS.MAXIMUM_SUSCEPTANCE,
FIELD_OPTIONS.MAXIMUM_Q_AT_NOMINAL_VOLTAGE,
FIELD_OPTIONS.MAX_SUSCEPTANCE,
FIELD_OPTIONS.MAX_Q_AT_NOMINAL_V,
],
[EquipmentType.STATIC_VAR_COMPENSATOR]: [FIELD_OPTIONS.PROPERTY],
[EquipmentType.HVDC_LINE]: [FIELD_OPTIONS.PROPERTY],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ export enum FieldType {
VOLTAGE_REGULATOR_ON = 'VOLTAGE_REGULATOR_ON',
MAXIMUM_SECTION_COUNT = 'MAXIMUM_SECTION_COUNT',
SECTION_COUNT = 'SECTION_COUNT',
MAXIMUM_SUSCEPTANCE = 'MAXIMUM_SUSCEPTANCE',
MAXIMUM_Q_AT_NOMINAL_VOLTAGE = 'MAXIMUM_Q_AT_NOMINAL_VOLTAGE',
MAX_SUSCEPTANCE = 'MAX_SUSCEPTANCE',
MAX_Q_AT_NOMINAL_V = 'MAX_Q_AT_NOMINAL_V',
NOMINAL_VOLTAGE = 'NOMINAL_VOLTAGE',
LOW_VOLTAGE_LIMIT = 'LOW_VOLTAGE_LIMIT',
HIGH_VOLTAGE_LIMIT = 'HIGH_VOLTAGE_LIMIT',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ export const EQUIPMENTS_FIELDS: EquipmentFields = {
[EQUIPMENT_TYPES.SHUNT_COMPENSATOR]: [
{ id: 'MAXIMUM_SECTION_COUNT', label: 'maximumSectionCount' },
{ id: 'SECTION_COUNT', label: 'sectionCount' },
{ id: 'MAXIMUM_SUSCEPTANCE', label: 'maxSusceptance' },
{ id: 'MAXIMUM_Q_AT_NOMINAL_VOLTAGE', label: 'maxQAtNominalV' },
{ id: 'MAX_SUSCEPTANCE', label: 'maxSusceptance' },
{ id: 'MAX_Q_AT_NOMINAL_V', label: 'maxQAtNominalV' },
],
[EQUIPMENT_TYPES.VOLTAGE_LEVEL]: [
{ id: 'NOMINAL_VOLTAGE', label: 'NominalVoltage' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,8 @@ import {
} from '../../../reactive-limits/reactive-limits-utils';
import { getRegulatingTerminalFormData } from '../../../regulating-terminal/regulating-terminal-form-utils';
import {
calculateCurvePointsToStore,
completeReactiveCapabilityCurvePointsData,
getRowEmptyFormData,
insertEmptyRowAtSecondToLastIndex,
REMOVE,
setCurrentReactiveCapabilityCurveTable,
} from '../../../reactive-limits/reactive-capability-curve/reactive-capability-utils';
import { useOpenShortWaitFetching } from '../../../commons/handle-modification-form';
import { EQUIPMENT_INFOS_TYPES, EQUIPMENT_TYPES } from 'components/utils/equipment-types';
Expand All @@ -85,6 +82,7 @@ import {
getConnectivityWithPositionEmptyFormData,
getConnectivityWithPositionValidationSchema,
} from '../../../connectivity/connectivity-form-utils';
import { isNodeBuilt } from '../../../../graph/util/model-functions';

const emptyFormData = {
[EQUIPMENT_NAME]: '',
Expand Down Expand Up @@ -193,10 +191,7 @@ const GeneratorModificationDialog = ({
reactiveCapabilityCurveChoice: editData?.reactiveCapabilityCurve?.value ? 'CURVE' : 'MINMAX',
maximumReactivePower: editData?.maxQ?.value ?? null,
minimumReactivePower: editData?.minQ?.value ?? null,
reactiveCapabilityCurveTable:
editData?.reactiveCapabilityCurvePoints?.length > 0
? completeReactiveCapabilityCurvePointsData(editData?.reactiveCapabilityCurvePoints)
: [getRowEmptyFormData(), getRowEmptyFormData()],
reactiveCapabilityCurveTable: editData?.reactiveCapabilityCurvePoints ?? null,
}),
...getRegulatingTerminalFormData({
equipmentId: editData?.regulatingTerminalId?.value,
Expand Down Expand Up @@ -246,43 +241,23 @@ const GeneratorModificationDialog = ({
setDataFetchStatus(FetchStatus.RUNNING);
fetchNetworkElementInfos(
studyUuid,
currentNodeUuid,
currentNode.id,
EQUIPMENT_TYPES.GENERATOR,
EQUIPMENT_INFOS_TYPES.FORM.type,
equipmentId,
true
)
.then((value) => {
if (value) {
// when editing modification form, first render should not trigger this reset
// which would empty the form instead of displaying data of existing form
const previousReactiveCapabilityCurveTable = value.reactiveCapabilityCurvePoints;
// on first render, we need to adjust the UI for the reactive capability curve table
// we need to check if the generator we fetch has reactive capability curve table
const previousReactiveCapabilityCurveTable = value?.reactiveCapabilityCurvePoints;
if (previousReactiveCapabilityCurveTable) {
const currentReactiveCapabilityCurveTable = getValues(
`${REACTIVE_LIMITS}.${REACTIVE_CAPABILITY_CURVE_TABLE}`
setCurrentReactiveCapabilityCurveTable(
previousReactiveCapabilityCurveTable,
`${REACTIVE_LIMITS}.${REACTIVE_CAPABILITY_CURVE_TABLE}`,
getValues,
setValue,
isNodeBuilt(currentNode)
);

const sizeDiff =
previousReactiveCapabilityCurveTable.length -
currentReactiveCapabilityCurveTable.length;

// if there are more values in previousValues table, we need to insert rows to current tables to match the number of previousValues table rows
if (sizeDiff > 0) {
for (let i = 0; i < sizeDiff; i++) {
insertEmptyRowAtSecondToLastIndex(currentReactiveCapabilityCurveTable);
}
setValue(
`${REACTIVE_LIMITS}.${REACTIVE_CAPABILITY_CURVE_TABLE}`,
currentReactiveCapabilityCurveTable
);
} else if (sizeDiff < 0) {
// if there are more values in current table, we need to add rows to previousValues tables to match the number of current table rows
for (let i = 0; i > sizeDiff; i--) {
insertEmptyRowAtSecondToLastIndex(previousReactiveCapabilityCurveTable);
}
}
}
setValue(`${CONNECTIVITY}.${VOLTAGE_LEVEL}.${ID}`, value?.voltageLevelId);
setValue(`${CONNECTIVITY}.${BUS_OR_BUSBAR_SECTION}.${ID}`, value?.busOrBusbarSectionId);
Expand All @@ -309,7 +284,7 @@ const GeneratorModificationDialog = ({
setGeneratorToModify(null);
}
},
[studyUuid, currentNodeUuid, reset, getValues, setValue, setValuesAndEmptyOthers, editData]
[studyUuid, currentNode, reset, getValues, setValue, setValuesAndEmptyOthers, editData]
);

useEffect(() => {
Expand All @@ -331,13 +306,7 @@ const GeneratorModificationDialog = ({
const onSubmit = useCallback(
(generator) => {
const reactiveLimits = generator[REACTIVE_LIMITS];
const buildCurvePointsToStore = calculateCurvePointsToStore(
reactiveLimits[REACTIVE_CAPABILITY_CURVE_TABLE],
generatorToModify
);

const isReactiveCapabilityCurveOn = reactiveLimits[REACTIVE_CAPABILITY_CURVE_CHOICE] === 'CURVE';

const isDistantRegulation =
generator?.[VOLTAGE_REGULATION_TYPE] === REGULATION_TYPES.DISTANT.id ||
(generator[VOLTAGE_REGULATION_TYPE] === null &&
Expand Down Expand Up @@ -379,7 +348,9 @@ const GeneratorModificationDialog = ({
droop: generator[DROOP],
maxQ: isReactiveCapabilityCurveOn ? null : reactiveLimits[MAXIMUM_REACTIVE_POWER],
minQ: isReactiveCapabilityCurveOn ? null : reactiveLimits[MINIMUM_REACTIVE_POWER],
reactiveCapabilityCurve: isReactiveCapabilityCurveOn ? buildCurvePointsToStore : null,
reactiveCapabilityCurve: isReactiveCapabilityCurveOn
? reactiveLimits[REACTIVE_CAPABILITY_CURVE_TABLE]
: null,
properties: toModificationProperties(generator),
}).catch((error) => {
snackError({
Expand All @@ -388,15 +359,7 @@ const GeneratorModificationDialog = ({
});
});
},
[
selectedId,
generatorToModify,
getPreviousRegulationType,
studyUuid,
currentNodeUuid,
editData?.uuid,
snackError,
]
[selectedId, getPreviousRegulationType, studyUuid, currentNodeUuid, editData?.uuid, snackError]
);

const open = useOpenShortWaitFetching({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ import {
} from '../../../../reactive-limits/reactive-limits-utils';
import { UNDEFINED_CONNECTION_DIRECTION } from '../../../../../network/constants';
import { sanitizeString } from '../../../../dialog-utils';
import {
calculateCurvePointsToStore,
completeReactiveCapabilityCurvePointsData,
getRowEmptyFormData,
} from '../../../../reactive-limits/reactive-capability-curve/reactive-capability-utils';
import { toModificationOperation } from '../../../../../utils/utils';

export type UpdateReactiveCapabilityCurveTable = (action: string, index: number) => void;
Expand Down Expand Up @@ -230,10 +225,6 @@ export function getConverterStationModificationData(
converterStationToModify: ConverterStationElementModificationInfos | undefined
) {
const reactiveLimits = converterStation[REACTIVE_LIMITS];
const buildCurvePointsToStore = calculateCurvePointsToStore(
reactiveLimits[REACTIVE_CAPABILITY_CURVE_TABLE],
converterStationToModify
);
const isReactiveCapabilityCurveOn = reactiveLimits[REACTIVE_CAPABILITY_CURVE_CHOICE] === 'CURVE';

return {
Expand All @@ -249,7 +240,9 @@ export function getConverterStationModificationData(
reactiveCapabilityCurve: toModificationOperation(isReactiveCapabilityCurveOn),
minQ: toModificationOperation(isReactiveCapabilityCurveOn ? null : reactiveLimits[MINIMUM_REACTIVE_POWER]),
maxQ: toModificationOperation(isReactiveCapabilityCurveOn ? null : reactiveLimits[MAXIMUM_REACTIVE_POWER]),
reactiveCapabilityCurvePoints: isReactiveCapabilityCurveOn ? buildCurvePointsToStore : null,
reactiveCapabilityCurvePoints: isReactiveCapabilityCurveOn
? reactiveLimits[REACTIVE_CAPABILITY_CURVE_TABLE]
: null,
};
}

Expand Down Expand Up @@ -313,7 +306,7 @@ function getConverterStationReactiveLimits(converterStation: ConverterStationInt
reactiveCapabilityCurveChoice: 'MINMAX',
minimumReactivePower: converterStation.minQ,
maximumReactivePower: converterStation.maxQ,
reactiveCapabilityCurveTable: [getRowEmptyFormData(), getRowEmptyFormData()],
reactiveCapabilityCurveTable: converterStation?.reactiveCapabilityCurvePoints ?? null,
});
}

Expand All @@ -327,10 +320,7 @@ function getConverterStationModificationReactiveLimits(
: 'MINMAX',
maximumReactivePower: converterStationEditData?.maxQ?.value ?? null,
minimumReactivePower: converterStationEditData?.minQ?.value ?? null,
reactiveCapabilityCurveTable:
converterStationEditData?.reactiveCapabilityCurvePoints?.length > 0
? completeReactiveCapabilityCurvePointsData(converterStationEditData?.reactiveCapabilityCurvePoints)
: [getRowEmptyFormData(), getRowEmptyFormData()],
reactiveCapabilityCurveTable: converterStationEditData?.reactiveCapabilityCurvePoints ?? null,
}),
};
}
Expand Down
Loading

0 comments on commit 48e431e

Please sign in to comment.