@Test public void testActivate () { TariffSubscription sub1 = tariffSubscriptionRepo.getSubscription(customer1, tariff); sub1.subscribe(100); TariffSubscription sub2 = tariffSubscriptionRepo.getSubscription(customer2, tariff); sub2.subscribe(200); EconomicControlEvent ece0 = new EconomicControlEvent(spec, 0.20, 0); EconomicControlEvent ece1 = new EconomicControlEvent(spec, 0.25, 1); capacityControl.postEconomicControl(ece0); capacityControl.postEconomicControl(ece1); capacityControl.activate(timeService.getCurrentTime(), 1); reset(mockAccounting); final HashMap<CustomerInfo, Object[]> answers = new HashMap<CustomerInfo, Object[]>(); when(mockAccounting.addTariffTransaction(any(TariffTransaction.Type.class), any(Tariff.class), any(CustomerInfo.class), anyInt(), anyDouble(), anyDouble())) .thenAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); CustomerInfo customer = (CustomerInfo)args[2]; answers.put(customer, args); return null; } }); sub1.usePower(200); sub2.usePower(300); assertEquals(2, answers.size(), "correct # of calls"); Object[] args = answers.get(customer1); assertNotNull(args, "customer1 included"); assertEquals(6, args.length, "correct arg count"); assertEquals(TariffTransaction.Type.CONSUME, (TariffTransaction.Type) args[0], "correct type"); assertEquals(tariff, (Tariff) args[1], "correct tariff"); assertEquals(-160.0, (Double) args[4], 1e-6, "correct kwh"); assertEquals(160.0 * 0.11, (Double) args[5], 1e-6, "correct charge"); args = answers.get(customer2); assertNotNull(args, "customer2 included"); assertEquals(6, args.length, "correct arg count"); assertEquals(TariffTransaction.Type.CONSUME, (TariffTransaction.Type) args[0], "correct type"); assertEquals(tariff, (Tariff) args[1], "correct tariff"); assertEquals(-240.0, (Double) args[4], 1e-6, "correct kwh"); assertEquals(240.0 * 0.11, (Double) args[5], 1e-6, "correct charge"); assertEquals(40.0 / 100.0, sub1.getRegulation(), 1e-6, "correct regulation sub1"); assertEquals(60.0 / 200.0, sub2.getRegulation(), 1e-6, "correct regulation sub1"); }
@Override public void activate (Instant time, int phaseNumber) { log.info("CapacityControlService.activate() phase {}", phaseNumber); int tsIndex = timeslotRepo.currentTimeslot().getSerialNumber(); List<EconomicControlEvent> controls = getControlsForTimeslot(tsIndex - 1); if (null != controls) { for (EconomicControlEvent event : controls) { log.warn("Expired economic control, ts=" + (tsIndex - 1) + ", broker=" + event.getBroker().getUsername()); } pendingEconomicControls.remove(tsIndex - 1); } controls = getControlsForTimeslot(tsIndex); if (null != controls) { for (EconomicControlEvent event : controls) { Tariff tariff = tariffRepo.findTariffById(event.getTariffId()); if (null == tariff) { log.warn("Cannot find tariff " + event.getTariffId() + " in EconomicControlEvent " + event.getId() + " from " + event.getBroker().getUsername()); } else { for (TariffSubscription sub : tariffSubscriptionRepo.findSubscriptionsForTariff(tariff)) { sub.postRatioControl(event.getCurtailmentRatio()); } } } } pendingEconomicControls.remove(tsIndex); }
CapacityControlService extends TimeslotPhaseProcessor implements CapacityControl, InitializationService { @Override public void activate (Instant time, int phaseNumber) { log.info("CapacityControlService.activate() phase {}", phaseNumber); int tsIndex = timeslotRepo.currentTimeslot().getSerialNumber(); List<EconomicControlEvent> controls = getControlsForTimeslot(tsIndex - 1); if (null != controls) { for (EconomicControlEvent event : controls) { log.warn("Expired economic control, ts=" + (tsIndex - 1) + ", broker=" + event.getBroker().getUsername()); } pendingEconomicControls.remove(tsIndex - 1); } controls = getControlsForTimeslot(tsIndex); if (null != controls) { for (EconomicControlEvent event : controls) { Tariff tariff = tariffRepo.findTariffById(event.getTariffId()); if (null == tariff) { log.warn("Cannot find tariff " + event.getTariffId() + " in EconomicControlEvent " + event.getId() + " from " + event.getBroker().getUsername()); } else { for (TariffSubscription sub : tariffSubscriptionRepo.findSubscriptionsForTariff(tariff)) { sub.postRatioControl(event.getCurtailmentRatio()); } } } } pendingEconomicControls.remove(tsIndex); } }
CapacityControlService extends TimeslotPhaseProcessor implements CapacityControl, InitializationService { @Override public void activate (Instant time, int phaseNumber) { log.info("CapacityControlService.activate() phase {}", phaseNumber); int tsIndex = timeslotRepo.currentTimeslot().getSerialNumber(); List<EconomicControlEvent> controls = getControlsForTimeslot(tsIndex - 1); if (null != controls) { for (EconomicControlEvent event : controls) { log.warn("Expired economic control, ts=" + (tsIndex - 1) + ", broker=" + event.getBroker().getUsername()); } pendingEconomicControls.remove(tsIndex - 1); } controls = getControlsForTimeslot(tsIndex); if (null != controls) { for (EconomicControlEvent event : controls) { Tariff tariff = tariffRepo.findTariffById(event.getTariffId()); if (null == tariff) { log.warn("Cannot find tariff " + event.getTariffId() + " in EconomicControlEvent " + event.getId() + " from " + event.getBroker().getUsername()); } else { for (TariffSubscription sub : tariffSubscriptionRepo.findSubscriptionsForTariff(tariff)) { sub.postRatioControl(event.getCurtailmentRatio()); } } } } pendingEconomicControls.remove(tsIndex); }  }
CapacityControlService extends TimeslotPhaseProcessor implements CapacityControl, InitializationService { @Override public void activate (Instant time, int phaseNumber) { log.info("CapacityControlService.activate() phase {}", phaseNumber); int tsIndex = timeslotRepo.currentTimeslot().getSerialNumber(); List<EconomicControlEvent> controls = getControlsForTimeslot(tsIndex - 1); if (null != controls) { for (EconomicControlEvent event : controls) { log.warn("Expired economic control, ts=" + (tsIndex - 1) + ", broker=" + event.getBroker().getUsername()); } pendingEconomicControls.remove(tsIndex - 1); } controls = getControlsForTimeslot(tsIndex); if (null != controls) { for (EconomicControlEvent event : controls) { Tariff tariff = tariffRepo.findTariffById(event.getTariffId()); if (null == tariff) { log.warn("Cannot find tariff " + event.getTariffId() + " in EconomicControlEvent " + event.getId() + " from " + event.getBroker().getUsername()); } else { for (TariffSubscription sub : tariffSubscriptionRepo.findSubscriptionsForTariff(tariff)) { sub.postRatioControl(event.getCurtailmentRatio()); } } } } pendingEconomicControls.remove(tsIndex); }  @Override String initialize(Competition competition, List<String> completedInits); @Override void exerciseBalancingControl(BalancingOrder order,
                                        double kwh, double payment); @Override void postEconomicControl(EconomicControlEvent event); @Override RegulationAccumulator getRegulationCapacity(BalancingOrder order); @Override void activate(Instant time, int phaseNumber); }
