Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gather all the unit conversions into one file #2447

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e091acb
gather all the unit conversions into one file
ghazwarhili Dec 11, 2024
16ef55e
add licence
ghazwarhili Dec 11, 2024
302fe30
Merge branch 'main' into mutualize-unit-conversion-into-one-file
ghazwarhili Dec 11, 2024
3e1df6c
Merge branch 'main' into mutualize-unit-conversion-into-one-file
thangqp Dec 16, 2024
013ee58
Merge two fieldType from commons-ui and study
thangqp Dec 16, 2024
537d481
Merge branch 'main' into mutualize-unit-conversion-into-one-file
ghazwarhili Dec 17, 2024
1e7eb1f
fix fieldType
ghazwarhili Dec 17, 2024
23264ff
Merge remote-tracking branch 'origin/mutualize-unit-conversion-into-o…
ghazwarhili Dec 17, 2024
bdfed42
revert conversion unit for result table
ghazwarhili Dec 17, 2024
0865e4a
add conversion unit to modification by formula
ghazwarhili Dec 17, 2024
c1432f0
Merge branch 'main' into mutualize-unit-conversion-into-one-file
ghazwarhili Dec 17, 2024
853950c
adapt the conversion unit to modifcation by tabular
ghazwarhili Dec 17, 2024
d841b7b
Merge remote-tracking branch 'origin/mutualize-unit-conversion-into-o…
ghazwarhili Dec 17, 2024
ebadd4a
fix converter unit input or output
ghazwarhili Dec 18, 2024
c38b717
enhance the name of the mapper function
ghazwarhili Dec 18, 2024
724af3d
Merge branch 'main' into mutualize-unit-conversion-into-one-file
ghazwarhili Dec 18, 2024
2df7d90
rename MAXIMUM_SUSCEPTANCE to MAX_SUSCEPTANCE
thangqp Dec 18, 2024
f0fa241
revert modif in package.json
thangqp Dec 18, 2024
ba8a934
Merge branch 'main' into mutualize-unit-conversion-into-one-file
thangqp Dec 18, 2024
631011d
revert modif in package-lock.json
thangqp Dec 18, 2024
7b7d98b
Ignore maxSusceptance and maxQAtNominalV conversion in tabular
thangqp Dec 18, 2024
8eaab7c
Merge branch 'main' into mutualize-unit-conversion-into-one-file
ghazwarhili Dec 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
*/

import type { ReadonlyDeep } from 'type-fest';
import { DataType, FieldOptionType, FieldType } from './assignment.type';
import { DataType, FieldOptionType } from './assignment.type';
import { LOAD_TYPES } from '../../../../../network/constants';
import { EquipmentType, kiloUnitToUnit, microUnitToUnit, unitToKiloUnit, unitToMicroUnit } from '@gridsuite/commons-ui';
import { EquipmentType, FieldType } from '@gridsuite/commons-ui';
import { KILO_AMPERE, MICRO_SIEMENS } from '../../../../../utils/field-constants';

