Skip to content

Commit affed4f

Browse files
author
EDWARDS Philippe
committed
add range type for non pst range actions in json schemas, and add unit test
Signed-off-by: EDWARDS Philippe <edwardsphi@gm0winl1028.bureau.si.interne>
1 parent b4ef511 commit affed4f

9 files changed

Lines changed: 311 additions & 4 deletions

File tree

data/crac/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/crac/io/json/deserializers/StandardRangeArrayDeserializer.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public static void deserialize(JsonParser jsonParser, StandardRangeActionAdder<?
3737
jsonParser.nextToken();
3838
adder.withMax(jsonParser.getDoubleValue());
3939
break;
40+
case JsonSerializationConstants.RANGE_TYPE:
41+
adder.withRangeType(JsonSerializationConstants.deserializeRangeType(jsonParser.nextTextValue()));
42+
break;
4043
default:
4144
throw new OpenRaoException("Unexpected field in StandardRange: " + jsonParser.getCurrentName());
4245
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema#",
3+
"$id": "resource:/schemas/counter-trade-range-action/counter-trade-range-action-v2.8.json",
4+
"type": "object",
5+
"properties": {
6+
"id": {
7+
"type": "string"
8+
},
9+
"name": {
10+
"type": [
11+
"string",
12+
"null"
13+
]
14+
},
15+
"operator": {
16+
"type": [
17+
"string",
18+
"null"
19+
]
20+
},
21+
"activationCost": "number",
22+
"variationCosts": {
23+
"$ref": "../variation-costs/variation-costs-v2.6.json"
24+
},
25+
"groupId": {
26+
"type": [
27+
"string",
28+
"null"
29+
]
30+
},
31+
"speed": {
32+
"type": "number"
33+
},
34+
"exportingCountry": {
35+
"$ref": "../country/country-v1.3.json"
36+
},
37+
"importingCountry": {
38+
"$ref": "../country/country-v1.3.json"
39+
},
40+
"ranges": {
41+
"type": "array",
42+
"items": {
43+
"type": "object",
44+
"properties": {
45+
"max": {
46+
"type": "number"
47+
},
48+
"min": {
49+
"type": "number"
50+
}
51+
},
52+
"additionalProperties": false
53+
}
54+
},
55+
"onInstantUsageRules": {
56+
"type": "array",
57+
"items": {
58+
"$ref": "../on-instant-usage-rule/on-instant-usage-rule-v2.8.json"
59+
}
60+
},
61+
"onContingencyStateUsageRules": {
62+
"type": "array",
63+
"items": {
64+
"$ref": "../on-contingency-state-usage-rule/on-contingency-state-usage-rule-v2.8.json"
65+
}
66+
},
67+
"onConstraintUsageRules": {
68+
"type": "array",
69+
"items": {
70+
"$ref": "../on-constraint-usage-rule/on-constraint-usage-rule-v2.8.json"
71+
}
72+
},
73+
"onFlowConstraintInCountryUsageRules": {
74+
"type": "array",
75+
"items": {
76+
"$ref": "../on-flow-constraint-in-country-usage-rule/on-flow-constraint-in-country-usage-rule-v2.8.json"
77+
}
78+
}
79+
},
80+
"additionalProperties": false,
81+
"required": [
82+
"id",
83+
"exportingCountry",
84+
"importingCountry",
85+
"ranges"
86+
]
87+
}