CapacityControlService extends TimeslotPhaseProcessor implements CapacityControl, InitializationService { @Override public void activate (Instant time, int phaseNumber) { log.info("CapacityControlService.activate() phase {}", phaseNumber); int tsIndex = timeslotRepo.currentTimeslot().getSerialNumber(); List<EconomicControlEvent> controls = getControlsForTimeslot(tsIndex - 1); if (null != controls) { for (EconomicControlEvent event : controls) { log.warn("Expired economic control, ts=" + (tsIndex - 1) + ", broker=" + event.getBroker().getUsername()); } pendingEconomicControls.remove(tsIndex - 1); } controls = getControlsForTimeslot(tsIndex); if (null != controls) { for (EconomicControlEvent event : controls) { Tariff tariff = tariffRepo.findTariffById(event.getTariffId()); if (null == tariff) { log.warn("Cannot find tariff " + event.getTariffId() + " in EconomicControlEvent " + event.getId() + " from " + event.getBroker().getUsername()); } else { for (TariffSubscription sub : tariffSubscriptionRepo.findSubscriptionsForTariff(tariff)) { sub.postRatioControl(event.getCurtailmentRatio()); } } } } pendingEconomicControls.remove(tsIndex); }  @Override String initialize(Competition competition, List<String> completedInits); @Override void exerciseBalancingControl(BalancingOrder order,
                                        double kwh, double payment); @Override void postEconomicControl(EconomicControlEvent event); @Override RegulationAccumulator getRegulationCapacity(BalancingOrder order); @Override void activate(Instant time, int phaseNumber);  }