Skip to content

Commit

Permalink
Non evacuated energy computation (#51)
Browse files Browse the repository at this point in the history
* non evacuated energy sensitivity analysis
  • Loading branch information
FranckLecuyer authored Jan 12, 2024
1 parent 79893ef commit 6ce9863
Show file tree
Hide file tree
Showing 46 changed files with 5,012 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@
import org.gridsuite.sensitivityanalysis.server.dto.SensitivityAnalysisStatus;
import org.gridsuite.sensitivityanalysis.server.dto.SensitivityResultFilterOptions;
import org.gridsuite.sensitivityanalysis.server.dto.SensitivityRunQueryResult;
import org.gridsuite.sensitivityanalysis.server.dto.resultselector.ResultTab;
import org.gridsuite.sensitivityanalysis.server.dto.resultselector.ResultsSelector;
import org.gridsuite.sensitivityanalysis.server.dto.nonevacuatedenergy.NonEvacuatedEnergyInputData;
import org.gridsuite.sensitivityanalysis.server.dto.nonevacuatedenergy.NonEvacuatedEnergyStatus;
import org.gridsuite.sensitivityanalysis.server.service.SensitivityAnalysisRunContext;
import org.gridsuite.sensitivityanalysis.server.service.SensitivityAnalysisService;
import org.gridsuite.sensitivityanalysis.server.service.SensitivityAnalysisWorkerService;
import org.gridsuite.sensitivityanalysis.server.service.nonevacuatedenergy.NonEvacuatedEnergyRunContext;
import org.gridsuite.sensitivityanalysis.server.service.nonevacuatedenergy.NonEvacuatedEnergyService;
import org.gridsuite.sensitivityanalysis.server.dto.SensitivityFactorsIdsByGroup;
import org.gridsuite.sensitivityanalysis.server.dto.resultselector.ResultTab;
import org.gridsuite.sensitivityanalysis.server.dto.resultselector.ResultsSelector;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand All @@ -49,9 +53,13 @@ public class SensitivityAnalysisController {

private final SensitivityAnalysisWorkerService workerService;

public SensitivityAnalysisController(SensitivityAnalysisService service, SensitivityAnalysisWorkerService workerService) {
private final NonEvacuatedEnergyService nonEvacuatedEnergyService;

public SensitivityAnalysisController(SensitivityAnalysisService service, SensitivityAnalysisWorkerService workerService,
NonEvacuatedEnergyService nonEvacuatedEnergyService) {
this.service = service;
this.workerService = workerService;
this.nonEvacuatedEnergyService = nonEvacuatedEnergyService;
}

private static ResultsSelector getSelector(String selectorJson) throws JsonProcessingException {
Expand Down Expand Up @@ -203,4 +211,79 @@ public ResponseEntity<List<String>> getProviders() {
public ResponseEntity<String> getDefaultProvider() {
return ResponseEntity.ok().body(service.getDefaultProvider());
}

@PostMapping(value = "/networks/{networkUuid}/non-evacuated-energy/run-and-save", produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
@Operation(summary = "Run a non evacuated energy sensitivity analysis on a network and save results in the database")
@ApiResponses(@ApiResponse(responseCode = "200", description = "The non evacuated energy sensitivity analysis default provider has been found"))
public ResponseEntity<UUID> runNonEvacuatedEnergy(@Parameter(description = "Network UUID") @PathVariable("networkUuid") UUID networkUuid,
@Parameter(description = "Variant Id") @RequestParam(name = "variantId", required = false) String variantId,
@Parameter(description = "Result receiver") @RequestParam(name = "receiver", required = false) String receiver,
@Parameter(description = "Provider") @RequestParam(name = "provider", required = false) String provider,
@Parameter(description = "reportUuid") @RequestParam(name = "reportUuid", required = false) UUID reportUuid,
@Parameter(description = "reporterId") @RequestParam(name = "reporterId", required = false) String reporterId,
@Parameter(description = "The type name for the report") @RequestParam(name = "reportType", required = false, defaultValue = "NonEvacuatedEnergy") String reportType,
@RequestBody NonEvacuatedEnergyInputData nonEvacuatedEnergyInputData,
@RequestHeader(HEADER_USER_ID) String userId) {
UUID resultUuid = nonEvacuatedEnergyService.runAndSaveResult(new NonEvacuatedEnergyRunContext(networkUuid, variantId, nonEvacuatedEnergyInputData, receiver, provider, reportUuid, reporterId, reportType, userId));
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(resultUuid);
}

@GetMapping(value = "/non-evacuated-energy/results/{resultUuid}", produces = APPLICATION_JSON_VALUE)
@Operation(summary = "Get a non evacuated energy result from the database")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The non evacuated energy result"),
@ApiResponse(responseCode = "404", description = "Non evacuated energy result has not been found")})
public ResponseEntity<String> getResult(@Parameter(description = "Result UUID")
@PathVariable("resultUuid") UUID resultUuid) {
String result = nonEvacuatedEnergyService.getRunResult(resultUuid);
return result != null ? ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(result)
: ResponseEntity.notFound().build();
}

@DeleteMapping(value = "/non-evacuated-energy/results/{resultUuid}", produces = APPLICATION_JSON_VALUE)
@Operation(summary = "Delete a non evacuated energy result from the database")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The non evacuated energy result has been deleted")})
public ResponseEntity<Void> deleteNonEvacuatedEnergyResult(@Parameter(description = "Result UUID") @PathVariable("resultUuid") UUID resultUuid) {
nonEvacuatedEnergyService.deleteResult(resultUuid);
return ResponseEntity.ok().build();
}

@DeleteMapping(value = "/non-evacuated-energy/results", produces = APPLICATION_JSON_VALUE)
@Operation(summary = "Delete all non evacuated energy results from the database")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "All non evacuated energy results have been deleted")})
public ResponseEntity<Void> deleteNonEvacuatedEnergyResults() {
nonEvacuatedEnergyService.deleteResults();
return ResponseEntity.ok().build();
}

@GetMapping(value = "/non-evacuated-energy/results/{resultUuid}/status", produces = APPLICATION_JSON_VALUE)
@Operation(summary = "Get the non evacuated energy status from the database")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The non evacuated energy status status")})
public ResponseEntity<String> getNonEvacuatedEnergyStatus(@Parameter(description = "Result UUID") @PathVariable("resultUuid") UUID resultUuid) {
String result = nonEvacuatedEnergyService.getStatus(resultUuid);
return ResponseEntity.ok().body(result);
}

@PutMapping(value = "/non-evacuated-energy/results/invalidate-status", produces = APPLICATION_JSON_VALUE)
@Operation(summary = "Invalidate the non evacuated energy status from the database")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The non evacuated energy status has been invalidated")})
public ResponseEntity<Void> invalidateNonEvacuatedEnergyStatus(@Parameter(description = "Result uuids") @RequestParam(name = "resultUuid") List<UUID> resultUuids) {
nonEvacuatedEnergyService.setStatus(resultUuids, NonEvacuatedEnergyStatus.NOT_DONE.name());
return ResponseEntity.ok().build();
}

@PutMapping(value = "/non-evacuated-energy/results/{resultUuid}/stop", produces = APPLICATION_JSON_VALUE)
@Operation(summary = "Stop a non evacuated energy computation")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The non evacuated energy has been stopped")})
public ResponseEntity<Void> stopNonEvacuatedEnergy(@Parameter(description = "Result UUID") @PathVariable("resultUuid") UUID resultUuid,
@Parameter(description = "Result receiver") @RequestParam(name = "receiver", required = false) String receiver) {
nonEvacuatedEnergyService.stop(resultUuid, receiver);
return ResponseEntity.ok().build();
}

@GetMapping(value = "/non-evacuated-energy-default-provider", produces = TEXT_PLAIN_VALUE)
@Operation(summary = "Get sensitivity analysis non evacuated energy default provider")
@ApiResponses(@ApiResponse(responseCode = "200", description = "The sensitivity analysis non evacuated energy default provider has been found"))
public ResponseEntity<String> getNonEvacuatedEnergyDefaultProvider() {
return ResponseEntity.ok().body(nonEvacuatedEnergyService.getDefaultProvider());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,16 @@ public SupervisionController(SupervisionService supervisionService) {
}

@GetMapping(value = "/results-count")
@Operation(summary = "Get results count")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The count of all results")})
@Operation(summary = "Get sensitivity analysis results count")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The count of all sensitivity analysis results")})
public ResponseEntity<Integer> getResultsCount() {
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(supervisionService.getResultsCount());
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(supervisionService.getAnalysisResultsCount());
}

@GetMapping(value = "/non-evacuated-energy/results-count")
@Operation(summary = "Get non evacuated energy results count")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The count of all non evacuated energy results")})
public ResponseEntity<Integer> getNonEvacuatedEnergyResultsCount() {
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(supervisionService.getNonEvacuatedEnergyResultsCount());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* 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.sensitivityanalysis.server.dto.nonevacuatedenergy;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.gridsuite.sensitivityanalysis.server.dto.EquipmentsContainer;

import java.util.List;

/**
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
*/
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Schema(description = "Sensitivity analysis non evacuated energy contingencies")
public class NonEvacuatedEnergyContingencies {
List<EquipmentsContainer> contingencies;

boolean activated;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* 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.sensitivityanalysis.server.dto.nonevacuatedenergy;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.List;

/**
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
*/
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Schema(description = "Sensitivity analysis non evacuated energy generators cappings")
public class NonEvacuatedEnergyGeneratorsCappings {
Double sensitivityThreshold;

List<NonEvacuatedEnergyGeneratorsCappingsByType> generators;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* 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.sensitivityanalysis.server.dto.nonevacuatedenergy;

import com.powsybl.iidm.network.EnergySource;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.gridsuite.sensitivityanalysis.server.dto.EquipmentsContainer;

import java.util.List;

/**
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
*/
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Schema(description = "Sensitivity analysis non evacuated energy generators cappings by type")
public class NonEvacuatedEnergyGeneratorsCappingsByType {
List<EquipmentsContainer> generators;

EnergySource energySource;

boolean activated;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* 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.sensitivityanalysis.server.dto.nonevacuatedenergy;

import com.powsybl.sensitivity.SensitivityAnalysisParameters;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.List;
import java.util.Map;

/**
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
*/
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Schema(description = "Sensitivity analysis non evacuated energy input data")
public class NonEvacuatedEnergyInputData {
private List<NonEvacuatedEnergyStageDefinition> nonEvacuatedEnergyStagesDefinition;

private List<NonEvacuatedEnergyStagesSelection> nonEvacuatedEnergyStagesSelection;

private NonEvacuatedEnergyGeneratorsCappings nonEvacuatedEnergyGeneratorsCappings;

private List<NonEvacuatedEnergyMonitoredBranches> nonEvacuatedEnergyMonitoredBranches;

private List<NonEvacuatedEnergyContingencies> nonEvacuatedEnergyContingencies;

@Schema(description = "Sensitivity parameters")
private SensitivityAnalysisParameters parameters;

@Schema(description = "Loadflow model-specific parameters")
private Map<String, String> loadFlowSpecificParameters;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* 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.sensitivityanalysis.server.dto.nonevacuatedenergy;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.gridsuite.sensitivityanalysis.server.dto.EquipmentsContainer;

import java.util.List;

/**
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
*/
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Schema(description = "Sensitivity analysis non evacuated energy monitored branches")
public class NonEvacuatedEnergyMonitoredBranches {
List<EquipmentsContainer> branches;

boolean activated;

boolean istN;

String limitNameN;

@JsonProperty("nCoefficient")
float nCoefficient;

boolean istNm1;

String limitNameNm1;

float nm1Coefficient;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* 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.sensitivityanalysis.server.dto.nonevacuatedenergy;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.powsybl.iidm.network.EnergySource;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.gridsuite.sensitivityanalysis.server.dto.EquipmentsContainer;

import java.util.List;

/**
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
*/
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@EqualsAndHashCode
@Schema(description = "Sensitivity analysis non evacuated energy stage definition")
public class NonEvacuatedEnergyStageDefinition {
List<EquipmentsContainer> generators;

EnergySource energySource;

@JsonProperty("pMaxPercents")
List<Float> pMaxPercents;
}
Loading

0 comments on commit 6ce9863

Please sign in to comment.