EMlab-generation Documentation  1.0
Documentation of the EMLab-Generation model.
ReceiveLongTermContractPowerRevenuesRole.java
1 /*******************************************************************************
2  * Copyright 2012 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  ******************************************************************************/
16 package emlab.gen.role.market;
17 
18 import org.springframework.beans.factory.annotation.Autowired;
19 import org.springframework.transaction.annotation.Transactional;
20 
21 import agentspring.role.Role;
22 import agentspring.role.RoleComponent;
32 import emlab.gen.role.AbstractEnergyProducerRole;
33 
43 @RoleComponent
44 public class ReceiveLongTermContractPowerRevenuesRole extends AbstractEnergyProducerRole implements Role<EnergyProducer> {
45 
46  @Autowired
47  Reps reps;
48 
49  @Override
50  @Transactional
51  public void act(EnergyProducer producer) {
52 
53  logger.info("Process electricity revenues");
54 
55  // Receive revenues for all long term contracts
56  for (Segment segment : reps.genericRepository.findAll(Segment.class)) {
57  for (LongTermContract longTermContract : reps.contractRepository.findLongTermContractsForEnergyProducerForSegmentActiveAtTime(
58  producer, segment, getCurrentTick())) {
59 
60  // Update the price with pass through factors.
61  double basePrice = longTermContract.getCapacity() * longTermContract.getPricePerUnit() * segment.getLengthInHours();
62  double co2PassThrough = longTermContract.getCo2PassThroughFactor();
63  double co2PriceStart = longTermContract.getCo2PriceStart();
64  double currentCo2Price = findLastKnownCO2Price(getCurrentTick());
65  double fuelPassThrough = longTermContract.getFuelPassThroughFactor();
66  double fuelPriceStart = longTermContract.getFuelPriceStart();
67  double currentFuelPrice = 0d;
68  Substance mainFuel = longTermContract.getMainFuel();
69  if (mainFuel != null) {
70  currentFuelPrice = findLastKnownPriceForSubstance(mainFuel, getCurrentTick());
71  }
72 
73  // prevent dividing by 0
74  if (fuelPriceStart == 0) {
75  fuelPriceStart = 1e-8;
76  }
77  if (co2PriceStart == 0) {
78  co2PriceStart = 1e-8;
79  }
80 
81  double updatedPrice = basePrice * (1 + fuelPassThrough * (currentFuelPrice / fuelPriceStart - 1))
82  * (1 + co2PassThrough * (currentCo2Price / co2PriceStart - 1));
83 
84  reps.nonTransactionalCreateRepository.createCashFlow(longTermContract.getTo(), longTermContract.getFrom(), updatedPrice,
85  CashFlow.ELECTRICITY_LONGTERM, getCurrentTick(), null);
86 
87  long hours = 0;
88  for (Segment s : longTermContract.getLongTermContractType().getSegments()) {
89  hours += s.getLengthInHours();
90  }
91 
92  double pricePerMWh = updatedPrice / (longTermContract.getCapacity() * hours);
93  logger.info("Revenue from long term contract @ {} euro/MWh", pricePerMWh);
94  }
95  }
96 
97  // Receive revenues for all spot trade
98 
99  // for (PowerPlantDispatchPlan plan : reps.powerPlantDispatchPlanRepository
100  // .findAllAcceptedPowerPlantDispatchPlansForEnergyProducerForTime(producer, getCurrentTick())) {
101  // logger.info("Found dispatch plan: {}", plan);
102  // if (plan.getAcceptedAmount() > 0) {
103  // double price = 0d;
104  // for (ClearingPoint point : reps.clearingPointRepositoryOld.findClearingPointsForSegmentAndTime(plan.getSegment(),
105  // getCurrentTick())) {
106  // SegmentClearingPoint cp = (SegmentClearingPoint) point;
107  // if (cp.getSegment().equals(plan.getSegment())) {
108  // price = cp.getPrice();
109  // }
110  // }
111  // logger.info("Revenue from spot market @ {} euro/MWh", price);
112  // reps.nonTransactionalCreateRepository.createCashFlow(plan.getBiddingMarket(), plan.getBidder(), plan.getAcceptedAmount()
113  // * plan.getSegment().getLengthInHours() * price, CashFlow.ELECTRICITY_SPOT, getCurrentTick(), plan.getPowerPlant());
114  // }
115  // }
116 
117  }
118 
119 }