Skip to content

Commit a3d0db7

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/ms/#237-enhancing-and-refactoring-ExtCoSimulation' into ms/ReCoDe
# Conflicts: # src/main/java/edu/ie3/simona/api/data/results/ExtResultContainer.java # src/main/java/edu/ie3/simona/api/data/results/ExtResultDataConnection.java # src/main/java/edu/ie3/simona/api/simulation/ExtCoSimulation.java # src/main/java/edu/ie3/simona/api/simulation/mapping/ExtEntityEntry.java
2 parents 8323f56 + b5b7826 commit a3d0db7

File tree

10 files changed

+56
-67
lines changed

10 files changed

+56
-67
lines changed

build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
plugins {
22
id 'groovy' // groovy support
33
id 'java' // java support
4-
id 'com.diffplug.spotless' version '7.0.1'//code format
4+
id 'com.diffplug.spotless' version '7.0.2'//code format
55
id 'pmd' // code check, working on source code
6-
id 'com.github.spotbugs' version '6.0.27' // code check, working on byte code
6+
id 'com.github.spotbugs' version '6.1.5' // code check, working on byte code
77
id "org.sonarqube" version "6.0.1.5171" // sonarqube
88
id 'signing'
99
id 'maven-publish' // publish to a maven repo (local or mvn central, has to be defined)
@@ -18,8 +18,8 @@ ext {
1818

1919
// required for pekko
2020
scalaVersion = "2.13"
21-
scalaBinaryVersion = "2.13.15"
22-
pekkoVersion = "1.1.2"
21+
scalaBinaryVersion = "2.13.16"
22+
pekkoVersion = "1.1.3"
2323
}
2424

2525
group = 'com.github.ie3-institute'

docs/readthedocs/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
commonmark==0.9.1
22
recommonmark==0.7.1
3-
Sphinx==8.1.3
3+
Sphinx==8.2.1
44
sphinx-rtd-theme==3.0.2
5-
myst-parser==4.0.0
5+
myst-parser==4.0.1
66
markdown-it-py==3.0.0

src/main/java/edu/ie3/simona/api/data/results/ExtResultContainer.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ public Map<String, ModelResultEntity> getResults() {
5757
return simonaResultsMap;
5858
}
5959

60-
public String getResultsAsString() {
61-
return resultMapToString(simonaResultsMap);
62-
}
63-
6460
public Long getTick() {
6561
return tick;
6662
}
@@ -129,19 +125,4 @@ public double getReactivePower(String assetId) {
129125
public double getLineLoading(String assetId) {
130126
throw new IllegalArgumentException("LINE LOADING is not implemented yet!");
131127
}
132-
133-
private String resultMapToString(Map<String, ModelResultEntity> results) {
134-
StringBuilder resultString = new StringBuilder();
135-
for (String key : results.keySet()) {
136-
resultString
137-
.append("id = ")
138-
.append(key)
139-
.append(", time = ")
140-
.append(results.get(key).getTime())
141-
.append(", result = ")
142-
.append(results.get(key).getClass().getSimpleName())
143-
.append("\n");
144-
}
145-
return resultString.toString();
146-
}
147128
}

src/main/java/edu/ie3/simona/api/data/results/ExtResultDataConnection.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ private List<ModelResultEntity> requestParticiapntResultsList(long tick)
113113
return receiveWithType(ProvideResultEntities.class).results();
114114
}
115115

116+
private List<ModelResultEntity> requestParticiapntResultsList(long tick)
117+
throws InterruptedException {
118+
sendExtMsg(new RequestResultEntities(tick, getParticipantResultDataAssets()));
119+
return receiveWithType(ProvideResultEntities.class).results();
120+
}
121+
116122
/**
117123
* Method that an external simulation can request results from SIMONA as a map string to object.
118124
*/
@@ -131,7 +137,7 @@ public Map<String, ModelResultEntity> requestGridResults(long tick) throws Inter
131137

132138
public Map<String, ModelResultEntity> requestParticipantResults(long tick)
133139
throws InterruptedException {
134-
return createResultMap(requestGridResultsList(tick));
140+
return createResultMap(requestParticiapntResultsList(tick));
135141
}
136142

