99import edu .ie3 .simona .api .data .model .em .*;
1010import edu .ie3 .simona .api .ontology .em .*;
1111import java .util .*;
12+ import org .slf4j .Logger ;
1213
1314/** Enables data connection of em data between SIMONA and SimonaAPI */
1415public final class ExtEmDataConnection
@@ -32,42 +33,39 @@ public List<UUID> getControlledEms() {
3233 }
3334
3435 /**
35- * Tries to send em data to SIMONA. A message is sent, if at least one map is not empty.
36+ * Tries to send em data to SIMONA. A message is sent, if the map is not empty.
3637 *
3738 * @param tick current tick
38- * @param flexRequests receiver to flex option request
39- * @param flexOptions receiver to flex options
40- * @param setPoints receiver to set point
41- * @param maybeNextTick option for the next tick in the simulation
39+ * @param emData a map: receiver to em data
40+ * @param log logger for logging warnings
4241 * @return true, if data was sent
4342 */
44- public boolean sendEmData (
45- long tick ,
46- Map <UUID , FlexOptionRequest > flexRequests ,
47- Map <UUID , List <FlexOptions >> flexOptions ,
48- Map <UUID , EmSetPoint > setPoints ,
49- Optional <Long > maybeNextTick ) {
43+ public boolean sendEmData (long tick , Map <UUID , ? extends EmData > emData , Logger log ) {
5044 // send message only if at least one value is present
51- if (!flexRequests . isEmpty () || ! flexOptions . isEmpty () || ! setPoints .isEmpty ()) {
52- sendExtMsg (new ProvideEmData (tick , flexRequests , flexOptions , setPoints , maybeNextTick ));
45+ if (!emData .isEmpty ()) {
46+ sendExtMsg (ProvideEmData . create (tick , emData , log ));
5347 return true ;
5448 }
5549 return false ;
5650 }
5751
5852 /**
59- * Tries to send flex option requests to SIMONA. A message is sent, if at least one entity is
60- * given.
53+ * Tries to send em data to SIMONA. A message is sent, if at least one map is not empty.
6154 *
6255 * @param tick current tick
63- * @param entities for which flex options should be requested
64- * @param disaggregated if disaggregated flex option should be returned
56+ * @param flexRequests receiver to flex option request
57+ * @param flexOptions receiver to flex options
58+ * @param setPoints receiver to set point that should be sent to SIMONA
6559 * @return true, if data was sent
6660 */
67- public boolean sendFlexRequest (long tick , Collection <UUID > entities , boolean disaggregated ) {
61+ public boolean sendEmData (
62+ long tick ,
63+ Map <UUID , FlexOptionRequest > flexRequests ,
64+ Map <UUID , List <FlexOptions >> flexOptions ,
65+ Map <UUID , EmSetPoint > setPoints ) {
6866 // send message only if at least one value is present
69- if (!entities .isEmpty ()) {
70- sendExtMsg (new RequestEmFlexResults (tick , new ArrayList <>( entities ), disaggregated ));
67+ if (!flexRequests . isEmpty () || ! flexOptions . isEmpty () || ! setPoints .isEmpty ()) {
68+ sendExtMsg (new ProvideEmData (tick , flexRequests , flexOptions , setPoints ));
7169 return true ;
7270 }
7371 return false ;
@@ -79,33 +77,13 @@ public boolean sendFlexRequest(long tick, Collection<UUID> entities, boolean dis
7977 *
8078 * @param tick current tick
8179 * @param emCommunicationMessages that should be sent
82- * @param maybeNextTick an option for the next tick
8380 * @return true, if data was sent
8481 */
8582 public boolean sendCommunicationMessage (
86- long tick ,
87- List <EmCommunicationMessage <?>> emCommunicationMessages ,
88- Optional <Long > maybeNextTick ) {
83+ long tick , List <EmCommunicationMessage <?>> emCommunicationMessages ) {
8984 // send message only if at least one value is present
9085 if (!emCommunicationMessages .isEmpty ()) {
91- sendExtMsg (new EmCommunicationMessages (tick , emCommunicationMessages , maybeNextTick ));
92- return true ;
93- }
94- return false ;
95- }
96-
97- /**
98- * Tries to send the em set points to SIMONA.
99- *
100- * @param tick current tick
101- * @param setPoints receiver to set point, that should be sent to SIMONA
102- * @param maybeNextTick option for the next tick in the simulation
103- * @return true, if data was sent
104- */
105- public boolean sendSetPoints (
106- long tick , Map <UUID , EmSetPoint > setPoints , Optional <Long > maybeNextTick ) {
107- if (!setPoints .isEmpty ()) {
108- sendExtMsg (new ProvideEmSetPointData (tick , setPoints , maybeNextTick ));
86+ sendExtMsg (new EmCommunicationMessages (tick , emCommunicationMessages ));
10987 return true ;
11088 }
11189 return false ;
@@ -115,13 +93,18 @@ public boolean sendSetPoints(
11593 * Method to request em flexibility options from SIMONA.
11694 *
11795 * @param tick for which set points are requested
118- * @param emEntities for which set points are requested
119- * @return an {@link FlexOptionsResponse} message
96+ * @param entities for which set points are requested
97+ * @return a map: uuid to list of flex options
12098 * @throws InterruptedException - on interruptions
12199 */
122- public Map <UUID , ExtendedFlexOptionsResult > requestEmFlexResults (
123- long tick , List <UUID > emEntities , boolean disaggregated ) throws InterruptedException {
124- sendExtMsg (new RequestEmFlexResults (tick , emEntities , disaggregated ));
100+ public Map <UUID , List <FlexOptions >> requestEmFlexResults (
101+ long tick , List <UUID > entities , boolean disaggregated ) throws InterruptedException {
102+ // create requests
103+ Map <UUID , FlexOptionRequest > requests = new HashMap <>();
104+ entities .forEach (
105+ emEntity -> requests .put (emEntity , new FlexOptionRequest (emEntity , disaggregated )));
106+
107+ sendExtMsg (new ProvideEmData (tick , requests , Collections .emptyMap (), Collections .emptyMap ()));
125108 return receiveWithType (FlexOptionsResponse .class ).receiverToFlexOptions ();
126109 }
127110
0 commit comments