data/crac/crac-io/crac-io-json/src/main/resources/schemas/counter-trade-range-action/counter-trade-range-action-v2.8.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
"items": {
4343
"type": "object",
4444
"properties": {
45+
"rangeType": {
46+
"$ref": "../range-type/range-type-v2.3.json"
47+
},
4548
"max": {
4649
"type": "number"
4750
},

data/crac/crac-io/crac-io-json/src/main/resources/schemas/crac/crac-v2.10.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,19 @@
8080
"hvdcRangeActions": {
8181
"type": "array",
8282
"items": {
83-
"$ref": "../hvdc-range-action/hvdc-range-action-v2.8.json"
83+
"$ref": "../hvdc-range-action/hvdc-range-action-v2.10.json"
8484
}
8585
},
8686
"injectionRangeActions": {
8787
"type": "array",
8888
"items": {
89-
"$ref": "../injection-range-action/injection-range-action-v2.8.json"
89+
"$ref": "../injection-range-action/injection-range-action-v2.10.json"
9090
}
9191
},
9292
"counterTradeRangeActions": {
9393
"type": "array",
9494
"items": {
95-
"$ref": "../counter-trade-range-action/counter-trade-range-action-v2.8.json"
95+
"$ref": "../counter-trade-range-action/counter-trade-range-action-v2.10.json"
9696
}
9797
},
9898
"networkActions": {
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema#",
3+
"$id": "resource:/schemas/hvdc-range-action/hvdc-range-action-v2.8.json",
4+
"type": "object",
5+
"properties": {
6+
"id": {
7+
"type": "string"
8+
},
9+
"name": {
10+
"type": [
11+
"string",
12+
"null"
13+
]
14+
},
15+
"operator": {
16+
"type": [
17+
"string",
18+
"null"
19+
]
20+
},
21+
"activationCost": "number",
22+
"variationCosts": {
23+
"$ref": "../variation-costs/variation-costs-v2.6.json"
24+
},
25+
"groupId": {
26+
"type": [
27+
"string",
28+
"null"
29+
]
30+
},
31+
"speed": {
32+
"type": "number"
33+
},
34+
"networkElementId": {
35+
"type": "string"
36+
},
37+
"ranges": {
38+
"type": "array",
39+
"items": {
40+
"type": "object",
41+
"properties": {
42+
"rangeType": {
43+
"$ref": "../range-type/range-type-v2.3.json"
44+
},
45+
"max": {
46+
"type": "number"
47+
},
48+
"min": {
49+
"type": "number"
50+
}
51+
},
52+
"additionalProperties": false
53+
}
54+
},
55+
"onInstantUsageRules": {
56+
"type": "array",
57+
"items": {
58+
"$ref": "../on-instant-usage-rule/on-instant-usage-rule-v2.8.json"
59+
}
60+
},
61+
"onContingencyStateUsageRules": {
62+
"type": "array",
63+
"items": {
64+
"$ref": "../on-contingency-state-usage-rule/on-contingency-state-usage-rule-v2.8.json"
65+
}
66+
},
67+
"onConstraintUsageRules": {
68+
"type": "array",
69+
"items": {
70+
"$ref": "../on-constraint-usage-rule/on-constraint-usage-rule-v2.8.json"
71+
}
72+
},
73+
"onFlowConstraintInCountryUsageRules": {
74+
"type": "array",
75+
"items": {
76+
"$ref": "../on-flow-constraint-in-country-usage-rule/on-flow-constraint-in-country-usage-rule-v2.8.json"
77+
}
78+
}
79+
},
80+
"additionalProperties": false,
81+
"required": [
82+
"id",
83+
"networkElementId",
84+
"ranges"
85+
]
86+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema#",
3+
"$id": "resource:/schemas/injection-range-action/injection-range-action-v2.8.json",
4+
"type": "object",
5+
"properties": {
6+
"id": {
7+
"type": "string"
8+
},
9+
"name": {
10+
"type": [
11+
"string",
12+
"null"
13+
]
14+
},
15+
"operator": {
16+
"type": [
17+
"string",
18+
"null"
19+
]
20+
},
21+
"activationCost": "number",
22+
"variationCosts": {
23+
"$ref": "../variation-costs/variation-costs-v2.6.json"
24+
},
25+
"groupId": {
26+
"type": [
27+
"string",
28+
"null"
29+
]
30+
},
31+
"speed": {
32+
"type": "number"
33+
},
34+
"networkElementIdsAndKeys": {
35+
"type": "object",
36+
"additionalProperties": {
37+
"type": "number"
38+
}
39+
},
40+
"ranges": {
41+
"type": "array",
42+
"items": {
43+
"type": "object",
44+
"properties": {
45+
"rangeType": {
46+
"$ref": "../range-type/range-type-v2.3.json"
47+
},
48+
"max": {
49+
"type": "number"
50+
},
51+
"min": {
52+
"type": "number"
53+
}
54+
},
55+
"additionalProperties": false
56+
}
57+
},
58+
"onInstantUsageRules": {
59+
"type": "array",
60+
"items": {
61+
"$ref": "../on-instant-usage-rule/on-instant-usage-rule-v2.8.json"
62+
}
63+
},
64+
"onContingencyStateUsageRules": {
65+
"type": "array",
66+
"items": {
67+
"$ref": "../on-contingency-state-usage-rule/on-contingency-state-usage-rule-v2.8.json"
68+
}
69+
},
70+
"onConstraintUsageRules": {
71+
"type": "array",
72+
"items": {
73+
"$ref": "../on-constraint-usage-rule/on-constraint-usage-rule-v2.8.json"
74+
}
75+
},
76+
"onFlowConstraintInCountryUsageRules": {
77+
"type": "array",
78+
"items": {
79+
"$ref": "../on-flow-constraint-in-country-usage-rule/on-flow-constraint-in-country-usage-rule-v2.8.json"
80+
}
81+
}
82+
},
83+
"additionalProperties": false,
84+
"required": [
85+
"id",
86+
"networkElementIdsAndKeys",
87+
"ranges"
88+
]
89+
}

data/crac/crac-io/crac-io-json/src/test/java/com/powsybl/openrao/data/crac/io/json/JsonRetrocompatibilityTest.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,27 @@ void importV2Point8Test() throws IOException {
409409
testContentOfV2Point8Crac(crac);
410410
}
411411

412+
@Test
413+
void importV2Point10Test() throws IOException {
414+
// added more flexibility on range types of non tap ranges
415+
String cracFilePath = "/retrocompatibility/v2/crac-v2.10.json";
416+
InputStream cracFile = getClass().getResourceAsStream(cracFilePath);
417+
418+
Crac crac = Crac.read(cracFilePath, cracFile, network);
419+
testContentOfV2Point10Crac(crac);
420+
}
421+
422+
@Test
423+
void importV2Point10WithMaxTso() throws IOException {
424+
// max tso should no longer be read (no api to test) but the crac should still import correctly
425+
// (a warning message should be logged)
426+
String cracFilePath = "/crac2.10-with_maxtso.json";
427+
InputStream cracFile = getClass().getResourceAsStream(cracFilePath);
428+
429+
Crac crac = Crac.read(cracFilePath, cracFile, network);
430+
assertEquals(1, crac.getFlowCnecs().size());
431+
}
432+
412433
private void testContentOfV1Point0Crac(Crac crac) {
413434
Instant preventiveInstant = crac.getInstant("preventive");
414435
Instant autoInstant = crac.getInstant("auto");
@@ -975,4 +996,21 @@ private void testContentOfV2Point8Crac(Crac crac) {
975996
assertEquals(-100, crac.getHvdcRangeAction("hvdcRange2Id").getInitialSetpoint(), 1e-3);
976997
assertEquals(50, crac.getInjectionRangeAction("injectionRange1Id").getInitialSetpoint(), 1e-3);
977998
}
999+
1000+
private void testContentOfV2Point10Crac(Crac crac) {
1001+
testContentOfV2Point8Crac(crac);
1002+
1003+
assertEquals(
1004+
1,
1005+
crac.getInjectionRangeAction("injectionRange1Id").getRanges().stream()
1006+
.filter(range -> range.getRangeType().equals(RangeType.RELATIVE_TO_PREVIOUS_INSTANT))
1007+
.count()
1008+
);
1009+
assertEquals(
1010+
1,
1011+
crac.getInjectionRangeAction("injectionRange1Id").getRanges().stream()
1012+
.filter(range -> range.getRangeType().equals(RangeType.ABSOLUTE))
1013+
.count()
1014+
);
1015+
}
9781016
}

data/crac/crac-io/crac-io-json/src/test/resources/crac2.10-with_maxtso.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
{
2929
"id": "flowCnec",
3030
"name": "flowCnec",
31-
"networkElementId": "FFR1AA1 FFR3AA1 1",
31+
"networkElementId": "ne4Id",
3232
"operator": "FR",
3333
"instant": "preventive",
3434
"contingencyId": null,

data/crac/crac-io/crac-io-json/src/test/resources/retrocompatibility/v2/crac-v2.10.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@
339339
"min" : -500.0,
340340
"max" : 500.0
341341
}, {
342+
"rangeType" : "relativeToPreviousInstant",
342343
"min" : -1000.0,
343344
"max" : 1000.0
344345
} ]

0 commit comments

Comments
 (0)