16 package emlab.gen.util;
18 import org.neo4j.graphdb.Node;
19 import org.springframework.beans.factory.annotation.Autowired;
20 import org.springframework.data.neo4j.aspects.core.NodeBacked;
21 import org.springframework.data.neo4j.support.Neo4jTemplate;
23 import agentspring.facade.Filters;
24 import agentspring.trend.Trend;
26 import com.tinkerpop.blueprints.pgm.impls.neo4j.Neo4jVertex;
36 import emlab.gen.role.AbstractEnergyProducerRole;
40 Neo4jTemplate
template;
52 public boolean plantIsOperational(Object node,
long tick) {
53 NodeBacked entity = this.getEntity(node);
55 throw new RuntimeException(
"Vertex is not a Power plant");
56 PowerPlant plant = (PowerPlant) entity;
57 return plant.isOperational(tick);
60 public boolean plantIsExpectedToBeOperational(Object node,
long tick) {
61 NodeBacked entity = this.getEntity(node);
63 throw new RuntimeException(
"Vertex is not a Power plant");
64 PowerPlant plant = (PowerPlant) entity;
65 return plant.isExpectedToBeOperational(tick);
68 public boolean plantIsInPipeline(Object node,
long tick) {
69 NodeBacked entity = this.getEntity(node);
71 throw new RuntimeException(
"Vertex is not a Power plant");
72 PowerPlant plant = (PowerPlant) entity;
73 return plant.isInPipeline(tick);
76 public double calculateCO2Emissions(Object node,
long tick) {
77 NodeBacked entity = this.getEntity(node);
79 throw new RuntimeException(
"Vertex is not a Power plant");
80 PowerPlant plant = (PowerPlant) entity;
81 return plant.calculateCO2EmissionsAtTime(tick,
false);
84 public double getTrendValue(Object node,
long tick) {
85 NodeBacked entity = this.getEntity(node);
86 if (!(entity instanceof Trend)) {
87 throw new RuntimeException(
"Vertex is not a Trend");
89 Trend trend = (Trend) entity;
90 return trend.getValue(tick);
93 public double findLastKnownPriceOnMarket(Object node,
long tick) {
94 NodeBacked entity = this.getEntity(node);
96 throw new RuntimeException(
"Vertex is not a Market");
98 DecarbonizationMarket market = (DecarbonizationMarket) entity;
101 Double average = calculateAverageMarketPriceBasedOnClearingPoints(reps.clearingPointRepositoryOld
102 .findClearingPointsForMarketAndTime(market, tick,
false));
103 Substance substance = market.getSubstance();
105 if (average != null) {
109 average = calculateAverageMarketPriceBasedOnClearingPoints(reps.clearingPointRepositoryOld.findClearingPointsForMarketAndTime(
110 market, tick - 1,
false));
111 if (average != null) {
115 if (market.getReferencePrice() > 0) {
116 return market.getReferencePrice();
120 if (supplier.getSubstance().equals(substance)) {
121 return supplier.getPriceOfCommodity().getValue(tick);
128 public double determineProductionOfDispatchPlanInMWh(Object node,
long tick) {
129 NodeBacked entity = this.getEntity(node);
131 throw new RuntimeException(
"Vertex is not a Dispatch plan");
133 PowerPlantDispatchPlan plan = (PowerPlantDispatchPlan) entity;
135 if (tick == plan.getTime()) {
136 return plan.getSegment().getLengthInHours()
137 * (plan.getAcceptedAmount() + plan.getCapacityLongTermContract());
142 public double findLastKnownPriceOnMarketInGJ(Object node,
long tick) {
143 double price = findLastKnownPriceOnMarket(node, tick);
145 NodeBacked entity = this.getEntity(node);
147 throw new RuntimeException(
"Vertex is not a Market");
149 DecarbonizationMarket market = (DecarbonizationMarket) entity;
151 Substance substance = market.getSubstance();
153 return price / substance.getEnergyDensity();
156 private Double calculateAverageMarketPriceBasedOnClearingPoints(Iterable<ClearingPoint> clearingPoints) {
157 double priceTimesVolume = 0d;
161 priceTimesVolume += point.getPrice() * point.getVolume();
162 volume += point.getVolume();
165 return priceTimesVolume / volume;
170 private NodeBacked getEntity(Object node) {
171 if (!(node instanceof Neo4jVertex))
172 throw new RuntimeException(
"Object is not neo4j vertex");
173 Neo4jVertex vertex = (Neo4jVertex) node;
174 Node n = vertex.getRawVertex();
175 NodeBacked entity = template.createEntityFromStoredType(n);
179 public boolean ltcIsActive(Object node,
long tick) {
180 NodeBacked entity = this.getEntity(node);
182 throw new RuntimeException(
"Vertex is not a Power plant");
183 LongTermContract contract = (LongTermContract) entity;
184 if (contract.getStart() <= tick & contract.getFinish() >= tick) {
191 private class Dummy
extends AbstractEnergyProducerRole {
193 public Reps getReps() {