From b5e40d8e86fb513249e67d69271156cc6056b93e Mon Sep 17 00:00:00 2001 From: Thang PHAM <117309322+thangqp@users.noreply.github.com> Date: Fri, 12 Jul 2024 18:09:23 +0200 Subject: [PATCH] [GridDyna] Using gridsuite filter library for mapping (#95) --- pom.xml | 7 + .../ds/server/DynamicSimulationException.java | 13 +- .../RestResponseEntityExceptionHandler.java | 6 +- .../dto/dynamicmapping/InputMapping.java | 27 +++ .../dto/dynamicmapping/ParameterFile.java | 23 +++ .../ds/server/dto/dynamicmapping/Rule.java | 36 ++++ .../ds/server/dto/dynamicmapping/Script.java | 36 ---- .../dynamicmapping/automata/Automaton.java | 26 +++ .../automata/BasicProperty.java | 26 +++ .../DynamicSimulationWorkerService.java | 38 ++-- .../ds/server/service/client/RestClient.java | 2 +- .../dynamicmapping/DynamicMappingClient.java | 14 +- .../impl/DynamicMappingClientImpl.java | 45 +++-- .../timeseries/impl/TimeSeriesClientImpl.java | 2 +- .../server/service/client/utils/UrlUtils.java | 9 +- .../contexts/DynamicSimulationRunContext.java | 18 +- .../CurveGroovyGeneratorService.java | 1 - .../EventGroovyGeneratorService.java | 27 --- .../service/parameters/ParametersService.java | 8 +- .../impl/CurveGroovyGeneratorServiceImpl.java | 10 +- .../impl/EventGroovyGeneratorServiceImpl.java | 88 --------- .../impl/ParametersServiceImpl.java | 119 ++++++++++-- .../ds/server/utils/PropertyType.java | 3 +- .../ds/server/utils/SetGroupType.java | 25 +++ .../org/gridsuite/ds/server/utils/Utils.java | 62 +++++- src/main/resources/templates/event/event.st | 3 - .../templates/event/eventProperty.st | 1 - src/main/resources/templates/event/events.st | 10 - ...stractDynamicSimulationControllerTest.java | 4 +- ...DynamicSimulationControllerIEEE14Test.java | 50 ++--- .../DynamicSimulationControllerTest.java | 17 +- .../ds/server/controller/utils/FileUtils.java | 1 + .../controller/utils/ParameterUtils.java | 15 +- .../ds/server/controller/utils/TestUtils.java | 2 +- .../dto/XmlSerializableParameterTest.java | 12 +- .../DynamicMappingClientTest.java | 79 +++----- .../timeseries/TimeSeriesClientTest.java | 7 +- .../data/ieee14/_01/input/mapping.json | 183 ++++++++++++++++++ .../data/ieee14/_01/input/models.groovy | 78 -------- .../data/ieee14/_01/output/result_SIM.json | 90 ++++----- src/test/resources/dynamicModels.groovy | 35 ---- 41 files changed, 751 insertions(+), 507 deletions(-) create mode 100644 src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/InputMapping.java create mode 100644 src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/ParameterFile.java create mode 100644 src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Rule.java delete mode 100644 src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Script.java create mode 100644 src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/automata/Automaton.java create mode 100644 src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/automata/BasicProperty.java delete mode 100644 src/main/java/org/gridsuite/ds/server/service/parameters/EventGroovyGeneratorService.java delete mode 100644 src/main/java/org/gridsuite/ds/server/service/parameters/impl/EventGroovyGeneratorServiceImpl.java create mode 100644 src/main/java/org/gridsuite/ds/server/utils/SetGroupType.java delete mode 100644 src/main/resources/templates/event/event.st delete mode 100644 src/main/resources/templates/event/eventProperty.st delete mode 100644 src/main/resources/templates/event/events.st create mode 100644 src/test/resources/data/ieee14/_01/input/mapping.json delete mode 100644 src/test/resources/data/ieee14/_01/input/models.groovy delete mode 100644 src/test/resources/dynamicModels.groovy diff --git a/pom.xml b/pom.xml index b99e5fdf..c810b272 100644 --- a/pom.xml +++ b/pom.xml @@ -141,10 +141,17 @@ com.powsybl powsybl-dynawaltz + 2.5.0-alpha-1 com.powsybl powsybl-dynawaltz-dsl + 2.5.0-alpha-1 + + + org.gridsuite + gridsuite-filter + 1.0.9 com.powsybl diff --git a/src/main/java/org/gridsuite/ds/server/DynamicSimulationException.java b/src/main/java/org/gridsuite/ds/server/DynamicSimulationException.java index ebc410bc..f1043b4b 100644 --- a/src/main/java/org/gridsuite/ds/server/DynamicSimulationException.java +++ b/src/main/java/org/gridsuite/ds/server/DynamicSimulationException.java @@ -6,9 +6,12 @@ */ package org.gridsuite.ds.server; +import lombok.Getter; + /** * @author Abdelsalem Hedhili */ +@Getter public class DynamicSimulationException extends RuntimeException { public enum Type { @@ -17,9 +20,11 @@ public enum Type { MAPPING_NOT_PROVIDED, RESULT_UUID_NOT_FOUND, DYNAMIC_MAPPING_NOT_FOUND, - CREATE_MAPPING_SCRIPT_ERROR, + EXPORT_PARAMETERS_ERROR, + GET_DYNAMIC_MAPPING_ERROR, CREATE_TIME_SERIES_ERROR, - DELETE_TIME_SERIES_ERROR + DELETE_TIME_SERIES_ERROR, + MAPPING_NOT_LAST_RULE_WITH_EMPTY_FILTER_ERROR, } private final Type type; @@ -28,8 +33,4 @@ public DynamicSimulationException(Type type, String message) { super(message); this.type = type; } - - public Type getType() { - return type; - } } diff --git a/src/main/java/org/gridsuite/ds/server/RestResponseEntityExceptionHandler.java b/src/main/java/org/gridsuite/ds/server/RestResponseEntityExceptionHandler.java index 5f356fc1..685672aa 100644 --- a/src/main/java/org/gridsuite/ds/server/RestResponseEntityExceptionHandler.java +++ b/src/main/java/org/gridsuite/ds/server/RestResponseEntityExceptionHandler.java @@ -34,11 +34,13 @@ protected ResponseEntity handleDynamicSimulationException(DynamicSimulat PROVIDER_NOT_FOUND -> ResponseEntity.status(HttpStatus.NOT_FOUND).body(exception.getMessage()); case URI_SYNTAX, - CREATE_MAPPING_SCRIPT_ERROR, + GET_DYNAMIC_MAPPING_ERROR, + EXPORT_PARAMETERS_ERROR, CREATE_TIME_SERIES_ERROR, DELETE_TIME_SERIES_ERROR -> ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(exception.getMessage()); - case MAPPING_NOT_PROVIDED + case MAPPING_NOT_PROVIDED, + MAPPING_NOT_LAST_RULE_WITH_EMPTY_FILTER_ERROR -> ResponseEntity.status(HttpStatus.BAD_REQUEST).body(exception.getMessage()); }; } diff --git a/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/InputMapping.java b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/InputMapping.java new file mode 100644 index 00000000..9f94ab0c --- /dev/null +++ b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/InputMapping.java @@ -0,0 +1,27 @@ +/** + * Copyright (c) 2024, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.gridsuite.ds.server.dto.dynamicmapping; + +import io.swagger.v3.oas.annotations.media.Schema; +import org.gridsuite.ds.server.dto.dynamicmapping.automata.Automaton; + +import java.util.List; + +/** + * @author Thang PHAM + */ +@Schema(description = "Mapping") +public record InputMapping( + @Schema(description = "Name") + String name, + @Schema(description = "Rules") + List rules, + @Schema(description = "Automata") + List automata +) { + +} diff --git a/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/ParameterFile.java b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/ParameterFile.java new file mode 100644 index 00000000..d11d12cc --- /dev/null +++ b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/ParameterFile.java @@ -0,0 +1,23 @@ +/** + * Copyright (c) 2024, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.gridsuite.ds.server.dto.dynamicmapping; + +import io.swagger.v3.oas.annotations.media.Schema; + +/** + * @author Thang PHAM + */ +@Schema(description = "Parameter sets in *.par format") +public record ParameterFile( + @Schema(description = "Name of the parent mapping") + String mappingName, + + @Schema(description = "Parameter file content in *.par format") + String fileContent +) { + +} diff --git a/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Rule.java b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Rule.java new file mode 100644 index 00000000..bb3deb13 --- /dev/null +++ b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Rule.java @@ -0,0 +1,36 @@ +/** + * Copyright (c) 2024, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.gridsuite.ds.server.dto.dynamicmapping; + +import io.swagger.v3.oas.annotations.media.Schema; +import org.gridsuite.ds.server.utils.SetGroupType; +import org.gridsuite.filter.expertfilter.ExpertFilter; +import org.gridsuite.filter.utils.EquipmentType; + +/** + * @author Thang PHAM + */ +@Schema(description = "Rule") +public record Rule( + @Schema(description = "Equipment type") + EquipmentType equipmentType, + + @Schema(description = "Mapped Model Instance ID") + String mappedModel, + + @Schema(description = "Mapped Parameter Set Group ID") + String setGroup, + + @Schema(description = "Mapped Parameter Set Group Type") + SetGroupType groupType, + + @Schema(description = "Filter") + ExpertFilter filter +) { + +} + diff --git a/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Script.java b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Script.java deleted file mode 100644 index 22d37a26..00000000 --- a/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Script.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Copyright (c) 2022, RTE (http://www.rte-france.com) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package org.gridsuite.ds.server.dto.dynamicmapping; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -import java.util.Date; - -/** - * @author Thang PHAM - */ -@NoArgsConstructor -@AllArgsConstructor -@Getter -@Setter -public class Script { - - private String name; - - // name of the original mapping - private String parentName; - - private String script; - - private Date createdDate; - - private String parametersFile; - -} diff --git a/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/automata/Automaton.java b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/automata/Automaton.java new file mode 100644 index 00000000..56deea6b --- /dev/null +++ b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/automata/Automaton.java @@ -0,0 +1,26 @@ +/** + * Copyright (c) 2024, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.gridsuite.ds.server.dto.dynamicmapping.automata; + +import io.swagger.v3.oas.annotations.media.Schema; + +import java.util.List; + +/** + * @author Thang PHAM + */ +@Schema(description = "Automaton") +public record Automaton( + @Schema(description = "Mapped Model Instance ID") + String model, + @Schema(description = "Mapped Parameters Set Group ID") + String setGroup, + @Schema(description = "Properties of automaton model") + List properties +) { + +} diff --git a/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/automata/BasicProperty.java b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/automata/BasicProperty.java new file mode 100644 index 00000000..d03864bd --- /dev/null +++ b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/automata/BasicProperty.java @@ -0,0 +1,26 @@ +/** + * Copyright (c) 2024, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +package org.gridsuite.ds.server.dto.dynamicmapping.automata; + +import io.swagger.v3.oas.annotations.media.Schema; +import org.gridsuite.ds.server.utils.PropertyType; + +/** + * @author Thang PHAM + */ +@Schema(description = "Basic property") +public record BasicProperty( + @Schema(description = "Property name") + String name, + @Schema(description = "Property value in string representation") + String value, + @Schema(description = "Property type") + PropertyType type +) { + +} diff --git a/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java b/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java index d43222cd..41803e38 100644 --- a/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java +++ b/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java @@ -11,18 +11,25 @@ import com.powsybl.commons.PowsyblException; import com.powsybl.computation.ComputationManager; import com.powsybl.dynamicsimulation.*; -import com.powsybl.dynamicsimulation.groovy.*; +import com.powsybl.dynamicsimulation.groovy.CurveGroovyExtension; +import com.powsybl.dynamicsimulation.groovy.GroovyCurvesSupplier; +import com.powsybl.dynamicsimulation.groovy.GroovyExtension; import com.powsybl.dynawaltz.DynaWaltzProvider; +import com.powsybl.dynawaltz.suppliers.dynamicmodels.DynamicModelConfig; +import com.powsybl.dynawaltz.suppliers.dynamicmodels.DynawoModelsSupplier; +import com.powsybl.dynawaltz.suppliers.events.DynawoEventModelsSupplier; +import com.powsybl.dynawaltz.suppliers.events.EventModelConfig; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.VariantManagerConstants; import com.powsybl.network.store.client.NetworkStoreService; import com.powsybl.timeseries.IrregularTimeSeriesIndex; import com.powsybl.timeseries.TimeSeries; -import org.apache.commons.collections4.CollectionUtils; import com.powsybl.ws.commons.computation.service.*; +import org.apache.commons.collections4.CollectionUtils; import org.gridsuite.ds.server.dto.DynamicSimulationParametersInfos; import org.gridsuite.ds.server.dto.DynamicSimulationStatus; -import org.gridsuite.ds.server.dto.dynamicmapping.Script; +import org.gridsuite.ds.server.dto.dynamicmapping.InputMapping; +import org.gridsuite.ds.server.dto.dynamicmapping.ParameterFile; import org.gridsuite.ds.server.service.client.dynamicmapping.DynamicMappingClient; import org.gridsuite.ds.server.service.contexts.DynamicSimulationResultContext; import org.gridsuite.ds.server.service.contexts.DynamicSimulationRunContext; @@ -127,21 +134,24 @@ public void preRun(DynamicSimulationRunContext runContext) { super.preRun(runContext); DynamicSimulationParametersInfos parametersInfos = runContext.getParameters(); - // get script and parameters file from dynamic mapping server - Script scriptObj = dynamicMappingClient.createFromMapping(runContext.getMapping()); + // get parameters file from dynamic mapping server + ParameterFile parameterFile = dynamicMappingClient.exportParameters(runContext.getMapping()); // get all dynamic simulation parameters - String parametersFile = scriptObj.getParametersFile(); + String parameterFileContent = parameterFile.fileContent(); DynamicSimulationParameters parameters = parametersService.getDynamicSimulationParameters( - parametersFile.getBytes(StandardCharsets.UTF_8), runContext.getProvider(), parametersInfos); + parameterFileContent.getBytes(StandardCharsets.UTF_8), runContext.getProvider(), parametersInfos); + + // get mapping then generate dynamic model configs + InputMapping inputMapping = dynamicMappingClient.getMapping(runContext.getMapping()); + List dynamicModel = parametersService.getDynamicModel(inputMapping, runContext.getNetwork()); + List eventModel = parametersService.getEventModel(parametersInfos.getEvents()); // set start and stop times parameters.setStartTime(parametersInfos.getStartTime().intValue()); // TODO remove intValue() when correct startTime to double in powsybl parameters.setStopTime(parametersInfos.getStopTime().intValue()); // TODO remove intValue() when correct stopTime to double in powsybl // groovy scripts - String dynamicModel = scriptObj.getScript(); - String eventModel = parametersService.getEventModel(parametersInfos.getEvents()); String curveModel = parametersService.getCurveModel(parametersInfos.getCurves()); // enrich runContext @@ -154,15 +164,9 @@ public void preRun(DynamicSimulationRunContext runContext) { @Override public CompletableFuture getCompletableFuture(DynamicSimulationRunContext runContext, String provider, UUID resultUuid) { - List dynamicModelExtensions = GroovyExtension.find(DynamicModelGroovyExtension.class, DynaWaltzProvider.NAME); - DynamicModelsSupplier dynamicModelsSupplier = new GroovyDynamicModelsSupplier( - new ByteArrayInputStream(runContext.getDynamicModelContent().getBytes()), dynamicModelExtensions - ); + DynamicModelsSupplier dynamicModelsSupplier = new DynawoModelsSupplier(runContext.getDynamicModelContent()); - List eventModelExtensions = GroovyExtension.find(EventModelGroovyExtension.class, DynaWaltzProvider.NAME); - EventModelsSupplier eventModelsSupplier = new GroovyEventModelsSupplier( - new ByteArrayInputStream(runContext.getEventModelContent().getBytes()), eventModelExtensions - ); + EventModelsSupplier eventModelsSupplier = new DynawoEventModelsSupplier(runContext.getEventModelContent()); List curveExtensions = GroovyExtension.find(CurveGroovyExtension.class, DynaWaltzProvider.NAME); CurvesSupplier curvesSupplier = new GroovyCurvesSupplier( diff --git a/src/main/java/org/gridsuite/ds/server/service/client/RestClient.java b/src/main/java/org/gridsuite/ds/server/service/client/RestClient.java index 6f3e8417..a0072777 100644 --- a/src/main/java/org/gridsuite/ds/server/service/client/RestClient.java +++ b/src/main/java/org/gridsuite/ds/server/service/client/RestClient.java @@ -14,7 +14,7 @@ * @author Thang PHAM */ public interface RestClient { - String DELIMITER = "/"; + String URL_DELIMITER = "/"; RestTemplate getRestTemplate(); diff --git a/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClient.java b/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClient.java index ecc4b32e..40118108 100644 --- a/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClient.java +++ b/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClient.java @@ -6,17 +6,21 @@ */ package org.gridsuite.ds.server.service.client.dynamicmapping; -import org.gridsuite.ds.server.dto.dynamicmapping.Script; +import org.gridsuite.ds.server.dto.dynamicmapping.InputMapping; +import org.gridsuite.ds.server.dto.dynamicmapping.ParameterFile; -import static org.gridsuite.ds.server.service.client.RestClient.DELIMITER; +import static org.gridsuite.ds.server.service.client.RestClient.URL_DELIMITER; /** * @author Thang PHAM */ public interface DynamicMappingClient { String API_VERSION = ""; - String DYNAMIC_MAPPING_SCRIPT_BASE_END_POINT = "scripts"; - String DYNAMIC_MAPPING_SCRIPT_CREATE_END_POINT = DYNAMIC_MAPPING_SCRIPT_BASE_END_POINT + DELIMITER + "from"; + String DYNAMIC_MAPPING_PARAMETERS_BASE_ENDPOINT = "parameters"; + String DYNAMIC_MAPPING_PARAMETERS_EXPORT_ENDPOINT = DYNAMIC_MAPPING_PARAMETERS_BASE_ENDPOINT + URL_DELIMITER + "export"; + String DYNAMIC_MAPPING_MAPPINGS_BASE_ENDPOINT = "mappings"; - Script createFromMapping(String mappingName); + ParameterFile exportParameters(String mappingName); + + InputMapping getMapping(String mappingName); } diff --git a/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/impl/DynamicMappingClientImpl.java b/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/impl/DynamicMappingClientImpl.java index ed7a9227..a8348568 100644 --- a/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/impl/DynamicMappingClientImpl.java +++ b/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/impl/DynamicMappingClientImpl.java @@ -8,7 +8,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.gridsuite.ds.server.DynamicSimulationException; -import org.gridsuite.ds.server.dto.dynamicmapping.Script; +import org.gridsuite.ds.server.dto.dynamicmapping.InputMapping; +import org.gridsuite.ds.server.dto.dynamicmapping.ParameterFile; import org.gridsuite.ds.server.service.client.AbstractRestClient; import org.gridsuite.ds.server.service.client.dynamicmapping.DynamicMappingClient; import org.springframework.beans.factory.annotation.Autowired; @@ -17,12 +18,12 @@ import org.springframework.stereotype.Service; import org.springframework.web.client.HttpStatusCodeException; import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.UriComponents; import org.springframework.web.util.UriComponentsBuilder; import java.util.Objects; -import static org.gridsuite.ds.server.DynamicSimulationException.Type.CREATE_MAPPING_SCRIPT_ERROR; -import static org.gridsuite.ds.server.DynamicSimulationException.Type.DYNAMIC_MAPPING_NOT_FOUND; +import static org.gridsuite.ds.server.DynamicSimulationException.Type.*; import static org.gridsuite.ds.server.service.client.utils.ExceptionUtils.handleHttpError; import static org.gridsuite.ds.server.service.client.utils.UrlUtils.buildEndPointUrl; @@ -38,25 +39,45 @@ public DynamicMappingClientImpl(@Value("${gridsuite.services.dynamic-mapping-ser } @Override - public Script createFromMapping(String mappingName) { + public ParameterFile exportParameters(String mappingName) { Objects.requireNonNull(mappingName); - String endPointUrl = buildEndPointUrl(getBaseUri(), API_VERSION, DYNAMIC_MAPPING_SCRIPT_CREATE_END_POINT); + String endPointUrl = buildEndPointUrl(getBaseUri(), API_VERSION, DYNAMIC_MAPPING_PARAMETERS_EXPORT_ENDPOINT); - UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromHttpUrl(endPointUrl + DELIMITER + "{mappingName}"); + UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromHttpUrl(endPointUrl); + uriComponentsBuilder.queryParam("mappingName", mappingName); + var uriComponents = uriComponentsBuilder.build(); - // to export script and not persist - uriComponentsBuilder.queryParam("persistent", false); - var uriComponents = uriComponentsBuilder.buildAndExpand(mappingName); + // call dynamic mapping Rest API + try { + return getRestTemplate().getForObject(uriComponents.toUriString(), ParameterFile.class); + } catch (HttpStatusCodeException e) { + if (HttpStatus.NOT_FOUND.equals(e.getStatusCode())) { + throw new DynamicSimulationException(DYNAMIC_MAPPING_NOT_FOUND, "No mapping has been found with name: " + mappingName); + } else { + throw handleHttpError(e, EXPORT_PARAMETERS_ERROR, getObjectMapper()); + } + } + } + + @Override + public InputMapping getMapping(String mappingName) { + Objects.requireNonNull(mappingName); + + String endPointUrl = buildEndPointUrl(getBaseUri(), API_VERSION, DYNAMIC_MAPPING_MAPPINGS_BASE_ENDPOINT); + + UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromHttpUrl(endPointUrl + URL_DELIMITER + "{mappingName}"); + + UriComponents uriComponents = uriComponentsBuilder.buildAndExpand(mappingName); // call dynamic mapping Rest API try { - return getRestTemplate().getForObject(uriComponents.toUriString(), Script.class); + return getRestTemplate().getForObject(uriComponents.toUriString(), InputMapping.class); } catch (HttpStatusCodeException e) { if (HttpStatus.NOT_FOUND.equals(e.getStatusCode())) { - throw new DynamicSimulationException(DYNAMIC_MAPPING_NOT_FOUND, "Mapping not found: " + mappingName); + throw new DynamicSimulationException(DYNAMIC_MAPPING_NOT_FOUND, "No mapping has been found with name: " + mappingName); } else { - throw handleHttpError(e, CREATE_MAPPING_SCRIPT_ERROR, getObjectMapper()); + throw handleHttpError(e, GET_DYNAMIC_MAPPING_ERROR, getObjectMapper()); } } } diff --git a/src/main/java/org/gridsuite/ds/server/service/client/timeseries/impl/TimeSeriesClientImpl.java b/src/main/java/org/gridsuite/ds/server/service/client/timeseries/impl/TimeSeriesClientImpl.java index 56473e7c..42aca434 100644 --- a/src/main/java/org/gridsuite/ds/server/service/client/timeseries/impl/TimeSeriesClientImpl.java +++ b/src/main/java/org/gridsuite/ds/server/service/client/timeseries/impl/TimeSeriesClientImpl.java @@ -74,7 +74,7 @@ public void deleteTimeSeriesGroup(UUID groupUuid) { String endPointUrl = buildEndPointUrl(getBaseUri(), API_VERSION, TIME_SERIES_END_POINT); - UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromHttpUrl(endPointUrl + DELIMITER + "{groupUuid}"); + UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromHttpUrl(endPointUrl + URL_DELIMITER + "{groupUuid}"); var uriComponents = uriComponentsBuilder.buildAndExpand(groupUuid); // call time-series Rest API diff --git a/src/main/java/org/gridsuite/ds/server/service/client/utils/UrlUtils.java b/src/main/java/org/gridsuite/ds/server/service/client/utils/UrlUtils.java index 48004ead..8d6b0335 100644 --- a/src/main/java/org/gridsuite/ds/server/service/client/utils/UrlUtils.java +++ b/src/main/java/org/gridsuite/ds/server/service/client/utils/UrlUtils.java @@ -14,14 +14,14 @@ import java.net.URISyntaxException; import static org.gridsuite.ds.server.DynamicSimulationException.Type.URI_SYNTAX; -import static org.gridsuite.ds.server.service.client.RestClient.DELIMITER; +import static org.gridsuite.ds.server.service.client.RestClient.URL_DELIMITER; /** * @author Thang PHAM */ public final class UrlUtils { private UrlUtils() { - throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); + throw new AssertionError("Utility class should not be instantiated"); } /** @@ -34,12 +34,11 @@ private UrlUtils() { public static String buildEndPointUrl(String baseUri, String apiVersion, String endPoint) { try { var sb = new StringBuilder(baseUri); - sb.append(DELIMITER); if (Strings.isNotBlank(apiVersion)) { - sb.append(apiVersion).append(DELIMITER); + sb.append(URL_DELIMITER).append(apiVersion); } if (Strings.isNotBlank(endPoint)) { - sb.append(endPoint); + sb.append(URL_DELIMITER).append(endPoint); } var url = sb.toString(); diff --git a/src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationRunContext.java b/src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationRunContext.java index 81ceb9ea..5a38c4ff 100644 --- a/src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationRunContext.java +++ b/src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationRunContext.java @@ -7,31 +7,35 @@ package org.gridsuite.ds.server.service.contexts; import com.powsybl.dynamicsimulation.DynamicSimulationParameters; +import com.powsybl.dynawaltz.suppliers.dynamicmodels.DynamicModelConfig; +import com.powsybl.dynawaltz.suppliers.events.EventModelConfig; +import com.powsybl.ws.commons.computation.dto.ReportInfos; +import com.powsybl.ws.commons.computation.service.AbstractComputationRunContext; import lombok.Builder; import lombok.Getter; import lombok.Setter; -import com.powsybl.ws.commons.computation.dto.ReportInfos; -import com.powsybl.ws.commons.computation.service.AbstractComputationRunContext; import org.gridsuite.ds.server.dto.DynamicSimulationParametersInfos; +import java.util.List; import java.util.UUID; /** * @author Abdelsalem Hedhili */ @Getter +@Setter public class DynamicSimulationRunContext extends AbstractComputationRunContext { - @Setter private String mapping; + private String mapping; // fields which are enriched in worker service - @Setter private String dynamicModelContent; + private List dynamicModelContent; - @Setter private String eventModelContent; + private List eventModelContent; - @Setter private String curveContent; + private String curveContent; - @Setter private DynamicSimulationParameters dynamicSimulationParameters; + private DynamicSimulationParameters dynamicSimulationParameters; @Builder public DynamicSimulationRunContext(UUID networkUuid, String variantId, String receiver, String provider, String mapping, diff --git a/src/main/java/org/gridsuite/ds/server/service/parameters/CurveGroovyGeneratorService.java b/src/main/java/org/gridsuite/ds/server/service/parameters/CurveGroovyGeneratorService.java index 589853fb..c7b1977f 100644 --- a/src/main/java/org/gridsuite/ds/server/service/parameters/CurveGroovyGeneratorService.java +++ b/src/main/java/org/gridsuite/ds/server/service/parameters/CurveGroovyGeneratorService.java @@ -15,7 +15,6 @@ * @author Thang PHAM */ public interface CurveGroovyGeneratorService { - String RESOURCE_PATH_DELIMETER = "/"; String CURVES_TEMPLATE_DIR = "templates/curve"; /** diff --git a/src/main/java/org/gridsuite/ds/server/service/parameters/EventGroovyGeneratorService.java b/src/main/java/org/gridsuite/ds/server/service/parameters/EventGroovyGeneratorService.java deleted file mode 100644 index 7679d430..00000000 --- a/src/main/java/org/gridsuite/ds/server/service/parameters/EventGroovyGeneratorService.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2023, RTE (http://www.rte-france.com) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -package org.gridsuite.ds.server.service.parameters; - -import org.gridsuite.ds.server.dto.event.EventInfos; - -import java.util.List; - -/** - * @author Thang PHAM - */ -public interface EventGroovyGeneratorService { - String RESOURCE_PATH_DELIMETER = "/"; - String EVENTS_TEMPLATE_DIR = "templates/event"; - - /** - * Generate a script groovy which contains events - * @param events given list of events - * @return a script groovy which contains events - */ - String generate(List events); -} diff --git a/src/main/java/org/gridsuite/ds/server/service/parameters/ParametersService.java b/src/main/java/org/gridsuite/ds/server/service/parameters/ParametersService.java index 84b0f938..17815692 100644 --- a/src/main/java/org/gridsuite/ds/server/service/parameters/ParametersService.java +++ b/src/main/java/org/gridsuite/ds/server/service/parameters/ParametersService.java @@ -8,8 +8,12 @@ import com.powsybl.dynamicsimulation.DynamicSimulationParameters; import com.powsybl.ws.commons.computation.dto.ReportInfos; +import com.powsybl.dynawaltz.suppliers.dynamicmodels.DynamicModelConfig; +import com.powsybl.dynawaltz.suppliers.events.EventModelConfig; +import com.powsybl.iidm.network.Network; import org.gridsuite.ds.server.dto.DynamicSimulationParametersInfos; import org.gridsuite.ds.server.dto.curve.CurveInfos; +import org.gridsuite.ds.server.dto.dynamicmapping.InputMapping; import org.gridsuite.ds.server.dto.event.EventInfos; import org.gridsuite.ds.server.service.contexts.DynamicSimulationRunContext; @@ -21,7 +25,7 @@ */ public interface ParametersService { - String getEventModel(List events); + List getEventModel(List events); String getCurveModel(List curves); @@ -29,4 +33,6 @@ public interface ParametersService { DynamicSimulationRunContext createRunContext(UUID networkUuid, String variantId, String receiver, String provider, String mapping, ReportInfos reportContext, String userId, DynamicSimulationParametersInfos parameters); + + List getDynamicModel(InputMapping inputMapping, Network network); } diff --git a/src/main/java/org/gridsuite/ds/server/service/parameters/impl/CurveGroovyGeneratorServiceImpl.java b/src/main/java/org/gridsuite/ds/server/service/parameters/impl/CurveGroovyGeneratorServiceImpl.java index 4faee6dc..4a76a533 100644 --- a/src/main/java/org/gridsuite/ds/server/service/parameters/impl/CurveGroovyGeneratorServiceImpl.java +++ b/src/main/java/org/gridsuite/ds/server/service/parameters/impl/CurveGroovyGeneratorServiceImpl.java @@ -18,10 +18,14 @@ import java.io.IOException; import java.nio.charset.Charset; -import java.util.*; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; import static org.gridsuite.ds.server.utils.EquipmentType.isStaticType; +import static org.gridsuite.ds.server.utils.Utils.RESOURCE_PATH_DELIMITER; /** * @author Thang PHAM @@ -34,8 +38,8 @@ public String generate(List curveInfosList) { String curvesTemplate; String curveTemplate; try { - curvesTemplate = IOUtils.toString(new ClassPathResource(CURVES_TEMPLATE_DIR + RESOURCE_PATH_DELIMETER + "curves.st").getInputStream(), Charset.defaultCharset()); - curveTemplate = IOUtils.toString(new ClassPathResource(CURVES_TEMPLATE_DIR + RESOURCE_PATH_DELIMETER + "curve.st").getInputStream(), Charset.defaultCharset()); + curvesTemplate = IOUtils.toString(new ClassPathResource(CURVES_TEMPLATE_DIR + RESOURCE_PATH_DELIMITER + "curves.st").getInputStream(), Charset.defaultCharset()); + curveTemplate = IOUtils.toString(new ClassPathResource(CURVES_TEMPLATE_DIR + RESOURCE_PATH_DELIMITER + "curve.st").getInputStream(), Charset.defaultCharset()); } catch (IOException e) { throw new PowsyblException("Unable to load templates for groovy script generation : " + e.getMessage()); } diff --git a/src/main/java/org/gridsuite/ds/server/service/parameters/impl/EventGroovyGeneratorServiceImpl.java b/src/main/java/org/gridsuite/ds/server/service/parameters/impl/EventGroovyGeneratorServiceImpl.java deleted file mode 100644 index f91ee0f9..00000000 --- a/src/main/java/org/gridsuite/ds/server/service/parameters/impl/EventGroovyGeneratorServiceImpl.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2023, RTE (http://www.rte-france.com) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -package org.gridsuite.ds.server.service.parameters.impl; - -import com.powsybl.commons.PowsyblException; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.StringUtils; -import org.gridsuite.ds.server.dto.event.EventInfos; -import org.gridsuite.ds.server.dto.event.EventPropertyInfos; -import org.gridsuite.ds.server.service.parameters.EventGroovyGeneratorService; -import org.gridsuite.ds.server.utils.PropertyType; -import org.gridsuite.ds.server.utils.Utils; -import org.springframework.core.io.ClassPathResource; -import org.springframework.stereotype.Service; -import org.stringtemplate.v4.ST; - -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; - -/** - * @author Thang PHAM - */ -@Service -public class EventGroovyGeneratorServiceImpl implements EventGroovyGeneratorService { - @Override - public String generate(List events) { - Objects.requireNonNull(events); - - String eventsTemplate; - String eventTemplate; - String eventPropertyTemplate; - try { - eventsTemplate = IOUtils.toString(new ClassPathResource(EVENTS_TEMPLATE_DIR + RESOURCE_PATH_DELIMETER + "events.st").getInputStream(), Charset.defaultCharset()); - eventTemplate = IOUtils.toString(new ClassPathResource(EVENTS_TEMPLATE_DIR + RESOURCE_PATH_DELIMETER + "event.st").getInputStream(), Charset.defaultCharset()); - eventPropertyTemplate = IOUtils.toString(new ClassPathResource(EVENTS_TEMPLATE_DIR + RESOURCE_PATH_DELIMETER + "eventProperty.st").getInputStream(), Charset.defaultCharset()); - } catch (IOException e) { - throw new PowsyblException("Unable to load templates for groovy script generation : " + e.getMessage()); - } - // config root template - ST eventsST = new ST(eventsTemplate); - - String[] eventStringList = events.stream().map(event -> generateEvent(eventTemplate, eventPropertyTemplate, event)).toArray(String[]::new); - eventsST.add("events", eventStringList); - - return eventsST.render(); - } - - private String generateEvent(String eventTemplate, String eventPropertyTemplate, EventInfos event) { - ST eventST = new ST(eventTemplate); - eventST.add("eventType", event.getEventType()); - - // --- add properties --- - String[] propertyStringList = event.getProperties().stream() - .map(property -> generateEventProperty(eventPropertyTemplate, property)) - .filter(property -> !StringUtils.isEmpty(property)).toArray(String[]::new); - eventST.add("properties", propertyStringList); - - return eventST.render(); - } - - private String generateEventProperty(String eventPropertyTemplate, EventPropertyInfos property) { - ST eventPropertyST = new ST(eventPropertyTemplate); - String value = property.getValue(); - if (StringUtils.isEmpty(value)) { - return null; - } - - // value => "value" when export groovy string value - if (property.getType() == PropertyType.STRING) { - value = Utils.convertStringToList(value).stream() - .map(elem -> "\"" + elem + "\"") - .collect(Collectors.joining(", ")); - } - - eventPropertyST.add("name", property.getName()); - eventPropertyST.add("value", value); - - return eventPropertyST.render(); - } -} diff --git a/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java b/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java index 8f8fdedf..cd0d3851 100644 --- a/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java +++ b/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java @@ -12,20 +12,36 @@ import com.powsybl.dynawaltz.DynaWaltzParameters; import com.powsybl.dynawaltz.DynaWaltzProvider; import com.powsybl.dynawaltz.parameters.ParametersSet; +import com.powsybl.dynawaltz.suppliers.PropertyBuilder; +import com.powsybl.dynawaltz.suppliers.PropertyType; +import com.powsybl.dynawaltz.suppliers.SetGroupType; +import com.powsybl.dynawaltz.suppliers.dynamicmodels.DynamicModelConfig; +import com.powsybl.dynawaltz.suppliers.events.EventModelConfig; import com.powsybl.dynawaltz.xml.ParametersXml; +import com.powsybl.iidm.network.Identifiable; +import com.powsybl.iidm.network.Network; +import com.powsybl.ws.commons.computation.dto.ReportInfos; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.ArrayUtils; import org.gridsuite.ds.server.DynamicSimulationException; -import com.powsybl.ws.commons.computation.dto.ReportInfos; import org.gridsuite.ds.server.dto.DynamicSimulationParametersInfos; import org.gridsuite.ds.server.dto.XmlSerializableParameter; import org.gridsuite.ds.server.dto.curve.CurveInfos; +import org.gridsuite.ds.server.dto.dynamicmapping.InputMapping; +import org.gridsuite.ds.server.dto.dynamicmapping.Rule; +import org.gridsuite.ds.server.dto.dynamicmapping.automata.Automaton; import org.gridsuite.ds.server.dto.event.EventInfos; import org.gridsuite.ds.server.dto.network.NetworkInfos; import org.gridsuite.ds.server.dto.solver.SolverInfos; import org.gridsuite.ds.server.service.contexts.DynamicSimulationRunContext; import org.gridsuite.ds.server.service.parameters.CurveGroovyGeneratorService; -import org.gridsuite.ds.server.service.parameters.EventGroovyGeneratorService; import org.gridsuite.ds.server.service.parameters.ParametersService; +import org.gridsuite.ds.server.utils.Utils; +import org.gridsuite.filter.expertfilter.ExpertFilter; +import org.gridsuite.filter.expertfilter.expertrule.CombinatorExpertRule; +import org.gridsuite.filter.utils.EquipmentType; +import org.gridsuite.filter.utils.FiltersUtils; +import org.gridsuite.filter.utils.expertfilter.CombinatorType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -35,13 +51,10 @@ import javax.xml.stream.XMLStreamException; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.util.Collections; -import java.util.List; -import java.util.Objects; -import java.util.UUID; +import java.util.*; +import java.util.stream.Collectors; -import static org.gridsuite.ds.server.DynamicSimulationException.Type.MAPPING_NOT_PROVIDED; -import static org.gridsuite.ds.server.DynamicSimulationException.Type.PROVIDER_NOT_FOUND; +import static org.gridsuite.ds.server.DynamicSimulationException.Type.*; /** * @author Thang PHAM @@ -50,27 +63,30 @@ public class ParametersServiceImpl implements ParametersService { private static final Logger LOGGER = LoggerFactory.getLogger(ParametersServiceImpl.class); + public static final String FIELD_STATIC_ID = "staticId"; private final CurveGroovyGeneratorService curveGroovyGeneratorService; - private final EventGroovyGeneratorService eventGroovyGeneratorService; - private final String defaultProvider; @Autowired public ParametersServiceImpl(CurveGroovyGeneratorService curveGroovyGeneratorService, - EventGroovyGeneratorService eventGroovyGeneratorService, @Value("${dynamic-simulation.default-provider}") String defaultProvider) { this.curveGroovyGeneratorService = curveGroovyGeneratorService; - this.eventGroovyGeneratorService = eventGroovyGeneratorService; this.defaultProvider = defaultProvider; } @Override - public String getEventModel(List events) { - String generatedGroovyEvents = eventGroovyGeneratorService.generate(events != null ? events : Collections.emptyList()); - LOGGER.info(generatedGroovyEvents); - return generatedGroovyEvents; + public List getEventModel(List events) { + if (CollectionUtils.isEmpty(events)) { + return Collections.emptyList(); + } + + return events.stream().map(event -> + new EventModelConfig( + event.getEventType(), + event.getProperties().stream().map(Utils::convertProperty).filter(Objects::nonNull).toList())) + .toList(); } @Override @@ -170,4 +186,75 @@ public DynamicSimulationRunContext createRunContext(UUID networkUuid, String var return runContext; } + + @Override + public List getDynamicModel(InputMapping inputMapping, Network network) { + if (inputMapping == null) { + return Collections.emptyList(); + } + + List dynamicModel = new ArrayList<>(); + + // --- transform equipment rules to DynamicModelConfigs --- // + List allRules = inputMapping.rules(); + // grouping rules by equipment type + Map> rulesByEquipmentTypeMap = allRules.stream().collect(Collectors.groupingBy(Rule::equipmentType)); + + // Only last rule can have empty filter checking + rulesByEquipmentTypeMap.forEach((equipmentType, rules) -> { + Rule ruleWithEmptyFilter = rules.stream().filter(rule -> rule.filter() == null).findFirst().orElse(null); + if (ruleWithEmptyFilter != null && rules.indexOf(ruleWithEmptyFilter) != (rules.size() - 1)) { + throw new DynamicSimulationException(MAPPING_NOT_LAST_RULE_WITH_EMPTY_FILTER_ERROR, + "Only last rule can have empty filter: type " + equipmentType + ", rule index " + rules.indexOf(ruleWithEmptyFilter) + 1); + } + }); + + // performing transformation + rulesByEquipmentTypeMap.forEach((equipmentType, rules) -> { + // accumulate matched equipment ids to compute otherwise case (last rule without filters) + Set matchedEquipmentIdsOfCurrentType = new TreeSet<>(); + + dynamicModel.addAll(rules.stream().flatMap(rule -> { + ExpertFilter filter = rule.filter(); + + // otherwise case, create an expert filter with AND operator and empty rules to get all equipments of the same type + if (filter == null) { + filter = ExpertFilter.builder() + .equipmentType(equipmentType) + .rules(CombinatorExpertRule.builder().combinator(CombinatorType.AND).rules(List.of()).build()) + .build(); + } + + List> matchedEquipmentsOfCurrentRule = FiltersUtils.getIdentifiables(filter, network, null); + + // eliminate already matched equipments to avoid duplication + if (!matchedEquipmentIdsOfCurrentType.isEmpty()) { + matchedEquipmentsOfCurrentRule = matchedEquipmentsOfCurrentRule.stream().filter(elem -> !matchedEquipmentIdsOfCurrentType.contains(elem.getId())).toList(); + } + + matchedEquipmentIdsOfCurrentType.addAll(matchedEquipmentsOfCurrentRule.stream().map(Identifiable::getId).toList()); + + return matchedEquipmentsOfCurrentRule.stream().map(equipment -> new DynamicModelConfig( + rule.mappedModel(), + rule.setGroup(), + SetGroupType.valueOf(rule.groupType().name()), + List.of(new PropertyBuilder() + .name(FIELD_STATIC_ID) + .value(equipment.getId()) + .type(PropertyType.STRING) + .build()))); + }).toList()); + }); + + // transform automatons to DynamicModelConfigs + List automata = inputMapping.automata(); + dynamicModel.addAll(automata.stream().map(automaton -> + new DynamicModelConfig( + automaton.model(), + automaton.setGroup(), + automaton.properties().stream().map(Utils::convertProperty).filter(Objects::nonNull).toList()) + ).toList()); + + return dynamicModel; + } } diff --git a/src/main/java/org/gridsuite/ds/server/utils/PropertyType.java b/src/main/java/org/gridsuite/ds/server/utils/PropertyType.java index 969b4a19..cdad6d41 100644 --- a/src/main/java/org/gridsuite/ds/server/utils/PropertyType.java +++ b/src/main/java/org/gridsuite/ds/server/utils/PropertyType.java @@ -10,9 +10,10 @@ * @author Thang PHAM */ public enum PropertyType { - ENUM, BOOLEAN, + ENUM, INTEGER, FLOAT, + DOUBLE, STRING, } diff --git a/src/main/java/org/gridsuite/ds/server/utils/SetGroupType.java b/src/main/java/org/gridsuite/ds/server/utils/SetGroupType.java new file mode 100644 index 00000000..e23133e6 --- /dev/null +++ b/src/main/java/org/gridsuite/ds/server/utils/SetGroupType.java @@ -0,0 +1,25 @@ +/** + * Copyright (c) 2024, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.gridsuite.ds.server.utils; + +/** + * @author Thang PHAM + */ +public enum SetGroupType { + /** + * group is used as a parameter set id + */ + FIXED, + /** + * the parameter set id comprise the model dynamic id (or the equipment static id if not found) prefixed by group + */ + PREFIX, + /** + * the parameter set id comprise the model dynamic id (or the equipment static id if not found) suffixed by group + */ + SUFFIX +} diff --git a/src/main/java/org/gridsuite/ds/server/utils/Utils.java b/src/main/java/org/gridsuite/ds/server/utils/Utils.java index 8d0e5b94..25d51558 100644 --- a/src/main/java/org/gridsuite/ds/server/utils/Utils.java +++ b/src/main/java/org/gridsuite/ds/server/utils/Utils.java @@ -7,6 +7,14 @@ package org.gridsuite.ds.server.utils; +import com.powsybl.dynawaltz.suppliers.Property; +import com.powsybl.dynawaltz.suppliers.PropertyBuilder; +import com.powsybl.dynawaltz.suppliers.PropertyType; +import com.powsybl.iidm.network.TwoSides; +import org.apache.commons.lang3.StringUtils; +import org.gridsuite.ds.server.dto.dynamicmapping.automata.BasicProperty; +import org.gridsuite.ds.server.dto.event.EventPropertyInfos; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -15,8 +23,11 @@ * @author Thang PHAM */ public final class Utils { + + public static final String RESOURCE_PATH_DELIMITER = "/"; + private Utils() { - // never called + throw new AssertionError("Utility class should not be instantiated"); } public static List convertStringToList(String stringArray) { @@ -24,4 +35,53 @@ public static List convertStringToList(String stringArray) { converted.addAll(Arrays.asList(stringArray.split(","))); return converted; } + + public static Property convertProperty(EventPropertyInfos property) { + return convertProperty(new BasicProperty( + property.getName(), + property.getValue(), + property.getType())); + } + + public static Property convertProperty(BasicProperty property) { + String value = property.value(); + PropertyBuilder propertyBuilder = new PropertyBuilder() + .name(property.name()); + if (property.type() == org.gridsuite.ds.server.utils.PropertyType.FLOAT) { + // powsybl-dynawo does not support FLOAT => use DOUBLE + propertyBuilder.value(value) + .type(PropertyType.DOUBLE); + } else if (property.type() == org.gridsuite.ds.server.utils.PropertyType.ENUM) { + // using value to infer enum type + if (StringUtils.isEmpty(value) || value.split("\\.").length != 2) { + return null; + } + + String[] splitValue = value.split("\\."); + String enumType = splitValue[0]; + String enumValue = splitValue[1]; + + // at moment process only TwoSides, e.g. TwoSides.TWO or TwoSides.ONE + if (TwoSides.class.getSimpleName().equals(enumType)) { + propertyBuilder.value(enumValue) + .type(PropertyType.TWO_SIDES); + } else { + return null; + } + } else if (property.type() == org.gridsuite.ds.server.utils.PropertyType.STRING) { + propertyBuilder.value(value) + .type(PropertyType.valueOf(property.type().name())); + List values = convertStringToList(value).stream().map(StringUtils::trim).toList(); + // check whether having multiple values + if (values.size() > 1) { + // override by set multiple values + propertyBuilder.values(values); + } + } else { + propertyBuilder.value(value) + .type(PropertyType.valueOf(property.type().name())); + } + + return propertyBuilder.build(); + } } diff --git a/src/main/resources/templates/event/event.st b/src/main/resources/templates/event/event.st deleted file mode 100644 index 8c824947..00000000 --- a/src/main/resources/templates/event/event.st +++ /dev/null @@ -1,3 +0,0 @@ - { - -} \ No newline at end of file diff --git a/src/main/resources/templates/event/eventProperty.st b/src/main/resources/templates/event/eventProperty.st deleted file mode 100644 index 688d7a78..00000000 --- a/src/main/resources/templates/event/eventProperty.st +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/src/main/resources/templates/event/events.st b/src/main/resources/templates/event/events.st deleted file mode 100644 index 7994ea4e..00000000 --- a/src/main/resources/templates/event/events.st +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Copyright (c) 2020, RTE (http://www.rte-france.com) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -import com.powsybl.iidm.network.TwoSides - - \ No newline at end of file diff --git a/src/test/java/org/gridsuite/ds/server/controller/AbstractDynamicSimulationControllerTest.java b/src/test/java/org/gridsuite/ds/server/controller/AbstractDynamicSimulationControllerTest.java index e468b891..8dadad3e 100644 --- a/src/test/java/org/gridsuite/ds/server/controller/AbstractDynamicSimulationControllerTest.java +++ b/src/test/java/org/gridsuite/ds/server/controller/AbstractDynamicSimulationControllerTest.java @@ -48,8 +48,6 @@ public abstract class AbstractDynamicSimulationControllerTest extends AbstractDy protected final String dsFailedDestination = "ds.failed.destination"; protected final String dsStoppedDestination = "ds.stopped.destination"; - public static final String RESOURCE_PATH_DELIMETER = "/"; - @MockBean protected DynamicMappingClient dynamicMappingClient; @@ -63,6 +61,7 @@ public abstract class AbstractDynamicSimulationControllerTest extends AbstractDy protected DynamicSimulationWorkerService dynamicSimulationWorkerService; @Before + @Override public void setUp() throws IOException { super.setUp(); @@ -80,6 +79,7 @@ public void setUp() throws IOException { } @After + @Override public void tearDown() throws Exception { super.tearDown(); diff --git a/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerIEEE14Test.java b/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerIEEE14Test.java index ef956181..778e5ec4 100644 --- a/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerIEEE14Test.java +++ b/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerIEEE14Test.java @@ -25,7 +25,8 @@ import org.gridsuite.ds.server.controller.utils.ParameterUtils; import org.gridsuite.ds.server.dto.DynamicSimulationParametersInfos; import org.gridsuite.ds.server.dto.curve.CurveInfos; -import org.gridsuite.ds.server.dto.dynamicmapping.Script; +import org.gridsuite.ds.server.dto.dynamicmapping.InputMapping; +import org.gridsuite.ds.server.dto.dynamicmapping.ParameterFile; import org.gridsuite.ds.server.dto.event.EventInfos; import org.gridsuite.ds.server.dto.timeseries.TimeSeriesGroupInfos; import org.gridsuite.ds.server.service.client.dynamicmapping.DynamicMappingClientTest; @@ -44,13 +45,12 @@ import java.io.InputStream; import java.io.UncheckedIOException; import java.nio.charset.StandardCharsets; -import java.text.ParseException; -import java.text.SimpleDateFormat; import java.util.*; -import static org.assertj.core.api.Assertions.assertThat; import static com.powsybl.ws.commons.computation.service.NotificationService.HEADER_RESULT_UUID; import static com.powsybl.ws.commons.computation.service.NotificationService.HEADER_USER_ID; +import static org.assertj.core.api.Assertions.assertThat; +import static org.gridsuite.ds.server.utils.Utils.RESOURCE_PATH_DELIMITER; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.springframework.http.MediaType.APPLICATION_JSON; @@ -66,10 +66,10 @@ public class DynamicSimulationControllerIEEE14Test extends AbstractDynamicSimula public static final String MAPPING_NAME_01 = "_01"; // directories - public static final String DATA_IEEE14_BASE_DIR = RESOURCE_PATH_DELIMETER + "data" + RESOURCE_PATH_DELIMETER + "ieee14"; + public static final String DATA_IEEE14_BASE_DIR = RESOURCE_PATH_DELIMITER + "data" + RESOURCE_PATH_DELIMITER + "ieee14"; public static final String INPUT = "input"; public static final String OUTPUT = "output"; - public static final String MODELS_GROOVY = "models.groovy"; + public static final String MAPPING_FILE = "mapping.json"; public static final String MODELS_PAR = "models.par"; public static final String RESULT_IDA_JSON = "result_IDA.json"; public static final String RESULT_SIM_JSON = "result_SIM.json"; @@ -93,9 +93,6 @@ public class DynamicSimulationControllerIEEE14Test extends AbstractDynamicSimula @Autowired private ObjectMapper objectMapper; - private static final String FIXED_DATE = "01/01/2023"; - private final SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); - @Override public OutputDestination getOutputDestination() { return output; @@ -115,34 +112,27 @@ protected void initNetworkStoreServiceMock() { protected void initDynamicMappingServiceMock() { try { String inputDir = DATA_IEEE14_BASE_DIR + - RESOURCE_PATH_DELIMETER + MAPPING_NAME_01 + - RESOURCE_PATH_DELIMETER + INPUT; - - // load models.groovy - String scriptPath = inputDir + RESOURCE_PATH_DELIMETER + MODELS_GROOVY; - InputStream scriptIS = getClass().getResourceAsStream(scriptPath); - byte[] scriptBytes; - scriptBytes = StreamUtils.copyToByteArray(scriptIS); - String script = new String(scriptBytes, StandardCharsets.UTF_8); + RESOURCE_PATH_DELIMITER + MAPPING_NAME_01 + + RESOURCE_PATH_DELIMITER + INPUT; // load models.par - String parametersFilePath = inputDir + RESOURCE_PATH_DELIMETER + MODELS_PAR; + String parametersFilePath = inputDir + RESOURCE_PATH_DELIMITER + MODELS_PAR; InputStream parametersFileIS = getClass().getResourceAsStream(parametersFilePath); byte[] parametersFileBytes; parametersFileBytes = StreamUtils.copyToByteArray(parametersFileIS); String parametersFile = new String(parametersFileBytes, StandardCharsets.UTF_8); - Script scriptObj = new Script( - MAPPING_NAME_01 + "-script", + ParameterFile parameterFile = new ParameterFile( MAPPING_NAME_01, - script, - dateFormat.parse(FIXED_DATE), parametersFile); - given(dynamicMappingClient.createFromMapping(DynamicMappingClientTest.MAPPING_NAME_01)).willReturn(scriptObj); + given(dynamicMappingClient.exportParameters(DynamicMappingClientTest.MAPPING_NAME_01)).willReturn(parameterFile); + + // load mapping.json + String mappingPath = inputDir + RESOURCE_PATH_DELIMITER + MAPPING_FILE; + InputMapping inputMapping = objectMapper.readValue(getClass().getResourceAsStream(mappingPath), InputMapping.class); + given(dynamicMappingClient.getMapping(DynamicMappingClientTest.MAPPING_NAME_01)).willReturn(inputMapping); } catch (IOException e) { throw new UncheckedIOException(e); - } catch (ParseException e) { - throw new IllegalArgumentException(e); } } @@ -233,16 +223,16 @@ public void test01GivenCurvesAndEvents() throws Exception { // --- CHECK result at detail level --- // // prepare expected result to compare String outputDir = DATA_IEEE14_BASE_DIR + - RESOURCE_PATH_DELIMETER + testBaseDir + - RESOURCE_PATH_DELIMETER + OUTPUT; - DynamicSimulationResult expectedResult = DynamicSimulationResultDeserializer.read(getClass().getResourceAsStream(outputDir + RESOURCE_PATH_DELIMETER + RESULT_SIM_JSON)); + RESOURCE_PATH_DELIMITER + testBaseDir + + RESOURCE_PATH_DELIMITER + OUTPUT; + DynamicSimulationResult expectedResult = DynamicSimulationResultDeserializer.read(getClass().getResourceAsStream(outputDir + RESOURCE_PATH_DELIMITER + RESULT_SIM_JSON)); String jsonExpectedTimeSeries = TimeSeries.toJson(new ArrayList<>(expectedResult.getCurves().values())); // convert result time series to json String jsonResultTimeSeries = TimeSeries.toJson(resultTimeSeries); // export result to file - FileUtils.writeStringToFile(this, outputDir + RESOURCE_PATH_DELIMETER + "exported_" + RESULT_SIM_JSON, jsonResultTimeSeries); + FileUtils.writeStringToFile(this, outputDir + RESOURCE_PATH_DELIMITER + "exported_" + RESULT_SIM_JSON, jsonResultTimeSeries); // compare result only timeseries assertThat(objectMapper.readTree(jsonResultTimeSeries)).isEqualTo(objectMapper.readTree(jsonExpectedTimeSeries)); diff --git a/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerTest.java b/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerTest.java index 81302dd1..32bce131 100644 --- a/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerTest.java +++ b/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerTest.java @@ -20,13 +20,14 @@ import com.powsybl.iidm.network.VariantManagerConstants; import com.powsybl.network.store.client.PreloadingStrategy; import com.powsybl.timeseries.*; -import org.apache.commons.collections4.CollectionUtils; import com.powsybl.ws.commons.computation.service.NotificationService; +import org.apache.commons.collections4.CollectionUtils; import org.gridsuite.ds.server.controller.utils.ParameterUtils; import org.gridsuite.ds.server.dto.DynamicSimulationParametersInfos; import org.gridsuite.ds.server.dto.DynamicSimulationStatus; -import org.gridsuite.ds.server.dto.dynamicmapping.Script; +import org.gridsuite.ds.server.dto.dynamicmapping.ParameterFile; import org.gridsuite.ds.server.dto.timeseries.TimeSeriesGroupInfos; +import org.gridsuite.ds.server.service.client.dynamicmapping.DynamicMappingClientTest; import org.gridsuite.ds.server.service.client.timeseries.TimeSeriesClientTest; import org.junit.Before; import org.junit.Test; @@ -49,8 +50,8 @@ import java.util.function.Supplier; import static com.powsybl.network.store.model.NetworkStoreApi.VERSION; -import static org.assertj.core.api.Assertions.assertThat; import static com.powsybl.ws.commons.computation.service.NotificationService.*; +import static org.assertj.core.api.Assertions.assertThat; import static org.gridsuite.ds.server.controller.utils.TestUtils.assertType; import static org.gridsuite.ds.server.service.DynamicSimulationService.COMPUTATION_TYPE; import static org.mockito.ArgumentMatchers.any; @@ -103,13 +104,12 @@ protected void initNetworkStoreServiceMock() { @Override protected void initDynamicMappingServiceMock() { - Script scriptObj = new Script( - MAPPING_NAME + "-script", + ParameterFile parameterFile = new ParameterFile( MAPPING_NAME, - "", - new Date(), ""); - given(dynamicMappingClient.createFromMapping(MAPPING_NAME)).willReturn(scriptObj); + given(dynamicMappingClient.exportParameters(MAPPING_NAME)).willReturn(parameterFile); + + given(dynamicMappingClient.getMapping(DynamicMappingClientTest.MAPPING_NAME_01)).willReturn(null); } @Override @@ -136,6 +136,7 @@ protected void initTimeSeriesServiceMock() { } @Before + @Override public void setUp() throws IOException { super.setUp(); } diff --git a/src/test/java/org/gridsuite/ds/server/controller/utils/FileUtils.java b/src/test/java/org/gridsuite/ds/server/controller/utils/FileUtils.java index 572897f6..0935e52d 100644 --- a/src/test/java/org/gridsuite/ds/server/controller/utils/FileUtils.java +++ b/src/test/java/org/gridsuite/ds/server/controller/utils/FileUtils.java @@ -17,6 +17,7 @@ */ public final class FileUtils { private FileUtils() { + throw new AssertionError("Utility class should not be instantiated"); } public static void writeStringToFile(Object caller, String filePathName, String content) throws IOException { diff --git a/src/test/java/org/gridsuite/ds/server/controller/utils/ParameterUtils.java b/src/test/java/org/gridsuite/ds/server/controller/utils/ParameterUtils.java index 42050089..d0fdb330 100644 --- a/src/test/java/org/gridsuite/ds/server/controller/utils/ParameterUtils.java +++ b/src/test/java/org/gridsuite/ds/server/controller/utils/ParameterUtils.java @@ -21,12 +21,14 @@ import java.util.List; +import static org.gridsuite.ds.server.service.parameters.impl.ParametersServiceImpl.FIELD_STATIC_ID; + /** * @author Thang PHAM */ public final class ParameterUtils { private ParameterUtils() { - + throw new AssertionError("Utility class should not be instantiated"); } /** @@ -180,9 +182,16 @@ public static List getCurveInfosList() { public static List getEventInfosList() { return List.of( new EventInfos(null, null, "_BUS____1-BUS____5-1_AC", null, "Disconnect", List.of( - new EventPropertyInfos(null, "staticId", "_BUS____1-BUS____5-1_AC", PropertyType.STRING), - new EventPropertyInfos(null, "startTime", "1", PropertyType.FLOAT), + new EventPropertyInfos(null, FIELD_STATIC_ID, "_BUS____1-BUS____5-1_AC", PropertyType.STRING), + new EventPropertyInfos(null, "startTime", "10", PropertyType.FLOAT), new EventPropertyInfos(null, "disconnectOnly", "TwoSides.TWO", PropertyType.ENUM) + )), + new EventInfos(null, null, "_BUS____1_TN", null, "FaultNode", List.of( + new EventPropertyInfos(null, FIELD_STATIC_ID, "_BUS____1_TN", PropertyType.STRING), + new EventPropertyInfos(null, "startTime", "20", PropertyType.FLOAT), + new EventPropertyInfos(null, "faultTime", "2", PropertyType.FLOAT), + new EventPropertyInfos(null, "rPu", "23", PropertyType.FLOAT), + new EventPropertyInfos(null, "xPu", "32", PropertyType.FLOAT) )) ); } diff --git a/src/test/java/org/gridsuite/ds/server/controller/utils/TestUtils.java b/src/test/java/org/gridsuite/ds/server/controller/utils/TestUtils.java index 6e6e413c..f541497f 100644 --- a/src/test/java/org/gridsuite/ds/server/controller/utils/TestUtils.java +++ b/src/test/java/org/gridsuite/ds/server/controller/utils/TestUtils.java @@ -22,7 +22,7 @@ public final class TestUtils { private static final long TIMEOUT = 100; private TestUtils() { - + throw new AssertionError("Utility class should not be instantiated"); } public static void assertQueuesEmptyThenClear(List destinations, OutputDestination output) throws InterruptedException { diff --git a/src/test/java/org/gridsuite/ds/server/dto/XmlSerializableParameterTest.java b/src/test/java/org/gridsuite/ds/server/dto/XmlSerializableParameterTest.java index 81bd6fcf..c5f7d842 100644 --- a/src/test/java/org/gridsuite/ds/server/dto/XmlSerializableParameterTest.java +++ b/src/test/java/org/gridsuite/ds/server/dto/XmlSerializableParameterTest.java @@ -37,6 +37,7 @@ import java.nio.file.Paths; import static com.powsybl.commons.test.ComparisonUtils.compareXml; +import static org.gridsuite.ds.server.utils.Utils.RESOURCE_PATH_DELIMITER; /** * @author Thang PHAM @@ -46,8 +47,7 @@ @ContextHierarchy({@ContextConfiguration(classes = {DynamicSimulationApplication.class, TestChannelBinderConfiguration.class})}) public class XmlSerializableParameterTest { - public static final String RESOURCE_PATH_DELIMETER = "/"; - public static final String DATA_XML = RESOURCE_PATH_DELIMETER + "data" + RESOURCE_PATH_DELIMETER + "xml"; + public static final String DATA_XML = RESOURCE_PATH_DELIMITER + "data" + RESOURCE_PATH_DELIMITER + "xml"; public static final String PAR_SCHEMA = "parameters.xsd"; public static final String OUTPUT = "output"; @@ -83,13 +83,13 @@ public void testWriteParameterGivenSolvers() throws IOException, XMLStreamExcept SolverInfos[] solvers = {idaSolver, simSolver}; // export solvers to par file - String resultDir = getClass().getResource(DATA_XML + RESOURCE_PATH_DELIMETER + OUTPUT).getPath(); + String resultDir = getClass().getResource(DATA_XML + RESOURCE_PATH_DELIMITER + OUTPUT).getPath(); Path exportedSolversFile = Paths.get(resultDir).resolve(EXPORTED_SOLVERS); Files.deleteIfExists(exportedSolversFile); XmlSerializableParameter.writeParameter(exportedSolversFile, XmlSerializableParameter.PARAMETER_SET, solvers); // compare two file - validate(DATA_XML + RESOURCE_PATH_DELIMETER + PAR_SCHEMA, DATA_XML + RESOURCE_PATH_DELIMETER + OUTPUT + RESOURCE_PATH_DELIMETER + EXPECTED_SOLVERS, exportedSolversFile); + validate(DATA_XML + RESOURCE_PATH_DELIMITER + PAR_SCHEMA, DATA_XML + RESOURCE_PATH_DELIMITER + OUTPUT + RESOURCE_PATH_DELIMITER + EXPECTED_SOLVERS, exportedSolversFile); } @Test @@ -97,12 +97,12 @@ public void testWriteParameterGivenNetwork() throws IOException, XMLStreamExcept NetworkInfos network = ParameterUtils.getDefaultNetwork(); // export network to par file - String resultDir = getClass().getResource(DATA_XML + RESOURCE_PATH_DELIMETER + OUTPUT).getPath(); + String resultDir = getClass().getResource(DATA_XML + RESOURCE_PATH_DELIMITER + OUTPUT).getPath(); Path exportedNetworkFile = Paths.get(resultDir).resolve(EXPORTED_NETWORK); Files.deleteIfExists(exportedNetworkFile); XmlSerializableParameter.writeParameter(exportedNetworkFile, XmlSerializableParameter.PARAMETER_SET, network); // compare two file - validate(DATA_XML + RESOURCE_PATH_DELIMETER + PAR_SCHEMA, DATA_XML + RESOURCE_PATH_DELIMETER + OUTPUT + RESOURCE_PATH_DELIMETER + EXPECTED_NETWORK, exportedNetworkFile); + validate(DATA_XML + RESOURCE_PATH_DELIMITER + PAR_SCHEMA, DATA_XML + RESOURCE_PATH_DELIMITER + OUTPUT + RESOURCE_PATH_DELIMITER + EXPECTED_NETWORK, exportedNetworkFile); } } diff --git a/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java b/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java index 3d6def04..e3746209 100644 --- a/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java +++ b/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java @@ -12,7 +12,7 @@ import com.github.tomakehurst.wiremock.WireMockServer; import com.github.tomakehurst.wiremock.client.WireMock; import org.gridsuite.ds.server.DynamicSimulationException; -import org.gridsuite.ds.server.dto.dynamicmapping.Script; +import org.gridsuite.ds.server.dto.dynamicmapping.ParameterFile; import org.gridsuite.ds.server.service.client.AbstractWireMockRestClientTest; import org.gridsuite.ds.server.service.client.dynamicmapping.impl.DynamicMappingClientImpl; import org.junit.Test; @@ -23,41 +23,31 @@ import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Optional; import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.catchThrowableOfType; -import static org.gridsuite.ds.server.DynamicSimulationException.Type.CREATE_MAPPING_SCRIPT_ERROR; import static org.gridsuite.ds.server.DynamicSimulationException.Type.DYNAMIC_MAPPING_NOT_FOUND; -import static org.gridsuite.ds.server.service.client.RestClient.DELIMITER; +import static org.gridsuite.ds.server.DynamicSimulationException.Type.EXPORT_PARAMETERS_ERROR; import static org.gridsuite.ds.server.service.client.dynamicmapping.DynamicMappingClient.API_VERSION; -import static org.gridsuite.ds.server.service.client.dynamicmapping.DynamicMappingClient.DYNAMIC_MAPPING_SCRIPT_CREATE_END_POINT; +import static org.gridsuite.ds.server.service.client.dynamicmapping.DynamicMappingClient.DYNAMIC_MAPPING_PARAMETERS_EXPORT_ENDPOINT; import static org.gridsuite.ds.server.service.client.utils.UrlUtils.buildEndPointUrl; -import static org.junit.Assert.assertEquals; +import static org.gridsuite.ds.server.utils.Utils.RESOURCE_PATH_DELIMITER; /** * @author Thang PHAM */ public class DynamicMappingClientTest extends AbstractWireMockRestClientTest { - public static final String RESOURCE_PATH_DELIMETER = "/"; - // mapping names public static final String MAPPING_NAME_01 = "_01"; // directories - public static final String DATA_IEEE14_BASE_DIR = RESOURCE_PATH_DELIMETER + "data" + RESOURCE_PATH_DELIMETER + "ieee14"; + public static final String DATA_IEEE14_BASE_DIR = RESOURCE_PATH_DELIMITER + "data" + RESOURCE_PATH_DELIMITER + "ieee14"; public static final String INPUT = "input"; - public static final String MODELS_GROOVY = "models.groovy"; public static final String MODELS_PAR = "models.par"; - private static final String FIXED_DATE = "01/01/2023"; - private final SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); - private DynamicMappingClient dynamicMappingClient; @Autowired @@ -66,9 +56,9 @@ public class DynamicMappingClientTest extends AbstractWireMockRestClientTest { @Autowired private ObjectMapper objectMapper; - private static String getEndpointUrl() { + private String getEndpointUrl() { return buildEndPointUrl("", API_VERSION, - DYNAMIC_MAPPING_SCRIPT_CREATE_END_POINT); + DYNAMIC_MAPPING_PARAMETERS_EXPORT_ENDPOINT); } @Override @@ -82,71 +72,58 @@ public void setup() { } @Test - public void testCreateFromMapping() throws IOException, ParseException { + public void testExportParameters() throws IOException { String mappingName = MAPPING_NAME_01; - // prepare script - String scriptJson; - // load models.groovy String inputDir = DATA_IEEE14_BASE_DIR + - RESOURCE_PATH_DELIMETER + mappingName + - RESOURCE_PATH_DELIMETER + INPUT; - String scriptPath = inputDir + RESOURCE_PATH_DELIMETER + MODELS_GROOVY; - InputStream scriptIS = getClass().getResourceAsStream(scriptPath); - byte[] scriptBytes; - scriptBytes = StreamUtils.copyToByteArray(scriptIS); - String script = new String(scriptBytes, StandardCharsets.UTF_8); + RESOURCE_PATH_DELIMITER + mappingName + + RESOURCE_PATH_DELIMITER + INPUT; // load models.par - String parametersFilePath = inputDir + RESOURCE_PATH_DELIMETER + MODELS_PAR; + String parametersFilePath = inputDir + RESOURCE_PATH_DELIMITER + MODELS_PAR; InputStream parametersFileIS = getClass().getResourceAsStream(parametersFilePath); byte[] parametersFileBytes; parametersFileBytes = StreamUtils.copyToByteArray(parametersFileIS); String parametersFile = new String(parametersFileBytes, StandardCharsets.UTF_8); - Script scriptObj = new Script( - mappingName + "-script", + ParameterFile parameterFile = new ParameterFile( mappingName, - script, - dateFormat.parse(FIXED_DATE), parametersFile); ObjectWriter ow = objectMapper.writer().withDefaultPrettyPrinter(); - scriptJson = ow.writeValueAsString(scriptObj); + String parameterFileJson = ow.writeValueAsString(parameterFile); - // mock response for test case GET with url - /scripts/from/{mappingName} + // mock response for GET parameters?mappingName= String baseUrl = getEndpointUrl(); - wireMockServer.stubFor(WireMock.get(WireMock.urlPathTemplate(baseUrl + DELIMITER + "{mappingName}")) - .withPathParam("mappingName", equalTo(mappingName)) + wireMockServer.stubFor(WireMock.get(WireMock.urlPathTemplate(baseUrl)) + .withQueryParam("mappingName", equalTo(mappingName)) .willReturn(WireMock.ok() - .withBody(scriptJson) + .withBody(parameterFileJson) .withHeader("Content-Type", "application/json; charset=utf-8") )); - Script createdScript = dynamicMappingClient.createFromMapping(MAPPING_NAME_01); + ParameterFile createdParameterFile = dynamicMappingClient.exportParameters(MAPPING_NAME_01); // check result - // models.groovy - assertEquals(script, Optional.of(createdScript).orElseThrow().getScript()); // load models.par - assertEquals(parametersFile, createdScript.getParametersFile()); + assertThat(createdParameterFile.fileContent()).isEqualTo(parametersFile); } @Test public void testCreateFromMappingGivenNotFound() { String mappingName = MAPPING_NAME_01; - // mock response for test case GET with url - /scripts/from/{mappingName} + // mock response for GET parameters/export?mappingName= String baseUrl = getEndpointUrl(); - wireMockServer.stubFor(WireMock.get(WireMock.urlPathTemplate(baseUrl + "{mappingName}")) - .withPathParam("mappingName", equalTo(mappingName)) + wireMockServer.stubFor(WireMock.get(WireMock.urlPathTemplate(baseUrl)) + .withQueryParam("mappingName", equalTo(mappingName)) .willReturn(WireMock.notFound() )); // test service - DynamicSimulationException dynamicSimulationException = catchThrowableOfType(() -> dynamicMappingClient.createFromMapping(MAPPING_NAME_01), + DynamicSimulationException dynamicSimulationException = catchThrowableOfType(() -> dynamicMappingClient.exportParameters(MAPPING_NAME_01), DynamicSimulationException.class); // check result @@ -158,22 +135,22 @@ public void testCreateFromMappingGivenNotFound() { public void testCreateFromMappingGivenException() { String mappingName = MAPPING_NAME_01; - // mock response for test case GET with url - /scripts/from/{mappingName} + // mock response for test case GET parameters/export?mappingName= String baseUrl = getEndpointUrl(); - wireMockServer.stubFor(WireMock.get(WireMock.urlPathTemplate(baseUrl + DELIMITER + "{mappingName}")) - .withPathParam("mappingName", equalTo(mappingName)) + wireMockServer.stubFor(WireMock.get(WireMock.urlPathTemplate(baseUrl)) + .withQueryParam("mappingName", equalTo(mappingName)) .willReturn(WireMock.serverError() .withBody(ERROR_MESSAGE) )); // test service - DynamicSimulationException dynamicSimulationException = catchThrowableOfType(() -> dynamicMappingClient.createFromMapping(MAPPING_NAME_01), + DynamicSimulationException dynamicSimulationException = catchThrowableOfType(() -> dynamicMappingClient.exportParameters(MAPPING_NAME_01), DynamicSimulationException.class); // check result assertThat(dynamicSimulationException.getType()) - .isEqualTo(CREATE_MAPPING_SCRIPT_ERROR); + .isEqualTo(EXPORT_PARAMETERS_ERROR); assertThat(dynamicSimulationException.getMessage()) .isEqualTo(ERROR_MESSAGE); diff --git a/src/test/java/org/gridsuite/ds/server/service/client/timeseries/TimeSeriesClientTest.java b/src/test/java/org/gridsuite/ds/server/service/client/timeseries/TimeSeriesClientTest.java index 7373fe78..856b7d97 100644 --- a/src/test/java/org/gridsuite/ds/server/service/client/timeseries/TimeSeriesClientTest.java +++ b/src/test/java/org/gridsuite/ds/server/service/client/timeseries/TimeSeriesClientTest.java @@ -50,16 +50,15 @@ public class TimeSeriesClientTest extends AbstractWireMockRestClientTest { @Autowired private ObjectMapper objectMapper; - private static List> createTimeSeriesList() { + private List> createTimeSeriesList() { Map> curves = new HashMap<>(); TimeSeriesIndex index = new IrregularTimeSeriesIndex(new long[]{32, 64, 128, 256}); curves.put("NETWORK__BUS____2-BUS____5-1_AC_iSide2", TimeSeries.createDouble("NETWORK__BUS____2-BUS____5-1_AC_iSide2", index, 333.847331, 333.847321, 333.847300, 333.847259)); curves.put("NETWORK__BUS____1_TN_Upu_value", TimeSeries.createDouble("NETWORK__BUS____1_TN_Upu_value", index, 1.059970, 1.059970, 1.059970, 1.059970)); - List> timeSeries = new ArrayList<>(curves.values()); - return timeSeries; + return new ArrayList<>(curves.values()); } - private static String getEndpointUrl() { + private String getEndpointUrl() { return buildEndPointUrl("", API_VERSION, TIME_SERIES_END_POINT); } diff --git a/src/test/resources/data/ieee14/_01/input/mapping.json b/src/test/resources/data/ieee14/_01/input/mapping.json new file mode 100644 index 00000000..be981046 --- /dev/null +++ b/src/test/resources/data/ieee14/_01/input/mapping.json @@ -0,0 +1,183 @@ +{ + "name": "mapping_01", + "rules": [ + { + "equipmentType": "LOAD", + "mappedModel": "LoadAlphaBeta", + "setGroup": "LAB", + "groupType": "FIXED" + }, + { + "equipmentType": "GENERATOR", + "mappedModel": "GeneratorSynchronousThreeWindingsProportionalRegulations", + "setGroup": "IEEE14", + "groupType": "PREFIX", + "filter": { + "equipmentType": "GENERATOR", + "type": "EXPERT", + "rules" : { + "combinator": "AND", + "dataType": "COMBINATOR", + "rules" : [ + { + "dataType": "NUMBER", + "field": "NOMINAL_VOLTAGE", + "operator": "EQUALS", + "value": 13.8 + } + ] + } + } + }, + { + "equipmentType": "GENERATOR", + "mappedModel": "GeneratorSynchronousFourWindingsProportionalRegulations", + "setGroup": "IEEE14", + "groupType": "PREFIX", + "filter": { + "equipmentType": "GENERATOR", + "type": "EXPERT", + "rules" : { + "combinator": "AND", + "dataType": "COMBINATOR", + "rules" : [ + { + "dataType": "NUMBER", + "field": "NOMINAL_VOLTAGE", + "operator": "EQUALS", + "value": 69.0 + } + ] + } + } + }, + { + "equipmentType": "GENERATOR", + "mappedModel": "GeneratorPQ", + "setGroup": "GPQ", + "groupType": "FIXED" + }, + { + "equipmentType": "STATIC_VAR_COMPENSATOR", + "mappedModel": "StaticVarCompensator", + "setGroup": "SVarCT", + "groupType": "FIXED", + "filter": { + "equipmentType": "STATIC_VAR_COMPENSATOR", + "type": "EXPERT", + "rules" : { + "combinator": "AND", + "dataType": "COMBINATOR", + "rules" : [{ + "dataType": "NUMBER", + "field": "NOMINAL_VOLTAGE", + "operator": "EQUALS", + "value": 69.0 + } + ] + } + } + } + ], + "automata": [ + { + "family": "CURRENT", + "model": "OverloadManagementSystem", + "setGroup": "CLA_2_4", + "properties": [ + { + "name": "dynamicModelId", + "value": "CLA_1", + "type": "STRING" + }, + { + "name": "iMeasurement", + "value": "_BUS____2-BUS____4-1_AC", + "type": "STRING" + }, + { + "name": "iMeasurementSide", + "value": "TwoSides.TWO", + "type": "ENUM" + }, + { + "name": "controlledBranch", + "value": "_BUS____2-BUS____4-1_AC", + "type": "STRING" + } + ] + }, + { + "family": "CURRENT", + "model": "OverloadManagementSystem", + "setGroup": "CLA_2_5", + "properties": [ + { + "name": "dynamicModelId", + "value": "CLA_2", + "type": "STRING" + }, + { + "name": "iMeasurement", + "value": "_BUS____2-BUS____5-1_AC", + "type": "STRING" + }, + { + "name": "iMeasurementSide", + "value": "TwoSides.TWO", + "type": "ENUM" + }, + { + "name": "controlledBranch", + "value": "_BUS____2-BUS____5-1_AC", + "type": "STRING" + } + ] + }, + { + "family": "VOLTAGE", + "model": "TapChangerBlockingAutomaton", + "setGroup": "TCB_2_4", + "properties": [ + { + "name": "dynamicModelId", + "value": "TCB_1", + "type": "STRING" + }, + { + "name": "uMeasurements", + "value": "_BUS___11_TN,_BUS___12_TN", + "type": "STRING" + }, + { + "name": "transformers", + "value": "_LOAD__11_EC,_LOAD__12_EC", + "type": "STRING" + } + ] + }, + { + "family": "VOLTAGE", + "model": "TapChangerBlockingAutomaton", + "setGroup": "TCB_2_5", + "properties": [ + { + "name": "dynamicModelId", + "value": "TCB_2", + "type": "STRING" + }, + { + "name": "uMeasurements", + "value": "_BUS____4_TN", + "type": "STRING" + }, + { + "name": "transformers", + "value": "_BUS____4-BUS____9-1_PT", + "type": "STRING" + } + ] + } + ], + "controlledParameters": false +} \ No newline at end of file diff --git a/src/test/resources/data/ieee14/_01/input/models.groovy b/src/test/resources/data/ieee14/_01/input/models.groovy deleted file mode 100644 index 2c0dcafb..00000000 --- a/src/test/resources/data/ieee14/_01/input/models.groovy +++ /dev/null @@ -1,78 +0,0 @@ -/** - * Copyright (c) 2021, RTE (http://www.rte-france.com) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -import com.powsybl.iidm.network.Generator -import com.powsybl.iidm.network.StaticVarCompensator -import com.powsybl.iidm.network.Load -import com.powsybl.iidm.network.TwoSides - -for (Generator equipment : network.generators) { - if (equipment.terminal.voltageLevel.nominalV == 13.800000) { - GeneratorSynchronousThreeWindingsProportionalRegulations { - staticId equipment.id - parameterSetId "IEEE14" + equipment.id - } - } else if (equipment.terminal.voltageLevel.nominalV == 69.000000) { - GeneratorSynchronousFourWindingsProportionalRegulations { - staticId equipment.id - parameterSetId "IEEE14" + equipment.id - } - } else if (true) { - GeneratorPQ { - staticId equipment.id - parameterSetId "GPQ" - } - } -} - -for (StaticVarCompensator equipment : network.staticVarCompensators) { - if (equipment.terminal.voltageLevel.nominalV == 69.000000) { - StaticVarCompensator { - staticId equipment.id - parameterSetId "SVarCT" - } - } -} - -for (Load equipment : network.loads) { - if (true) { - LoadAlphaBeta { - staticId equipment.id - parameterSetId "LAB" - } - } -} - -OverloadManagementSystem { - parameterSetId "CLA_2_4" - dynamicModelId "CLA_1" - iMeasurement "_BUS____2-BUS____4-1_AC" - iMeasurementSide TwoSides.TWO - controlledBranch "_BUS____2-BUS____4-1_AC" -} - -OverloadManagementSystem { - parameterSetId "CLA_2_5" - dynamicModelId "CLA_2" - iMeasurement "_BUS____2-BUS____5-1_AC" - iMeasurementSide TwoSides.TWO - controlledBranch "_BUS____2-BUS____5-1_AC" -} - -TapChangerBlockingAutomaton { - parameterSetId "TCB_2_4" - dynamicModelId "TCB_1" - uMeasurements "_BUS___11_TN", "_BUS___12_TN" - transformers "_LOAD__11_EC", "_LOAD__12_EC" -} - -TapChangerBlockingAutomaton { - parameterSetId "TCB_2_5" - dynamicModelId "TCB_2" - uMeasurements "_BUS____4_TN" - transformers "_BUS____4-BUS____9-1_PT" -} \ No newline at end of file diff --git a/src/test/resources/data/ieee14/_01/output/result_SIM.json b/src/test/resources/data/ieee14/_01/output/result_SIM.json index 133a5a64..c15803e6 100644 --- a/src/test/resources/data/ieee14/_01/output/result_SIM.json +++ b/src/test/resources/data/ieee14/_01/output/result_SIM.json @@ -6,156 +6,156 @@ "name" : "SVC2_SVarC_injector_QInjPu", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 10000, 11000, 11000, 12000, 13000, 14000, 15000, 16000, 16000, 17000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 56, - "stepValues" : [ -0.031738, -0.007935, -0.003222, 0.172601, 0.191644, 0.189343, 0.184884, 0.197732, 0.203929, 0.200946, 0.199999, 0.185314, 0.313312, 0.415058, 0.39714, 0.380065, 0.376941, 0.377728 ], - "stepLengths" : [ 1, 1, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 27 ] + "uncompressedLength" : 57, + "stepValues" : [ -0.031738, -0.007935, -0.007276, -0.002564, 0.172366, 0.19151, 0.189278, 0.184818, 0.197699, 0.203913, 0.200938, 0.199995, 0.18531, 0.313309, 0.415057, 0.39714, 0.380065, 0.37694, 0.377728 ], + "stepLengths" : [ 1, 2, 9, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 18 ] } ] }, { "metadata" : { "name" : "_GEN____3_SM_generator_omegaPu", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 10000, 11000, 11000, 12000, 13000, 14000, 15000, 16000, 16000, 17000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 56, + "uncompressedLength" : 57, "stepValues" : [ 1.0, 0.999831, 0.999806, 0.999657, 0.999646, 0.999615, 0.999581, 0.998868, 0.998811, 0.998709, 0.99856, 0.998442, 0.998362 ], - "stepLengths" : [ 3, 3, 5, 2, 1, 1, 9, 1, 1, 1, 1, 1, 27 ] + "stepLengths" : [ 13, 3, 5, 2, 1, 1, 9, 1, 1, 1, 1, 1, 18 ] } ] }, { "metadata" : { "name" : "_LOAD___2_EC_load_QPu", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 10000, 11000, 11000, 12000, 13000, 14000, 15000, 16000, 16000, 17000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 56, - "stepValues" : [ 0.126839, 0.126962, 0.126691, 0.126715, 0.126749, 0.126759, 0.127039, 0.126746, 0.12674, 0.126747, 0.127671, 0.126586, 0.12648, 0.12654, 0.126558, 0.126557, 0.126555 ], - "stepLengths" : [ 1, 1, 1, 2, 1, 4, 1, 2, 1, 9, 1, 1, 1, 1, 1, 1, 27 ] + "uncompressedLength" : 57, + "stepValues" : [ 0.126839, 0.126962, 0.12697, 0.126699, 0.126716, 0.126749, 0.126759, 0.127039, 0.126746, 0.12674, 0.126747, 0.127671, 0.126586, 0.12648, 0.12654, 0.126558, 0.126557, 0.126555 ], + "stepLengths" : [ 1, 2, 9, 1, 2, 1, 4, 1, 2, 1, 9, 1, 1, 1, 1, 1, 1, 18 ] } ] }, { "metadata" : { "name" : "_LOAD___2_EC_load_PPu", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 10000, 11000, 11000, 12000, 13000, 14000, 15000, 16000, 16000, 17000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 56, - "stepValues" : [ 0.216863, 0.216968, 0.216736, 0.216757, 0.216785, 0.216794, 0.217034, 0.216783, 0.216778, 0.216784, 0.217573, 0.216646, 0.216555, 0.216607, 0.216622, 0.216621, 0.216619 ], - "stepLengths" : [ 1, 1, 1, 2, 1, 4, 1, 2, 1, 9, 1, 1, 1, 1, 1, 1, 27 ] + "uncompressedLength" : 57, + "stepValues" : [ 0.216863, 0.216968, 0.216975, 0.216743, 0.216757, 0.216786, 0.216794, 0.217034, 0.216783, 0.216778, 0.216784, 0.217573, 0.216646, 0.216555, 0.216607, 0.216622, 0.216621, 0.216619 ], + "stepLengths" : [ 1, 2, 9, 1, 2, 1, 4, 1, 2, 1, 9, 1, 1, 1, 1, 1, 1, 18 ] } ] }, { "metadata" : { "name" : "_GEN____3_SM_generator_QGen", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 10000, 11000, 11000, 12000, 13000, 14000, 15000, 16000, 16000, 17000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 56, - "stepValues" : [ 25.432854, 25.119541, 23.633342, 29.121397, 29.829532, 29.573958, 28.63852, 37.534679, 38.845762, 38.622417, 38.521909, 29.999842, 92.036606, 109.12902, 107.191712, 105.214641, 104.881032, 104.978456 ], - "stepLengths" : [ 1, 1, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 27 ] + "uncompressedLength" : 57, + "stepValues" : [ 25.432854, 25.119541, 25.09512, 23.608993, 29.119339, 29.829256, 29.573806, 28.638375, 37.534592, 38.845719, 38.622397, 38.5219, 29.999834, 92.036603, 109.129019, 107.191711, 105.214641, 104.881032, 104.978456 ], + "stepLengths" : [ 1, 2, 9, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 18 ] } ] }, { "metadata" : { "name" : "SVC2_SVarC_modeHandling_mode_value", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 10000, 11000, 11000, 12000, 13000, 14000, 15000, 16000, 16000, 17000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 56, + "uncompressedLength" : 57, "stepValues" : [ 3.0 ], - "stepLengths" : [ 56 ] + "stepLengths" : [ 57 ] } ] }, { "metadata" : { "name" : "SVC2_SVarC_injector_BPu", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 10000, 11000, 11000, 12000, 13000, 14000, 15000, 16000, 16000, 17000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 56, - "stepValues" : [ -0.012932, -0.00323, -0.001314, 0.070395, 0.078141, 0.077197, 0.075212, 0.080625, 0.083156, 0.081936, 0.08155, 0.075014, 0.127917, 0.169596, 0.162198, 0.155202, 0.153927, 0.154252 ], - "stepLengths" : [ 1, 1, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 27 ] + "uncompressedLength" : 57, + "stepValues" : [ -0.012932, -0.00323, -0.002962, -0.001046, 0.070299, 0.078086, 0.077171, 0.075185, 0.080612, 0.083149, 0.081932, 0.081548, 0.075013, 0.127916, 0.169595, 0.162197, 0.155201, 0.153926, 0.154252 ], + "stepLengths" : [ 1, 2, 9, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 18 ] } ] }, { "metadata" : { "name" : "SVC2_SVarC_injector_PInjPu", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 10000, 11000, 11000, 12000, 13000, 14000, 15000, 16000, 16000, 17000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 56, + "uncompressedLength" : 57, "stepValues" : [ -0.0, -1.0E-6, 1.0E-6, 1.2E-5, 0.0, -3.0E-6, -1.0E-6, 7.0E-6, 1.7E-5, 0.0, 1.0E-6, 0.0, 1.0E-6, 6.0E-6, -5.9E-5, 5.0E-6 ], - "stepLengths" : [ 3, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 27 ] + "stepLengths" : [ 13, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 18 ] } ] }, { "metadata" : { "name" : "SVC2_SVarC_injector_UPu", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 10000, 11000, 11000, 12000, 13000, 14000, 15000, 16000, 16000, 17000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 56, - "stepValues" : [ 1.04441, 1.044917, 1.043801, 1.043901, 1.044039, 1.04408, 1.045235, 1.044028, 1.044004, 1.04403, 1.044031, 1.047831, 1.043368, 1.042931, 1.043178, 1.043254, 1.043248, 1.043239 ], - "stepLengths" : [ 1, 1, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 27 ] + "uncompressedLength" : 57, + "stepValues" : [ 1.04441, 1.044917, 1.04495, 1.043834, 1.043903, 1.04404, 1.044081, 1.045235, 1.044028, 1.044004, 1.04403, 1.044031, 1.047831, 1.043368, 1.042931, 1.043178, 1.043254, 1.043248, 1.043239 ], + "stepLengths" : [ 1, 2, 9, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 18 ] } ] }, { "metadata" : { "name" : "_GEN____3_SM_voltageRegulator_EfdPu", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 10000, 11000, 11000, 12000, 13000, 14000, 15000, 16000, 16000, 17000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 56, - "stepValues" : [ 1.113815, 1.112414, 1.106843, 1.126104, 1.123718, 1.120924, 1.117658, 1.146109, 1.141868, 1.137235, 1.135909, 1.103233, 1.308934, 1.308534, 1.267248, 1.25156, 1.249371, 1.249583 ], - "stepLengths" : [ 1, 1, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 27 ] + "uncompressedLength" : 57, + "stepValues" : [ 1.113815, 1.112414, 1.112292, 1.106721, 1.126103, 1.123721, 1.120926, 1.117659, 1.146109, 1.141868, 1.137235, 1.135909, 1.103233, 1.308934, 1.308534, 1.267248, 1.25156, 1.249371, 1.249583 ], + "stepLengths" : [ 1, 2, 9, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 18 ] } ] }, { "metadata" : { "name" : "_GEN____3_SM_generator_PGen", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 10000, 11000, 11000, 12000, 13000, 14000, 15000, 16000, 16000, 17000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 56, - "stepValues" : [ 0.036881, -0.007339, 15.349408, 3.143088, 1.248892, 1.954053, 16.691385, 5.296473, 2.840279, 3.427963, 3.7307, 52.684413, 21.622315, 9.857958, 11.458084, 13.42682, 13.752483, 13.614968 ], - "stepLengths" : [ 1, 1, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 27 ] + "uncompressedLength" : 57, + "stepValues" : [ 0.036881, -0.007339, -2.24E-4, 15.356225, 3.142704, 1.248209, 1.953908, 16.691252, 5.296474, 2.840281, 3.42796, 3.730698, 52.684413, 21.622314, 9.857958, 11.458084, 13.42682, 13.752482, 13.614968 ], + "stepLengths" : [ 1, 2, 9, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 18 ] } ] }, { "metadata" : { "name" : "_GEN____3_SM_generator_UStatorPu", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 10000, 11000, 11000, 12000, 13000, 14000, 15000, 16000, 16000, 17000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 56, - "stepValues" : [ 1.011427, 1.011497, 1.011775, 1.010812, 1.010931, 1.011071, 1.011234, 1.009812, 1.010024, 1.010256, 1.010322, 1.011956, 1.001671, 1.001691, 1.003755, 1.004539, 1.004649, 1.004638 ], - "stepLengths" : [ 1, 1, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 27 ] + "uncompressedLength" : 57, + "stepValues" : [ 1.011427, 1.011497, 1.011503, 1.011781, 1.010812, 1.010931, 1.011071, 1.011234, 1.009812, 1.010024, 1.010256, 1.010322, 1.011956, 1.001671, 1.001691, 1.003755, 1.004539, 1.004649, 1.004638 ], + "stepLengths" : [ 1, 2, 9, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 18 ] } ] } ], "timeLine" : [] diff --git a/src/test/resources/dynamicModels.groovy b/src/test/resources/dynamicModels.groovy deleted file mode 100644 index 3e693696..00000000 --- a/src/test/resources/dynamicModels.groovy +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Copyright (c) 2020, RTE (http://www.rte-france.com) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -import com.powsybl.iidm.network.Load -import com.powsybl.iidm.network.Generator - -for (Load load : network.loads) { - if (load.id != "_LOAD___8_EC") { - LoadAlphaBeta { - staticId load.id - parameterSetId "LAB" - } - } -} - -for (Generator gen : network.generators) { - if (gen.id != "_GEN____6_SM" && gen.id != "_GEN____8_SM") { - GeneratorSynchronousFourWindingsProportionalRegulations { - staticId gen.id - parameterSetId "GSFWPR" + gen.id - } - } else { - GeneratorSynchronousThreeWindingsProportionalRegulations { - staticId gen.id - parameterSetId "GSTWPR" + gen.id - } - } - OmegaRef { - generatorDynamicModelId gen.id - } -}