/** * Processes a tariff transaction, updating the broker's cash position * and the consumption, production data in the distribution report. */ public void processTransaction(TariffTransaction tx, ArrayList<Object> messages) { //log.info("processing tariff tx " + tx.toString()); updateCash(tx.getBroker(), tx.getCharge()); // update the distribution report if (TariffTransaction.Type.CONSUME == tx.getTxType()) totalConsumption -= tx.getKWh(); else if (TariffTransaction.Type.PRODUCE == tx.getTxType()) totalProduction += tx.getKWh(); }
/** * Creates a tariff transaction that is not a regulation transaction. */ public TariffTransaction makeTariffTransaction(Broker broker, TariffTransaction.Type txType, TariffSpecification spec, CustomerInfo customer, int customerCount, double kWh, double charge) { return new TariffTransaction (broker, getTimeslotIndex(), txType, spec, customer, customerCount, kWh, charge, false); }
/** * Returns a mapping of brokers to total supply and demand among subscribed * customers. */ @Override public Map<Broker, Map<Type, Double>> getCurrentSupplyDemandByBroker () { HashMap<Broker, Map<Type, Double>> result = new HashMap<Broker, Map<Type, Double>>(); for (BrokerTransaction btx : pendingTransactions) { if (btx instanceof TariffTransaction) { TariffTransaction ttx = (TariffTransaction)btx; Broker broker = ttx.getBroker(); Map<Type, Double> record = result.get(broker); if (null == record) { record = new HashMap<Type, Double>(); result.put(broker, record); record.put(Type.CONSUME, 0.0); record.put(Type.PRODUCE, 0.0); } if (ttx.getTxType() == Type.CONSUME) record.put(Type.CONSUME, record.get(Type.CONSUME) + ttx.getKWh()); else if (ttx.getTxType() == Type.PRODUCE) record.put(Type.PRODUCE, record.get(Type.PRODUCE) + ttx.getKWh()); } } return result; }
TariffTransaction.Type txType = ttx.getTxType(); CustomerInfo customer = ttx.getCustomerInfo(); HashMap<CustomerInfo, CustomerRecord> customerMap = customerSubscriptions.get(ttx.getTariffSpec()); CustomerRecord record = customerMap.get(customer); record = new CustomerRecord(customer, ttx.getCustomerCount()); customerMap.put(customer, record); record.signup(ttx.getCustomerCount()); record.withdraw(ttx.getCustomerCount()); if (ttx.getCustomerCount() != record.subscribedPopulation) { log.info("production by subset " + ttx.getCustomerCount() + " of subscribed population " + record.subscribedPopulation); record.produceConsume(ttx.getKWh(), ttx.getPostedTime()); if (ttx.getCustomerCount() != record.subscribedPopulation) { log.info("consumption by subset " + ttx.getCustomerCount() + " of subscribed population " + record.subscribedPopulation); record.produceConsume(ttx.getKWh(), ttx.getPostedTime()); TariffTransaction.Type.CONSUME == txType)) { ensureBootProfiles(); record = bootProfiles.get(ttx.getCustomerInfo()); record.produceConsume(ttx.getKWh(), ttx.getPostedTime());
@Override public synchronized TariffTransaction addRegulationTransaction (Tariff tariff, CustomerInfo customer, int customerCount, double kWh, double charge) { TariffTransaction.Type txType = TariffTransaction.Type.CONSUME; if (kWh > 0.0) txType = TariffTransaction.Type.PRODUCE; TariffTransaction ttx = txFactory.makeTariffTransaction(tariff.getBroker(), txType, tariffRepo.findSpecificationById(tariff.getSpecId()), customer, customerCount, kWh, charge, true); if (null == ttx.getTariffSpec()) log.error("Null tariff spec in addTariffTx()"); pendingTransactions.add(ttx); return ttx; }
/** * Returns the net load for the given broker in the current timeslot. * Note that this only works AFTER the customer models have run, and * BEFORE the day's transactions have been processed. The value will be * negative if the broker's customers are consuming more than they produce * in the current timeslot. */ @Override public synchronized double getCurrentNetLoad (Broker broker) { double netLoad = 0.0; for (BrokerTransaction btx : pendingTransactions) { if (btx instanceof TariffTransaction) { TariffTransaction ttx = (TariffTransaction)btx; if (ttx.getBroker().getUsername().equals(broker.getUsername())) { if (ttx.getTxType() == TariffTransaction.Type.CONSUME || ttx.getTxType() == TariffTransaction.Type.PRODUCE) { netLoad += ttx.getKWh(); } } } } log.info("net load for " + broker.getUsername() + ": " + netLoad); return netLoad; }
@Override public synchronized TariffTransaction addTariffTransaction(TariffTransaction.Type txType, Tariff tariff, CustomerInfo customer, int customerCount, double kWh, double charge) { TariffTransaction ttx = txFactory.makeTariffTransaction(tariff.getBroker(), txType, tariffRepo.findSpecificationById(tariff.getSpecId()), customer, customerCount, kWh, charge); if (null == ttx.getTariffSpec()) log.error("Null tariff spec in addTariffTx()"); pendingTransactions.add(ttx); return ttx; }
/** * Creates a tariff transaction that could be a regulation transaction, * depending on the value of the isRegulation parameter. */ public TariffTransaction makeTariffTransaction(Broker broker, TariffTransaction.Type txType, TariffSpecification spec, CustomerInfo customer, int customerCount, double kWh, double charge, boolean isRegulation) { return new TariffTransaction (broker, getTimeslotIndex(), txType, spec, customer, customerCount, kWh, charge, isRegulation); }