Skip to content

Commit

Permalink
adapt to changes in simonaApi - first part
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfeismann committed Dec 3, 2024
1 parent eb62225 commit 7998586
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ final case class EvModelWrapper(
def id: String = original.getId

lazy val pRatedAc: Power = Kilowatts(
original.getSRatedAC.to(KILOWATT).getValue.doubleValue
original.getPRatedAC.to(KILOWATT).getValue.doubleValue
)
lazy val pRatedDc: Power = Kilowatts(
original.getSRatedDC.to(KILOWATT).getValue.doubleValue
original.getPRatedDC.to(KILOWATT).getValue.doubleValue
)
lazy val eStorage: Energy = KilowattHours(
original.getEStorage.to(KILOWATTHOUR).getValue.doubleValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

package edu.ie3.simona.service.ev

import edu.ie3.simona.api.data.ev.ExtEvData
import edu.ie3.simona.api.data.ev.ExtEvDataConnection
import edu.ie3.simona.api.data.ev.model.EvModel
import edu.ie3.simona.api.data.ev.ontology._
import edu.ie3.simona.api.data.ontology.DataMessageFromExt
Expand Down Expand Up @@ -46,7 +46,7 @@ object ExtEvDataService {
)

final case class ExtEvStateData(
extEvData: ExtEvData,
extEvData: ExtEvDataConnection,
uuidToActorRef: Map[UUID, ActorRef] = Map.empty[UUID, ActorRef],
extEvMessage: Option[EvDataMessageFromExt] = None,
freeLots: ReceiveDataMap[UUID, Int] = ReceiveDataMap.empty,
Expand All @@ -55,7 +55,7 @@ object ExtEvDataService {
) extends ServiceBaseStateData

final case class InitExtEvData(
extEvData: ExtEvData
extEvData: ExtEvDataConnection
) extends InitializeServiceStateData

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ import edu.ie3.simona.agent.EnvironmentRefs
import edu.ie3.simona.agent.grid.GridAgent
import edu.ie3.simona.agent.grid.GridAgentMessages.CreateGridAgent
import edu.ie3.simona.api.ExtSimAdapter
import edu.ie3.simona.api.data.ExtData
import edu.ie3.simona.api.data.ev.{ExtEvData, ExtEvSimulation}
import edu.ie3.simona.api.data.ev.ExtEvDataConnection
import edu.ie3.simona.api.simulation.ExtSimAdapterData
import edu.ie3.simona.config.{ArgsParser, RefSystemParser, SimonaConfig}
import edu.ie3.simona.event.listener.{ResultEventListener, RuntimeEventListener}
Expand Down Expand Up @@ -220,16 +219,16 @@ class SimonaStandaloneSetup(

// setup data services that belong to this external simulation
val (extData, extDataInit): (
Iterable[ExtData],
Iterable[ExtEvDataConnection],
Iterable[(Class[_ <: SimonaService[_]], ClassicRef)],
) =
extLink.getExtDataSimulations.asScala.zipWithIndex.map {
case (_: ExtEvSimulation, dIndex) =>
extLink.getExtSimulation.getDataConnections.asScala.zipWithIndex.map {
case (_: ExtEvDataConnection, dIndex) =>
val extEvDataService = context.toClassic.simonaActorOf(
ExtEvDataService.props(scheduler.toClassic),
s"$index-$dIndex",
)
val extEvData = new ExtEvData(extEvDataService, extSimAdapter)
val extEvData = new ExtEvDataConnection()

extEvDataService ! SimonaService.Create(
InitExtEvData(extEvData),
Expand All @@ -243,9 +242,8 @@ class SimonaStandaloneSetup(
(extEvData, (classOf[ExtEvDataService], extEvDataService))
}.unzip

extLink.getExtSimulation.setup(
extSimAdapterData,
extData.toList.asJava,
extLink.setup(
extSimAdapterData
)

// starting external simulation
Expand Down
38 changes: 19 additions & 19 deletions src/test/java/edu/ie3/simona/test/common/model/MockEvModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@
public class MockEvModel implements EvModel {
private final UUID uuid;
private final String id;
private final ComparableQuantity<Power> sRatedAC;
private final ComparableQuantity<Power> sRatedDC;
private final ComparableQuantity<Power> pRatedAC;
private final ComparableQuantity<Power> pRatedDC;
private final ComparableQuantity<Energy> eStorage;
private final ComparableQuantity<Energy> storedEnergy;
private final Long departureTick;

public MockEvModel(
UUID uuid,
String id,
ComparableQuantity<Power> sRatedAC,
ComparableQuantity<Power> sRatedDC,
ComparableQuantity<Power> pRatedAC,
ComparableQuantity<Power> pRatedDC,
ComparableQuantity<Energy> eStorage,
ComparableQuantity<Energy> storedEnergy,
Long departureTick) {
this.uuid = uuid;
this.id = id;
this.sRatedAC = sRatedAC;
this.sRatedDC = sRatedDC;
this.pRatedAC = pRatedAC;
this.pRatedDC = pRatedDC;
this.eStorage = eStorage;
this.storedEnergy = storedEnergy;
this.departureTick = departureTick;
Expand All @@ -44,14 +44,14 @@ public MockEvModel(
public MockEvModel(
UUID uuid,
String id,
ComparableQuantity<Power> sRatedAC,
ComparableQuantity<Power> sRatedDC,
ComparableQuantity<Power> pRatedAC,
ComparableQuantity<Power> pRatedDC,
ComparableQuantity<Energy> eStorage,
Long departureTick) {
this.uuid = uuid;
this.id = id;
this.sRatedAC = sRatedAC;
this.sRatedDC = sRatedDC;
this.pRatedAC = pRatedAC;
this.pRatedDC = pRatedDC;
this.eStorage = eStorage;
this.storedEnergy = Quantities.getQuantity(0d, PowerSystemUnits.KILOWATTHOUR);
this.departureTick = departureTick;
Expand All @@ -68,13 +68,13 @@ public String getId() {
}

@Override
public ComparableQuantity<Power> getSRatedAC() {
return sRatedAC;
public ComparableQuantity<Power> getPRatedAC() {
return pRatedAC;
}

@Override
public ComparableQuantity<Power> getSRatedDC() {
return sRatedDC;
public ComparableQuantity<Power> getPRatedDC() {
return pRatedDC;
}

@Override
Expand All @@ -94,11 +94,11 @@ public Long getDepartureTick() {

@Override
public MockEvModel copyWith(ComparableQuantity<Energy> newStoredEnergy) {
return new MockEvModel(uuid, id, sRatedAC, sRatedDC, eStorage, newStoredEnergy, departureTick);
return new MockEvModel(uuid, id, pRatedAC, pRatedDC, eStorage, newStoredEnergy, departureTick);
}

public MockEvModel copyWithDeparture(Long departureTick) {
return new MockEvModel(uuid, id, sRatedAC, sRatedDC, eStorage, storedEnergy, departureTick);
return new MockEvModel(uuid, id, pRatedAC, pRatedDC, eStorage, storedEnergy, departureTick);
}

@Override
Expand All @@ -108,15 +108,15 @@ public boolean equals(Object o) {
MockEvModel that = (MockEvModel) o;
return uuid.equals(that.uuid)
&& id.equals(that.id)
&& sRatedAC.equals(that.sRatedAC)
&& sRatedDC.equals(that.sRatedDC)
&& pRatedAC.equals(that.pRatedAC)
&& pRatedDC.equals(that.pRatedDC)
&& eStorage.equals(that.eStorage)
&& storedEnergy.equals(that.storedEnergy)
&& departureTick.equals(that.departureTick);
}

@Override
public int hashCode() {
return Objects.hash(uuid, id, sRatedAC, sRatedDC, eStorage, storedEnergy, departureTick);
return Objects.hash(uuid, id, pRatedAC, pRatedDC, eStorage, storedEnergy, departureTick);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1363,9 +1363,9 @@ class EvcsAgentModelCalculationSpec
resultListener.expectMsgPF() { case FlexOptionsResultEvent(flexResult) =>
flexResult.getInputModel shouldBe evcsInputModelQv.getUuid
flexResult.getTime shouldBe 900.toDateTime
flexResult.getpRef should beEquivalentTo(ev900.unwrap().getSRatedAC)
flexResult.getpMin should beEquivalentTo(ev900.unwrap().getSRatedAC)
flexResult.getpMax should beEquivalentTo(ev900.unwrap().getSRatedAC)
flexResult.getpRef should beEquivalentTo(ev900.unwrap().getPRatedAC)
flexResult.getpMin should beEquivalentTo(ev900.unwrap().getPRatedAC)
flexResult.getpMax should beEquivalentTo(ev900.unwrap().getPRatedAC)
}

emAgent.send(evcsAgent, IssueNoControl(900))
Expand All @@ -1377,7 +1377,7 @@ class EvcsAgentModelCalculationSpec
Kilowatts(
ev900
.unwrap()
.getSRatedAC
.getPRatedAC
.to(PowerSystemUnits.KILOWATT)
.getValue
.doubleValue
Expand Down Expand Up @@ -1431,7 +1431,7 @@ class EvcsAgentModelCalculationSpec
case ParticipantResultEvent(result: EvResult)
if result.getTime.equals(900.toDateTime) =>
result.getInputModel shouldBe ev900.uuid
result.getP should beEquivalentTo(ev900.unwrap().getSRatedAC)
result.getP should beEquivalentTo(ev900.unwrap().getPRatedAC)
result.getQ should beEquivalentTo(0d.asMegaVar)
result.getSoc should beEquivalentTo(0d.asPercent)
case ParticipantResultEvent(result: EvResult)
Expand All @@ -1446,7 +1446,7 @@ class EvcsAgentModelCalculationSpec
case ParticipantResultEvent(result: EvcsResult) =>
result.getInputModel shouldBe evcsInputModelQv.getUuid
result.getTime shouldBe 900.toDateTime
result.getP should beEquivalentTo(ev900.unwrap().getSRatedAC)
result.getP should beEquivalentTo(ev900.unwrap().getPRatedAC)
result.getQ should beEquivalentTo(0d.asMegaVar)
}

Expand Down Expand Up @@ -1480,9 +1480,9 @@ class EvcsAgentModelCalculationSpec
resultListener.expectMsgPF() { case FlexOptionsResultEvent(flexResult) =>
flexResult.getInputModel shouldBe evcsInputModelQv.getUuid
flexResult.getTime shouldBe 4500.toDateTime
flexResult.getpRef should beEquivalentTo(ev4500.unwrap().getSRatedAC)
flexResult.getpMin should beEquivalentTo(ev4500.unwrap().getSRatedAC)
flexResult.getpMax should beEquivalentTo(ev4500.unwrap().getSRatedAC)
flexResult.getpRef should beEquivalentTo(ev4500.unwrap().getPRatedAC)
flexResult.getpMin should beEquivalentTo(ev4500.unwrap().getPRatedAC)
flexResult.getpMax should beEquivalentTo(ev4500.unwrap().getPRatedAC)
}

emAgent.send(evcsAgent, IssueNoControl(4500))
Expand Down Expand Up @@ -1530,9 +1530,9 @@ class EvcsAgentModelCalculationSpec
resultListener.expectMsgPF() { case FlexOptionsResultEvent(flexResult) =>
flexResult.getInputModel shouldBe evcsInputModelQv.getUuid
flexResult.getTime shouldBe 9736.toDateTime
flexResult.getpRef should beEquivalentTo(ev4500.unwrap().getSRatedAC)
flexResult.getpRef should beEquivalentTo(ev4500.unwrap().getPRatedAC)
flexResult.getpMin should beEquivalentTo(0d.asKiloWatt)
flexResult.getpMax should beEquivalentTo(ev4500.unwrap().getSRatedAC)
flexResult.getpMax should beEquivalentTo(ev4500.unwrap().getPRatedAC)
}

emAgent.send(evcsAgent, IssuePowerControl(9736, Kilowatts(10.0)))
Expand Down Expand Up @@ -1595,7 +1595,7 @@ class EvcsAgentModelCalculationSpec
emAgent.send(evcsAgent, FlexActivation(11700))

val combinedChargingPower =
ev11700.unwrap().getSRatedAC.add(ev4500.unwrap().getSRatedAC)
ev11700.unwrap().getPRatedAC.add(ev4500.unwrap().getPRatedAC)
val combinedChargingPowerSq = Kilowatts(
combinedChargingPower.to(PowerSystemUnits.KILOWATT).getValue.doubleValue
)
Expand All @@ -1620,7 +1620,7 @@ class EvcsAgentModelCalculationSpec
flexResult.getTime shouldBe 11700.toDateTime
flexResult.getpRef should beEquivalentTo(combinedChargingPower)
flexResult.getpMin should beEquivalentTo(
ev4500.unwrap().getSRatedAC.multiply(-1)
ev4500.unwrap().getPRatedAC.multiply(-1)
)
flexResult.getpMax should beEquivalentTo(combinedChargingPower)
}
Expand Down Expand Up @@ -1772,7 +1772,7 @@ class EvcsAgentModelCalculationSpec
flexResult.getpMin should beEquivalentTo(
ev4500
.unwrap()
.getSRatedAC
.getPRatedAC
.multiply(
-1
)
Expand Down Expand Up @@ -1965,9 +1965,9 @@ class EvcsAgentModelCalculationSpec
resultListener.expectMsgPF() { case FlexOptionsResultEvent(flexResult) =>
flexResult.getInputModel shouldBe evcsInputModelQv.getUuid
flexResult.getTime shouldBe 36000.toDateTime
flexResult.getpRef should beEquivalentTo(ev4500.unwrap().getSRatedAC)
flexResult.getpRef should beEquivalentTo(ev4500.unwrap().getPRatedAC)
flexResult.getpMin should beEquivalentTo(0.asKiloWatt)
flexResult.getpMax should beEquivalentTo(ev4500.unwrap().getSRatedAC)
flexResult.getpMax should beEquivalentTo(ev4500.unwrap().getPRatedAC)
}

emAgent.send(evcsAgent, IssuePowerControl(36000, Kilowatts(4.0)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
package edu.ie3.simona.service.ev

import com.typesafe.config.ConfigFactory
import edu.ie3.simona.api.data.ev.ExtEvData
import edu.ie3.simona.api.data.ev.ExtEvDataConnection
import edu.ie3.simona.api.data.ev.model.EvModel
import edu.ie3.simona.api.data.ev.ontology._
import edu.ie3.simona.api.data.ontology.ScheduleDataServiceMessage
Expand Down Expand Up @@ -61,13 +61,14 @@ class ExtEvDataServiceSpec
private val evcs2UUID =
UUID.fromString("104acdaa-5dc5-4197-aed2-2fddb3c4f237")

val extEvData = new ExtEvDataConnection()

"An uninitialized ev movement service" must {
"send correct completion message after initialisation" in {
val scheduler = TestProbe("scheduler")
val extSimAdapter = TestProbe("extSimAdapter")

val evService = TestActorRef(new ExtEvDataService(scheduler.ref))
val extEvData = new ExtEvData(evService, extSimAdapter.ref)

val key =
ScheduleLock.singleKey(TSpawner, scheduler.ref.toTyped, INIT_SIM_TICK)
Expand All @@ -90,7 +91,6 @@ class ExtEvDataServiceSpec
val extSimAdapter = TestProbe("extSimAdapter")

val evService = TestActorRef(new ExtEvDataService(scheduler.ref))
val extEvData = new ExtEvData(evService, extSimAdapter.ref)

val evcs1 = TestProbe("evcs1")

Expand Down Expand Up @@ -124,7 +124,6 @@ class ExtEvDataServiceSpec
val extSimAdapter = TestProbe("extSimAdapter")

val evService = TestActorRef(new ExtEvDataService(scheduler.ref))
val extEvData = new ExtEvData(evService, extSimAdapter.ref)

val key =
ScheduleLock.singleKey(TSpawner, scheduler.ref.toTyped, INIT_SIM_TICK)
Expand Down Expand Up @@ -171,7 +170,6 @@ class ExtEvDataServiceSpec
val extSimAdapter = TestProbe("extSimAdapter")

val evService = TestActorRef(new ExtEvDataService(scheduler.ref))
val extEvData = new ExtEvData(evService, extSimAdapter.ref)

val key =
ScheduleLock.singleKey(TSpawner, scheduler.ref.toTyped, INIT_SIM_TICK)
Expand Down Expand Up @@ -204,7 +202,6 @@ class ExtEvDataServiceSpec
val extSimAdapter = TestProbe("extSimAdapter")

val evService = TestActorRef(new ExtEvDataService(scheduler.ref))
val extEvData = new ExtEvData(evService, extSimAdapter.ref)

val key =
ScheduleLock.singleKey(TSpawner, scheduler.ref.toTyped, INIT_SIM_TICK)
Expand Down Expand Up @@ -305,7 +302,6 @@ class ExtEvDataServiceSpec
val extSimAdapter = TestProbe("extSimAdapter")

val evService = TestActorRef(new ExtEvDataService(scheduler.ref))
val extEvData = new ExtEvData(evService, extSimAdapter.ref)

val key =
ScheduleLock.singleKey(TSpawner, scheduler.ref.toTyped, INIT_SIM_TICK)
Expand Down Expand Up @@ -380,7 +376,6 @@ class ExtEvDataServiceSpec
val extSimAdapter = TestProbe("extSimAdapter")

val evService = TestActorRef(new ExtEvDataService(scheduler.ref))
val extEvData = new ExtEvData(evService, extSimAdapter.ref)

val key =
ScheduleLock.singleKey(TSpawner, scheduler.ref.toTyped, INIT_SIM_TICK)
Expand Down Expand Up @@ -423,7 +418,6 @@ class ExtEvDataServiceSpec
val extSimAdapter = TestProbe("extSimAdapter")

val evService = TestActorRef(new ExtEvDataService(scheduler.ref))
val extEvData = new ExtEvData(evService, extSimAdapter.ref)

val key =
ScheduleLock.singleKey(TSpawner, scheduler.ref.toTyped, INIT_SIM_TICK)
Expand Down Expand Up @@ -527,7 +521,6 @@ class ExtEvDataServiceSpec
val extSimAdapter = TestProbe("extSimAdapter")

val evService = TestActorRef(new ExtEvDataService(scheduler.ref))
val extEvData = new ExtEvData(evService, extSimAdapter.ref)

val key =
ScheduleLock.singleKey(TSpawner, scheduler.ref.toTyped, INIT_SIM_TICK)
Expand Down Expand Up @@ -574,7 +567,6 @@ class ExtEvDataServiceSpec
val extSimAdapter = TestProbe("extSimAdapter")

val evService = TestActorRef(new ExtEvDataService(scheduler.ref))
val extEvData = new ExtEvData(evService, extSimAdapter.ref)

val key =
ScheduleLock.singleKey(TSpawner, scheduler.ref.toTyped, INIT_SIM_TICK)
Expand Down Expand Up @@ -652,7 +644,6 @@ class ExtEvDataServiceSpec
val extSimAdapter = TestProbe("extSimAdapter")

val evService = TestActorRef(new ExtEvDataService(scheduler.ref))
val extEvData = new ExtEvData(evService, extSimAdapter.ref)

val key =
ScheduleLock.singleKey(TSpawner, scheduler.ref.toTyped, INIT_SIM_TICK)
Expand Down

0 comments on commit 7998586

Please sign in to comment.