/** @Override hook */ protected void subscribeDefault() { for (CapacityBundle bundle : capacityBundles) { PowerType powerType = bundle.getPowerType(); if (getTariffMarket().getDefaultTariff(powerType) != null) { log.info( bundle.getName() + ": Subscribing " + bundle.getPopulation() + " customers to default " + powerType + " tariff"); subscribe( getTariffMarket().getDefaultTariff(powerType), bundle, bundle.getPopulation(), false); } else { log.info( bundle.getName() + ": No default tariff for power type " + powerType + "; trying generic type"); PowerType genericType = powerType.getGenericType(); if (getTariffMarket().getDefaultTariff(genericType) == null) { log.error( bundle.getName() + ": No default tariff for generic power type " + genericType + " either!"); } else { log.info( bundle.getName() + ": Subscribing " + bundle.getPopulation() + " customers to default " + genericType + " tariff"); subscribe( getTariffMarket().getDefaultTariff(genericType), bundle, bundle.getPopulation(), false); } } } }
// @StateChange private void subscribe(Tariff tariff, CapacityBundle bundle, int customerCount, boolean verbose) { getTariffMarket().subscribeToTariff(tariff, bundle.getCustomerInfo(), customerCount); if (verbose) { log.info( bundle.getName() + ": Subscribed " + customerCount + " customers to tariff " + tariff.getId() + " successfully"); } }
private void usePower(Timeslot timeslot) { for (CapacityBundle bundle : capacityBundles) { List<TariffSubscription> subscriptions = getTariffSubscriptionRepo().findActiveSubscriptionsForCustomer(bundle.getCustomerInfo()); double totalCapacity = 0.0; double totalUsageCharge = 0.0; for (TariffSubscription subscription : subscriptions) { double usageSign = bundle.getPowerType().isConsumption() ? +1 : -1; double currCapacity = usageSign * useCapacity(subscription, bundle); if (Config.getInstance().isUsageChargesLogging()) { double charge = subscription .getTariff() .getUsageCharge(currCapacity, subscription.getTotalUsage(), false); totalUsageCharge += charge; } subscription.usePower(currCapacity); totalCapacity += currCapacity; } log.info( bundle.getName() + ": Total " + bundle.getPowerType() + " capacity for timeslot " + timeslot.getSerialNumber() + " = " + totalCapacity); logUsageCharges( bundle.getName() + ": Total " + bundle.getPowerType() + " usage charge for timeslot " + timeslot.getSerialNumber() + " = " + totalUsageCharge); } }