export const FIELD_OPTIONS = {
Expand Down Expand Up @@ -102,21 +102,17 @@ 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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MICRO_SIEMENS to SIEMENS

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same

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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MVar and not Micro S

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same

dataType: DataType.DOUBLE,
outputConverter: (value) => microUnitToUnit(value),
inputConverter: (value) => unitToMicroUnit(value),
},
NOMINAL_VOLTAGE: {
id: FieldType.NOMINAL_VOLTAGE,
Expand All @@ -138,16 +134,12 @@ export const FIELD_OPTIONS = {
label: 'LowShortCircuitCurrentLimit',
unit: KILO_AMPERE,
dataType: DataType.DOUBLE,
outputConverter: (value) => kiloUnitToUnit(value),
inputConverter: (value) => unitToKiloUnit(value),
},
HIGH_SHORT_CIRCUIT_CURRENT_LIMIT: {
id: FieldType.HIGH_SHORT_CIRCUIT_CURRENT_LIMIT,
label: 'HighShortCircuitCurrentLimit',
unit: KILO_AMPERE,
dataType: DataType.DOUBLE,
outputConverter: (value) => kiloUnitToUnit(value),
inputConverter: (value) => unitToKiloUnit(value),
},
ACTIVE_POWER: {
id: FieldType.ACTIVE_POWER,
Expand All @@ -174,16 +166,12 @@ export const FIELD_OPTIONS = {
label: 'G',
unit: MICRO_SIEMENS,
dataType: DataType.DOUBLE,
outputConverter: (value) => microUnitToUnit(value),
inputConverter: (value) => unitToMicroUnit(value),
},
B: {
id: FieldType.B,
label: 'B',
unit: MICRO_SIEMENS,
dataType: DataType.DOUBLE,
outputConverter: (value) => microUnitToUnit(value),
inputConverter: (value) => unitToMicroUnit(value),
},
RATED_U1: {
id: FieldType.RATED_U1,
Expand Down Expand Up @@ -314,8 +302,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 @@ -26,18 +26,6 @@ export const getFieldOption = (fieldName?: string | null) => {
return Object.values(FIELD_OPTIONS).find((fieldOption) => fieldOption.id === fieldName);
};

export const convertOutputValue = (fieldName?: string | null, fieldValue?: FieldValue) => {
const fieldOption = getFieldOption(fieldName);
// @ts-expect-error TODO TS2339: Property outputConverter does not exist on typeof FIELD_OPTIONS[*]
return fieldOption?.outputConverter ? fieldOption.outputConverter(Number(fieldValue)) : fieldValue;
};

export const convertInputValue = (fieldName?: string | null, fieldValue?: FieldValue) => {
const fieldOption = getFieldOption(fieldName);
// @ts-expect-error TODO TS2339: Property inputConverter does not exist on typeof FIELD_OPTIONS[*]
return fieldOption?.inputConverter ? fieldOption.inputConverter(Number(fieldValue)) : fieldValue;
};

// ("undefined" is accepted here in RHF, but it conflicts with MUI behaviour which does not like undefined values)
export const getAssignmentInitialValue = () => ({
[FILTERS]: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,52 +36,6 @@ export type FieldOptionType = {
inputConverter?: (value: number) => number | undefined;
};

export enum FieldType {
PROPERTY = 'PROPERTY',
RATED_NOMINAL_POWER = 'RATED_NOMINAL_POWER',
MINIMUM_ACTIVE_POWER = 'MINIMUM_ACTIVE_POWER',
MAXIMUM_ACTIVE_POWER = 'MAXIMUM_ACTIVE_POWER',
ACTIVE_POWER_SET_POINT = 'ACTIVE_POWER_SET_POINT',
REACTIVE_POWER_SET_POINT = 'REACTIVE_POWER_SET_POINT',
VOLTAGE_SET_POINT = 'VOLTAGE_SET_POINT',
PLANNED_ACTIVE_POWER_SET_POINT = 'PLANNED_ACTIVE_POWER_SET_POINT',
MARGINAL_COST = 'MARGINAL_COST',
PLANNED_OUTAGE_RATE = 'PLANNED_OUTAGE_RATE',
FORCED_OUTAGE_RATE = 'FORCED_OUTAGE_RATE',
DROOP = 'DROOP',
TRANSIENT_REACTANCE = 'TRANSIENT_REACTANCE',
STEP_UP_TRANSFORMER_REACTANCE = 'STEP_UP_TRANSFORMER_REACTANCE',
Q_PERCENT = 'Q_PERCENT',
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',
NOMINAL_VOLTAGE = 'NOMINAL_VOLTAGE',
LOW_VOLTAGE_LIMIT = 'LOW_VOLTAGE_LIMIT',
HIGH_VOLTAGE_LIMIT = 'HIGH_VOLTAGE_LIMIT',
LOW_SHORT_CIRCUIT_CURRENT_LIMIT = 'LOW_SHORT_CIRCUIT_CURRENT_LIMIT',
HIGH_SHORT_CIRCUIT_CURRENT_LIMIT = 'HIGH_SHORT_CIRCUIT_CURRENT_LIMIT',
ACTIVE_POWER = 'ACTIVE_POWER',
REACTIVE_POWER = 'REACTIVE_POWER',
R = 'R',
X = 'X',
G = 'G',
B = 'B',
RATED_U1 = 'RATED_U1',
RATED_U2 = 'RATED_U2',
RATED_S = 'RATED_S',
TARGET_V = 'TARGET_V',
RATIO_LOW_TAP_POSITION = 'RATIO_LOW_TAP_POSITION',
RATIO_TAP_POSITION = 'RATIO_TAP_POSITION',
RATIO_TARGET_DEADBAND = 'RATIO_TARGET_DEADBAND',
REGULATION_VALUE = 'REGULATION_VALUE',
PHASE_LOW_TAP_POSITION = 'PHASE_LOW_TAP_POSITION',
PHASE_TAP_POSITION = 'PHASE_TAP_POSITION',
PHASE_TARGET_DEADBAND = 'PHASE_TARGET_DEADBAND',
LOAD_TYPE = 'LOAD_TYPE',
}

// --- types for the form model --- //

export type Assignment = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@

import { yupResolver } from '@hookform/resolvers/yup';
import yup from 'components/utils/yup-config';
import { CustomFormProvider, useSnackMessage } from '@gridsuite/commons-ui';
import {
convertInputValues,
convertOutputValues,
CustomFormProvider,
FieldType,
useSnackMessage,
} from '@gridsuite/commons-ui';
import { FC, useCallback, useEffect } from 'react';
import { FetchStatus } from '../../../../../services/utils';
import { useForm } from 'react-hook-form';
Expand All @@ -18,8 +24,6 @@ import ModificationByAssignmentForm from './modification-by-assignment-form';
import { ASSIGNMENTS, EDITED_FIELD, EQUIPMENT_TYPE_FIELD, VALUE_FIELD } from '../../../../utils/field-constants';
import { modifyByAssignment } from '../../../../../services/study/network-modifications';
import {
convertInputValue,
convertOutputValue,
getAssignmentFromEditData,
getAssignmentInitialValue,
getAssignmentsSchema,
Expand Down Expand Up @@ -72,7 +76,10 @@ const ModificationByAssignmentDialog: FC<any> = ({
const assignments: Assignment[] =
editData.assignmentInfosList?.map((info: Assignment) => {
const assignment = getAssignmentFromEditData(info);
const valueConverted = convertInputValue(assignment[EDITED_FIELD], assignment[VALUE_FIELD]);
const fieldKey = assignment[EDITED_FIELD] as keyof typeof FieldType;
const field = FieldType[fieldKey];
const value = assignment[VALUE_FIELD];
const valueConverted = convertInputValues(field, value);
return {
...assignment,
[VALUE_FIELD]: valueConverted,
Expand All @@ -93,7 +100,10 @@ const ModificationByAssignmentDialog: FC<any> = ({
(formData: ModificationByAssignment) => {
const assignmentsList = formData[ASSIGNMENTS].map((assignment) => {
const dataType = getDataType(assignment[EDITED_FIELD]);
const valueConverted = convertOutputValue(assignment[EDITED_FIELD], assignment[VALUE_FIELD]);
const fieldKey = assignment[EDITED_FIELD] as keyof typeof FieldType;
const field = FieldType[fieldKey];
const value = assignment[VALUE_FIELD];
const valueConverted = convertOutputValues(field, value);
return {
...assignment,
dataType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@

import { yupResolver } from '@hookform/resolvers/yup';
import yup from 'components/utils/yup-config';
import { CustomFormProvider, useSnackMessage } from '@gridsuite/commons-ui';
import {
convertInputValues,
convertOutputValues,
CustomFormProvider,
FieldType,
useSnackMessage,
} from '@gridsuite/commons-ui';
import { useCallback, useEffect } from 'react';
import { FetchStatus } from '../../../../../services/utils';
import { useForm } from 'react-hook-form';
Expand All @@ -29,11 +35,11 @@ import {
import { modifyByFormula } from '../../../../../services/study/network-modifications';
import { getFormulaInitialValue, getFormulaSchema } from './formula/formula-utils';

function getFieldOrValue(input) {
function getFieldOrConvertedUnitValue(input, fieldType) {
const value = input.replace(',', '.');
const isNumber = !isNaN(parseFloat(value));
return {
[VALUE]: isNumber ? value : null,
[VALUE]: isNumber ? convertOutputValues(fieldType, value) : null,
[EQUIPMENT_FIELD]: isNumber ? null : input,
};
}
Expand Down Expand Up @@ -71,8 +77,16 @@ const ByFormulaDialog = ({ editData, currentNode, studyUuid, isUpdate, editDataF
useEffect(() => {
if (editData) {
const formulas = editData.formulaInfosList?.map((formula) => {
const ref1 = formula?.fieldOrValue1?.value?.toString() ?? formula?.fieldOrValue1?.equipmentField;
const ref2 = formula?.fieldOrValue2?.value?.toString() ?? formula?.fieldOrValue2?.equipmentField;
const valueConverted1 = convertInputValues(
FieldType[formula[EDITED_FIELD]],
formula?.fieldOrValue1?.value
);
const valueConverted2 = convertInputValues(
FieldType[formula[EDITED_FIELD]],
formula?.fieldOrValue2?.value
);
const ref1 = valueConverted1?.toString() ?? formula?.fieldOrValue1?.equipmentField;
const ref2 = valueConverted2?.toString() ?? formula?.fieldOrValue2?.equipmentField;
return {
[REFERENCE_FIELD_OR_VALUE_1]: ref1,
[REFERENCE_FIELD_OR_VALUE_2]: ref2,
Expand All @@ -95,8 +109,14 @@ const ByFormulaDialog = ({ editData, currentNode, studyUuid, isUpdate, editDataF
const onSubmit = useCallback(
(data) => {
const formulas = data[FORMULAS].map((formula) => {
const fieldOrValue1 = getFieldOrValue(formula[REFERENCE_FIELD_OR_VALUE_1]);
const fieldOrValue2 = getFieldOrValue(formula[REFERENCE_FIELD_OR_VALUE_2]);
const fieldOrValue1 = getFieldOrConvertedUnitValue(
formula[REFERENCE_FIELD_OR_VALUE_1],
FieldType[formula[EDITED_FIELD]]
);
const fieldOrValue2 = getFieldOrConvertedUnitValue(
formula[REFERENCE_FIELD_OR_VALUE_2],
FieldType[formula[EDITED_FIELD]]
);
return {
fieldOrValue1,
fieldOrValue2,
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 @@ -7,7 +7,7 @@

import { Grid } from '@mui/material';
import { MicroSusceptanceAdornment, OhmAdornment } from '../../../dialog-utils';
import { FloatInput } from '@gridsuite/commons-ui';
import { convertInputValues, FieldType, FloatInput } from '@gridsuite/commons-ui';
import { ConnectivityForm } from '../../../connectivity/connectivity-form';
import {
B1,
Expand All @@ -20,7 +20,6 @@ import {
R,
X,
} from 'components/utils/field-constants';
import { unitToMicroUnit } from 'utils/unit-converter';
import PropertiesForm from '../../common/properties/properties-form';
import useVoltageLevelsListInfos from '../../../../../hooks/use-voltage-levels-list-infos';
import GridSection from '../../../commons/grid-section';
Expand Down Expand Up @@ -70,7 +69,7 @@ const LineCharacteristicsPane = ({
name={`${id}.${G1}`}
label="ShuntConductanceText"
adornment={MicroSusceptanceAdornment}
previousValue={unitToMicroUnit(lineToModify?.g1)}
previousValue={convertInputValues(FieldType.G1, lineToModify?.g1)}
clearable={clearableFields}
/>
);
Expand All @@ -80,7 +79,7 @@ const LineCharacteristicsPane = ({
name={`${id}.${B1}`}
label="ShuntSusceptanceText"
adornment={MicroSusceptanceAdornment}
previousValue={unitToMicroUnit(lineToModify?.b1)}
previousValue={convertInputValues(FieldType.B1, lineToModify?.b1)}
clearable={clearableFields}
/>
);
Expand All @@ -90,7 +89,7 @@ const LineCharacteristicsPane = ({
name={`${id}.${G2}`}
label="ShuntConductanceText"
adornment={MicroSusceptanceAdornment}
previousValue={unitToMicroUnit(lineToModify?.g2)}
previousValue={convertInputValues(FieldType.G2, lineToModify?.g2)}
clearable={clearableFields}
/>
);
Expand All @@ -100,7 +99,7 @@ const LineCharacteristicsPane = ({
name={`${id}.${B2}`}
label="ShuntSusceptanceText"
adornment={MicroSusceptanceAdornment}
previousValue={unitToMicroUnit(lineToModify?.b2)}
previousValue={convertInputValues(FieldType.B2, lineToModify?.b2)}
clearable={clearableFields}
/>
);
Expand Down
Loading
Loading