Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Non evacuated energy computation #51

Merged
merged 24 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ae81ac1
non evacuated energy sensitivity analysis (in progress)
FranckLecuyer Nov 3, 2023
2a959f5
non evacuated energy sensitivity parameters
FranckLecuyer Nov 20, 2023
9fe609c
non evacuated energy sensitivity parameters
FranckLecuyer Nov 30, 2023
a83b584
Merge remote-tracking branch 'origin/main' into non-evacuated-energy-…
FranckLecuyer Nov 30, 2023
50b6907
non evacuated energy sensitivity parameters
FranckLecuyer Dec 1, 2023
2e0cc05
Handle provider and default provider for non evacuated energy
FranckLecuyer Dec 6, 2023
351e078
Merge remote-tracking branch 'origin/main' into non-evacuated-energy-…
FranckLecuyer Dec 6, 2023
cbfb207
Non evacuated energy computation logs are now displayed in the result…
FranckLecuyer Dec 7, 2023
ec09471
Fix check on limits existence (permanent and temporary limit)
FranckLecuyer Dec 14, 2023
c590f6f
Merge remote-tracking branch 'origin/main' into non-evacuated-energy-…
FranckLecuyer Dec 15, 2023
fc4ee21
Fix failing test
FranckLecuyer Dec 15, 2023
5fbfc56
Some fixes and refactoring
FranckLecuyer Dec 19, 2023
a70c795
Merge remote-tracking branch 'origin/main' into non-evacuated-energy-…
FranckLecuyer Dec 19, 2023
b15ca22
Merge remote-tracking branch 'origin/main' into non-evacuated-energy-…
FranckLecuyer Jan 3, 2024
b8efe32
Changes after renamings in study-server
FranckLecuyer Jan 8, 2024
03208a4
Use specific status for non evacuated energy
FranckLecuyer Jan 9, 2024
7ce81d7
Changing endpoints
FranckLecuyer Jan 9, 2024
8c23a28
Some changes after code review
FranckLecuyer Jan 10, 2024
0119055
Fix resource test file
FranckLecuyer Jan 10, 2024
83ee023
Refactoring code on smaller methods
FranckLecuyer Jan 10, 2024
4a94d84
Another code refactoring
FranckLecuyer Jan 10, 2024
454ed58
Code refactoring
FranckLecuyer Jan 11, 2024
acf0ee4
Fix report on limit considered for monitored branch
FranckLecuyer Jan 11, 2024
cf9b3c9
Adding another report
FranckLecuyer Jan 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@
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.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 +52,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 +210,79 @@ public ResponseEntity<List<String>> getProviders() {
public ResponseEntity<String> getDefaultProvider() {
return ResponseEntity.ok().body(service.getDefaultProvider());
}

@PostMapping(value = "/networks/{networkUuid}/non-evacuated-energy", produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
FranckLecuyer marked this conversation as resolved.
Show resolved Hide resolved
@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)
FranckLecuyer marked this conversation as resolved.
Show resolved Hide resolved
@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();
}
FranckLecuyer marked this conversation as resolved.
Show resolved Hide resolved

@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);
}
FranckLecuyer marked this conversation as resolved.
Show resolved Hide resolved

@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, SensitivityAnalysisStatus.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();
FranckLecuyer marked this conversation as resolved.
Show resolved Hide resolved
}

@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.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;
import org.gridsuite.sensitivityanalysis.server.dto.EquipmentsContainer;

import java.util.List;

/**
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
*/
@SuperBuilder
@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,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.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;
import org.gridsuite.sensitivityanalysis.server.dto.EquipmentsContainer;

import java.util.List;

/**
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
*/
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Schema(description = "Sensitivity analysis non evacuated energy generators limit by type")
public class NonEvacuatedEnergyGeneratorLimitByType {
FranckLecuyer marked this conversation as resolved.
Show resolved Hide resolved
List<EquipmentsContainer> generators;

EnergySource energySource;

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.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;

import java.util.List;

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

List<NonEvacuatedEnergyGeneratorLimitByType> generators;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* 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.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;

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

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

private List<NonEvacuatedEnergyStagesSelection> nonEvacuatedEnergyStagesSelection;
Comment on lines +30 to +32
Copy link
Contributor

Choose a reason for hiding this comment

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

It's related to the comment in the tests but I would change the data model so it does not rely on lists and index of lists. It makes relationships between objects clearer and avoid to iterate through indexes in the code.


private NonEvacuatedEnergyGeneratorsLimit nonEvacuatedEnergyGeneratorsLimit;

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.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;
import org.gridsuite.sensitivityanalysis.server.dto.EquipmentsContainer;

import java.util.List;

/**
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
*/
@SuperBuilder
@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.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;
import org.gridsuite.sensitivityanalysis.server.dto.EquipmentsContainer;

import java.util.List;

/**
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
*/
@SuperBuilder
@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;
}
Comment on lines +32 to +39
Copy link
Contributor

Choose a reason for hiding this comment

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

What if it becomes like that

Suggested change
public class NonEvacuatedEnergyStageDefinition {
List<EquipmentsContainer> generators;
EnergySource energySource;
@JsonProperty("pMaxPercents")
List<Float> pMaxPercents;
}
public class NonEvacuatedEnergyGeneratorsSourceGroup {
List<EquipmentsContainer> generators;
EnergySource energySource;
}

Loading
Loading