-
Notifications
You must be signed in to change notification settings - Fork 0
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
Dynamic Simulation - Curve Configuration - Add some expert filter's criteria for Load and Generator and new operators IN, NOT_IN #78
Changes from all commits
807207c
eeb112e
6de045f
dc38bfb
5445b6d
f122589
86c27d4
50028a1
012bd35
d1590c3
c6f824f
7c644d8
dbdb92f
384ab5b
11459da
cc2dfce
e788137
f861b71
9c777fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
package org.gridsuite.filter.server.dto.expertfilter.expertrule; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.powsybl.commons.PowsyblException; | ||
import com.powsybl.iidm.network.Identifiable; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
@@ -16,7 +17,12 @@ | |
import lombok.experimental.SuperBuilder; | ||
import org.gridsuite.filter.server.utils.expertfilter.DataType; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.gridsuite.filter.server.utils.expertfilter.ExpertFilterUtils.getFieldValue; | ||
import static org.gridsuite.filter.server.utils.expertfilter.OperatorType.isMultipleCriteriaOperator; | ||
|
||
/** | ||
* @author Antoine Bouhours <antoine.bouhours at rte-france.com> | ||
|
@@ -30,6 +36,10 @@ public class NumberExpertRule extends AbstractExpertRule { | |
@Schema(description = "Value") | ||
private Double value; | ||
|
||
@Schema(description = "Values") | ||
@JsonDeserialize(as = HashSet.class) | ||
private Set<Double> values; | ||
|
||
public static Double getNumberValue(String value) { | ||
return Double.parseDouble(value); | ||
} | ||
|
@@ -54,12 +64,18 @@ public boolean evaluateRule(Identifiable<?> identifiable) { | |
case LOWER_OR_EQUALS -> identifiableValue.compareTo(filterValue) <= 0; | ||
case LOWER -> identifiableValue.compareTo(filterValue) < 0; | ||
case EXISTS -> true; // We return true here because we already test above if identifiableValue is NaN. | ||
case IN -> this.getValues().contains(identifiableValue); | ||
case NOT_IN -> !this.getValues().contains(identifiableValue); | ||
default -> throw new PowsyblException(this.getOperator() + " operator not supported with " + this.getDataType() + " rule data type"); | ||
}; | ||
} | ||
|
||
@Override | ||
public String getStringValue() { | ||
return String.valueOf(this.getValue()); | ||
if (isMultipleCriteriaOperator(this.getOperator())) { // multiple values | ||
return this.getValues().stream().map(String::valueOf).collect(Collectors.joining(",")); | ||
} else { // single value or absence | ||
Comment on lines
+75
to
+77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe return an empty string, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should manage at DTO level by a validator to do a cross validation between two fields. This will be corrected in another PR |
||
return this.getValue() != null ? String.valueOf(this.getValue()) : null; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
package org.gridsuite.filter.server.dto.expertfilter.expertrule; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.powsybl.commons.PowsyblException; | ||
import com.powsybl.iidm.network.Identifiable; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
@@ -17,7 +18,11 @@ | |
import org.apache.commons.lang3.StringUtils; | ||
import org.gridsuite.filter.server.utils.expertfilter.DataType; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import static org.gridsuite.filter.server.utils.expertfilter.ExpertFilterUtils.getFieldValue; | ||
import static org.gridsuite.filter.server.utils.expertfilter.OperatorType.isMultipleCriteriaOperator; | ||
|
||
/** | ||
* @author Antoine Bouhours <antoine.bouhours at rte-france.com> | ||
|
@@ -31,6 +36,19 @@ public class StringExpertRule extends AbstractExpertRule { | |
@Schema(description = "Value") | ||
private String value; | ||
|
||
@Schema(description = "Values") | ||
@JsonDeserialize(as = HashSet.class) | ||
private Set<String> values; | ||
|
||
@Override | ||
public String getStringValue() { | ||
if (isMultipleCriteriaOperator(this.getOperator())) { // multiple values | ||
return String.join(",", this.getValues()); | ||
} else { // single value or absence | ||
Comment on lines
+45
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, throws a NPE if this.getValues() is null. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idem! Should manage at DTO level by a validator to do a cross validation between two fields. This will be corrected in another PR |
||
return this.getValue(); | ||
} | ||
} | ||
|
||
@Override | ||
@JsonProperty(access = JsonProperty.Access.READ_ONLY) | ||
public DataType getDataType() { | ||
|
@@ -46,12 +64,9 @@ public boolean evaluateRule(Identifiable<?> identifiable) { | |
case BEGINS_WITH -> StringUtils.startsWithIgnoreCase(identifiableValue, this.getValue()); | ||
case ENDS_WITH -> StringUtils.endsWithIgnoreCase(identifiableValue, this.getValue()); | ||
case EXISTS -> !StringUtils.isEmpty(identifiableValue); | ||
case IN -> this.getValues().contains(identifiableValue); | ||
case NOT_IN -> !this.getValues().contains(identifiableValue); | ||
Comment on lines
+67
to
+68
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential NPE There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idem! Should manage at DTO level by a validator to do a cross validation between two fields. This will be corrected in another PR |
||
default -> throw new PowsyblException(this.getOperator() + " operator not supported with " + this.getDataType() + " rule data type"); | ||
}; | ||
} | ||
|
||
@Override | ||
public String getStringValue() { | ||
return getValue(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential NPE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idem! Should manage at DTO level by a validator to do a cross validation between two fields. This will be corrected in another PR