137143
protected Map<String, ModelResultEntity> createResultMap(List<ModelResultEntity> results) {

src/main/java/edu/ie3/simona/api/simulation/ExtCoSimulation.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,9 @@ private void sendSingleResultType(
274274
Logger log)
275275
throws InterruptedException {
276276
log.info("Request results from SIMONA for {} for tick {}!", type, tick);
277-
log.debug(
278-
"[{}] Received {} results from SIMONA!\n{}",
279-
tick,
280-
type,
281-
resultMapToString(resultsToBeSend));
277+
278+
String resultString = resultMapToString(resultsToBeSend);
279+
log.debug("[{}] Received {} results from SIMONA!\n{}", tick, type, resultString);
282280
dataQueueSimonaApiToExtCoSimulator.queueData(
283281
new ExtResultContainer(tick, resultsToBeSend, nextTick));
284282
log.info("Sent {} results for tick {} to {}", type, tick, extSimulatorName);
@@ -306,14 +304,18 @@ protected void sendResultToExt(
306304

307305
private String resultMapToString(Map<String, ModelResultEntity> results) {
308306
StringBuilder resultString = new StringBuilder();
309-
for (String key : results.keySet()) {
307+
308+
for (Map.Entry<String, ModelResultEntity> entry : results.entrySet()) {
309+
String key = entry.getKey();
310+
ModelResultEntity value = entry.getValue();
311+
310312
resultString
311313
.append("id = ")
312314
.append(key)
313315
.append(", time = ")
314-
.append(results.get(key).getTime())
316+
.append(value.getTime())
315317
.append(", result = ")
316-
.append(results.get(key).getClass().getSimpleName())
318+
.append(value.getClass().getSimpleName())
317319
.append("\n");
318320
}
319321
return resultString.toString();

src/main/java/edu/ie3/simona/api/simulation/mapping/ExtEntityEntry.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@
2020
* @param dataType data types the external asset expects
2121
*/
2222
public record ExtEntityEntry(
23-
UUID uuid,
24-
String id,
25-
Optional<ColumnScheme>
26-
columnScheme, // FIXME: placeholder -> ColumnScheme should handle more data types
27-
DataType dataType)
23+
UUID uuid, String id, Optional<ColumnScheme> columnScheme, DataType dataType)
2824
implements InputEntity {
2925

3026
public String toString() {

src/main/java/edu/ie3/simona/api/simulation/mapping/ExtEntityFactory.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ protected ExtEntityEntry buildModel(EntityData data) {
4646
throw new FactoryException(e);
4747
}
4848

49-
return new ExtEntityEntry(
50-
simonaUuid,
51-
extId,
52-
columnScheme, // FIXME: Interim version -> ColumnScheme should handle more data types
53-
inputType);
49+
return new ExtEntityEntry(simonaUuid, extId, columnScheme, inputType);
5450
}
5551
}

src/test/groovy/edu/ie3/simona/api/data/results/ExtResultDataConnectionTest.groovy

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ class ExtResultDataConnectionTest extends Specification implements DataServiceTe
3030
@Shared
3131
Map<UUID, String> gridResultAssetMapping = [:]
3232

33+
@Shared
34+
Map<UUID, String> flexResultAssetMapping = [:]
35+
3336
class WrongResultDataResponseMessageToExt implements ResultDataResponseMessageToExt {}
3437

3538
def setupSpec() {
@@ -46,7 +49,7 @@ class ExtResultDataConnectionTest extends Specification implements DataServiceTe
4649
def dataService = new TestProbe(actorSystem)
4750
def dataServiceActivation = new TestProbe(actorSystem)
4851
def extSimAdapter = new TestProbe(actorSystem)
49-
def extResultDataConnection = new ExtResultDataConnection(participantResultAssetMapping, gridResultAssetMapping)
52+
def extResultDataConnection = new ExtResultDataConnection(participantResultAssetMapping, gridResultAssetMapping, flexResultAssetMapping)
5053
extResultDataConnection.setActorRefs(
5154
dataService.ref(),
5255
dataServiceActivation.ref(),
@@ -61,7 +64,7 @@ class ExtResultDataConnectionTest extends Specification implements DataServiceTe
6164
def receivedResults = extResultDataConnection.requestResults(0L)
6265

6366
then:
64-
dataService.expectMsg(new RequestResultEntities(0L))
67+
dataService.expectMsg(new RequestResultEntities(0L, [inputUuid]))
6568
extSimAdapter.expectMsg(new ScheduleDataServiceMessage(dataServiceActivation.ref()))
6669
receivedResults.get("Load") == loadResult
6770
}
@@ -71,7 +74,7 @@ class ExtResultDataConnectionTest extends Specification implements DataServiceTe
7174
def dataService = new TestProbe(actorSystem)
7275
def dataServiceActivation = new TestProbe(actorSystem)
7376
def extSimAdapter = new TestProbe(actorSystem)
74-
def extResultDataConnection = new ExtResultDataConnection(participantResultAssetMapping, gridResultAssetMapping)
77+
def extResultDataConnection = new ExtResultDataConnection(participantResultAssetMapping, gridResultAssetMapping, flexResultAssetMapping)
7578
extResultDataConnection.setActorRefs(
7679
dataService.ref(),
7780
dataServiceActivation.ref(),
@@ -86,14 +89,14 @@ class ExtResultDataConnectionTest extends Specification implements DataServiceTe
8689
extResultDataConnection.requestResults(0L)
8790

8891
then:
89-
dataService.expectMsg(new RequestResultEntities(0L))
92+
dataService.expectMsg(new RequestResultEntities(0L, [inputUuid]))
9093
extSimAdapter.expectMsg(new ScheduleDataServiceMessage(dataServiceActivation.ref()))
9194
thrown RuntimeException
9295
}
9396

9497
def "ExtResultData should convert a list of result entities correctly to a map of resultAssetMappingId to result entity"() {
9598
given:
96-
def extResultDataConnection = new ExtResultDataConnection(participantResultAssetMapping, gridResultAssetMapping)
99+
def extResultDataConnection = new ExtResultDataConnection(participantResultAssetMapping, gridResultAssetMapping, flexResultAssetMapping)
97100

98101
when:
99102
def mapOfResults = extResultDataConnection.createResultMap([loadResult])
@@ -105,7 +108,7 @@ class ExtResultDataConnectionTest extends Specification implements DataServiceTe
105108

106109
def "ExtResultData should throw an exception, if a result with a wrong data type was provided"() {
107110
given:
108-
def extResultDataConnection = new ExtResultDataConnection(participantResultAssetMapping, gridResultAssetMapping)
111+
def extResultDataConnection = new ExtResultDataConnection(participantResultAssetMapping, gridResultAssetMapping, flexResultAssetMapping)
109112
Quantity<ElectricCurrent> iAMag = Quantities.getQuantity(100, StandardUnits.ELECTRIC_CURRENT_MAGNITUDE)
110113
Quantity<Angle> iAAng = Quantities.getQuantity(45, StandardUnits.ELECTRIC_CURRENT_ANGLE)
111114
Quantity<ElectricCurrent> iBMag = Quantities.getQuantity(150, StandardUnits.ELECTRIC_CURRENT_MAGNITUDE)

src/test/groovy/edu/ie3/simona/api/simulation/ExtCoSimulationTest.groovy

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,19 @@ class ExtCoSimulationTest extends Specification {
2020
UUID uuid2 = UUID.randomUUID()
2121
UUID uuid3 = UUID.randomUUID()
2222

23+
Optional<ColumnScheme> columnScheme = Optional.of(ColumnScheme.ACTIVE_POWER)
24+
2325
ExtEntityMapping mapping = new ExtEntityMapping([
24-
new ExtEntityEntry(uuid1, "primary1", ColumnScheme.ACTIVE_POWER, DataType.EXT_PRIMARY_INPUT),
25-
new ExtEntityEntry(uuid2, "em1", ColumnScheme.ACTIVE_POWER, DataType.EXT_EM_INPUT),
26-
new ExtEntityEntry(uuid3, "primary2", ColumnScheme.ACTIVE_POWER, DataType.EXT_PRIMARY_INPUT),
26+
new ExtEntityEntry(uuid1, "primary1", columnScheme, DataType.EXT_PRIMARY_INPUT),
27+
new ExtEntityEntry(uuid2, "em1", columnScheme, DataType.EXT_EM_INPUT),
28+
new ExtEntityEntry(uuid3, "primary2", columnScheme, DataType.EXT_PRIMARY_INPUT),
2729
])
2830

2931
when:
3032
def actual = ExtCoSimulation.buildPrimaryConnection(mapping, log)
3133

3234
then:
33-
actual.get().primaryDataAssets == [uuid3, uuid1]
35+
actual.primaryDataAssets == [uuid3, uuid1]
3436
}
3537

3638
def "An ExtCoSimulation can build an em data connection correctly"() {
@@ -39,17 +41,19 @@ class ExtCoSimulationTest extends Specification {
3941
UUID uuid2 = UUID.randomUUID()
4042
UUID uuid3 = UUID.randomUUID()
4143

44+
Optional<ColumnScheme> columnScheme = Optional.of(ColumnScheme.ACTIVE_POWER)
45+
4246
ExtEntityMapping mapping = new ExtEntityMapping([
43-
new ExtEntityEntry(uuid1, "em1", ColumnScheme.ACTIVE_POWER, DataType.EXT_EM_INPUT),
44-
new ExtEntityEntry(uuid2, "em2", ColumnScheme.ACTIVE_POWER, DataType.EXT_EM_INPUT),
45-
new ExtEntityEntry(uuid3, "primary1", ColumnScheme.ACTIVE_POWER, DataType.EXT_PRIMARY_INPUT),
47+
new ExtEntityEntry(uuid1, "em1", columnScheme, DataType.EXT_EM_INPUT),
48+
new ExtEntityEntry(uuid2, "em2", columnScheme, DataType.EXT_EM_INPUT),
49+
new ExtEntityEntry(uuid3, "primary1", columnScheme, DataType.EXT_PRIMARY_INPUT),
4650
])
4751

4852
when:
4953
def actual = ExtCoSimulation.buildEmConnection(mapping, log)
5054

5155
then:
52-
actual.get().controlledEms == [uuid1, uuid2]
56+
actual.controlledEms == [uuid1, uuid2]
5357
}
5458

5559
def "An ExtCoSimulation can build a result data connection correctly"() {
@@ -58,19 +62,20 @@ class ExtCoSimulationTest extends Specification {
5862
UUID uuid2 = UUID.randomUUID()
5963
UUID uuid3 = UUID.randomUUID()
6064

65+
Optional<ColumnScheme> columnScheme = Optional.of(ColumnScheme.ACTIVE_POWER)
66+
6167
ExtEntityMapping mapping = new ExtEntityMapping([
62-
new ExtEntityEntry(uuid1, "grid_result", ColumnScheme.ACTIVE_POWER, DataType.EXT_GRID_RESULT),
63-
new ExtEntityEntry(uuid2, "participant_result", ColumnScheme.ACTIVE_POWER, DataType.EXT_PARTICIPANT_RESULT),
64-
new ExtEntityEntry(uuid3, "primary1", ColumnScheme.ACTIVE_POWER, DataType.EXT_PRIMARY_INPUT),
68+
new ExtEntityEntry(uuid1, "grid_result", columnScheme, DataType.EXT_GRID_RESULT),
69+
new ExtEntityEntry(uuid2, "participant_result", columnScheme, DataType.EXT_PARTICIPANT_RESULT),
70+
new ExtEntityEntry(uuid3, "primary1", columnScheme, DataType.EXT_PRIMARY_INPUT),
6571
])
6672

6773
when:
6874
def actual = ExtCoSimulation.buildResultConnection(mapping, log)
6975

7076
then:
71-
actual.isPresent()
72-
73-
actual.get().gridResultDataAssets == [uuid1]
74-
actual.get().participantResultDataAssets == [uuid2]
77+
actual.gridResultDataAssets == [uuid1]
78+
actual.participantResultDataAssets == [uuid2]
79+
actual.flexOptionAssets == []
7580
}
7681
}

src/test/groovy/edu/ie3/simona/api/simulation/mapping/ExtEntityMappingTest.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ class ExtEntityMappingTest extends Specification {
1212
ExtEntityEntry extResultEntry = new ExtEntityEntry(
1313
loadUuid,
1414
"Load",
15-
ColumnScheme.parse("p").get(),
15+
ColumnScheme.parse("p"),
1616
DataType.EXT_PARTICIPANT_RESULT
1717
)
1818

1919
@Shared
2020
ExtEntityEntry extInputEntry = new ExtEntityEntry(
2121
loadUuid,
2222
"Load",
23-
ColumnScheme.parse("p").get(),
23+
ColumnScheme.parse("p"),
2424
DataType.EXT_PRIMARY_INPUT
2525
)
2626

0 commit comments

Comments
 (0)