16 package emlab.gen.repository;
18 import java.util.ArrayList;
19 import java.util.List;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23 import org.springframework.beans.factory.annotation.Autowired;
24 import org.springframework.data.neo4j.support.Neo4jTemplate;
25 import org.springframework.stereotype.Repository;
26 import org.springframework.transaction.annotation.Transactional;
28 import com.tinkerpop.blueprints.pgm.Vertex;
29 import com.tinkerpop.pipes.Pipe;
30 import com.tinkerpop.pipes.util.Pipeline;
48 static Logger logger = LoggerFactory.getLogger(ContractRepository.class);
51 Neo4jTemplate
template;
53 public Iterable<LongTermContract> findLongTermContractsForEnergyProducerActiveAtTime(
EnergyProducer energyProducer,
long time) {
56 Pipe<Vertex, Vertex> pipeline =
new Pipeline<Vertex, Vertex>(contractPipe);
58 List<LongTermContract> list =
new ArrayList<LongTermContract>();
60 for (
Contract contract : findAllByPipe(energyProducer, pipeline)) {
61 if (contract.getStart() <= time && contract.getFinish() >= time) {
68 public Iterable<LongTermContract> findLongTermContractsForEnergyProducerForSegmentActiveAtTime(
EnergyProducer energyProducer,
73 Pipe<Vertex, Vertex> pipeline =
new Pipeline<Vertex, Vertex>(contractPipe);
75 List<LongTermContract> list =
new ArrayList<LongTermContract>();
76 for (
Contract contract : findAllByPipe(energyProducer, pipeline)) {
80 if (ltc.getStart() <= time && ltc.getFinish() >= time) {
81 if (ltc.getLongTermContractType().getSegments().contains(segment)) {
89 public Iterable<Contract> findLongTermContractsForEnergyConsumerActiveAtTime(
EnergyConsumer energyConsumer,
long time) {
92 Pipe<Vertex, Vertex> pipeline =
new Pipeline<Vertex, Vertex>(contractPipe);
94 List<Contract> list =
new ArrayList<Contract>();
96 for (
Contract contract : findAllByPipe(energyConsumer, pipeline)) {
97 if (contract.getStart() <= time && contract.getFinish() >= time) {
104 public Iterable<LongTermContract> findLongTermContractsForEnergyConsumerForSegmentActiveAtTime(
EnergyConsumer consumer,
107 List<LongTermContract> list =
new ArrayList<LongTermContract>();
108 for (
Contract contract : findLongTermContractsForEnergyConsumerActiveAtTime(consumer, time)) {
112 if (ltc.getStart() <= time && ltc.getFinish() >= time) {
113 if (ltc.getLongTermContractType().getSegments().contains(segment)) {
126 if (ltc.getStart() <= time && ltc.getFinish() >= time) {
127 if (ltc.getUnderlyingPowerPlant().equals(plant)) {
135 public Iterable<LongTermContract> findLongTermContractsForEnergyConsumerForSegmentForZoneActiveAtTime(
EnergyConsumer consumer,
137 List<LongTermContract> list =
new ArrayList<LongTermContract>();
138 for (
LongTermContract ltc : findLongTermContractsForEnergyConsumerForSegmentActiveAtTime(consumer, segment, currentTick)) {
139 if (ltc.getZone().equals(zone)) {
155 double co2PassThroughFactor,
double fuelPriceStart,
double co2PriceStart) {
158 contract.setUnderlyingPowerPlant(plant);
159 contract.setFrom(seller);
160 contract.setTo(buyer);
161 contract.setZone(zone);
162 contract.setPricePerUnit(price);
163 contract.setCapacity(capacity);
164 contract.setLongTermContractType(longTermContractType);
165 contract.setStart(time);
166 contract.setFinish(time + duration.getDuration() - 1);
167 contract.setDuration(duration);
168 contract.setSigned(signed);
169 contract.setMainFuel(mainFuel);
170 contract.setFuelPassThroughFactor(fuelPassThroughFactor);
171 contract.setCo2PassThroughFactor(co2PassThroughFactor);
172 contract.setFuelPriceStart(fuelPriceStart);
173 contract.setCo2PriceStart(co2PriceStart);
180 Substance mainFuel,
double fuelPassThroughFactor,
double co2PassThroughFactor,
double fuelPriceStart,
double co2PriceStart) {
183 offer.setSeller(seller);
184 offer.setUnderlyingPowerPlant(plant);
186 offer.setPrice(price);
187 offer.setCapacity(capacity);
188 offer.setLongTermContractType(longTermContractType);
189 offer.setStart(time);
190 offer.setDuration(duration);
191 offer.setMainFuel(mainFuel);
192 offer.setFuelPassThroughFactor(fuelPassThroughFactor);
193 offer.setCo2PassThroughFactor(co2PassThroughFactor);
194 offer.setFuelPriceStart(fuelPriceStart);
195 offer.setCo2PriceStart(co2PriceStart);
200 public void removeOffer(LongTermContractOffer offer) {
205 public void removeAllOffers() {
206 for (LongTermContractOffer offer :
template.repositoryFor(LongTermContractOffer.class).findAll()) {
212 public void reassignLongTermContractToNewPowerPlant(LongTermContract longTermContract, PowerPlant plant) {
213 longTermContract.setUnderlyingPowerPlant(plant);
LongTermContract submitLongTermContractForElectricity(PowerPlant plant, DecarbonizationAgent seller, DecarbonizationAgent buyer, Zone zone, double price, double capacity, LongTermContractType longTermContractType, long time, LongTermContractDuration duration, boolean signed, Substance mainFuel, double fuelPassThroughFactor, double co2PassThroughFactor, double fuelPriceStart, double co2PriceStart)