private int getTimeIndex (DateTime dateTime) { // Used for testing if (simulationBaseTime == null) { simulationBaseTime = timeslotRepo.currentTimeslot().getStartTime(); } long diff = dateTime.getMillis() - simulationBaseTime.getMillis(); return (int) (diff / (1000 * 3600)); }
private void broadcastWeatherReports () { WeatherReport report = null; try { report = weatherReportRepo.currentWeatherReport(); } catch (PowerTacException e) { log.error("Weather Service reports Weather Report Repo empty"); } if (report == null) { // In the event of an error return a default log.error("null weather-report for : " + timeslotRepo.currentSerialNumber() +" " + timeslotRepo.currentTimeslot()); brokerProxyService.broadcastMessage(new WeatherReport(timeslotRepo.currentSerialNumber(), 0.0, 0.0, 0.0, 0.0)); } else { brokerProxyService.broadcastMessage(report); } }
private TimeslotUpdate makeTimeslotUpdate () { List<Timeslot> enabled = timeslotRepo.enabledTimeslots(); TimeslotUpdate msg = new TimeslotUpdate(timeService.getCurrentTime(), enabled.get(0).getSerialNumber(), enabled.get(enabled.size() - 1).getSerialNumber()); return msg; }
Timeslot currentTimeslot = timeslotRepo.findBySerialNumber(expectedIndex); if (currentTimeslot == null) { return null; Timeslot next = timeslotRepo.currentTimeslot(); if (next.getSerialNumber() > expectedIndex) {
private int getTimeslotIndex () { return timeslotRepo.currentSerialNumber(); }
Timeslot current = timeslotRepo.currentTimeslot(); log.info("activate: timeslot " + current.getSerialNumber()); for (Timeslot timeslot : timeslotRepo.enabledTimeslots()) { for (Timeslot timeslot : timeslotRepo.enabledTimeslots()) { double neededKWh = 0.0; int index = (timeslot.getSerialNumber()) % 24; for (Timeslot timeslot : timeslotRepo.enabledTimeslots()) { int index = (timeslot.getSerialNumber()) % usageRecordLength; neededKWh = collectUsage(index);
private double computeForecastCapacity (int future) int now = timeslotRepo.currentSerialNumber(); int timeToFuture = future - now; Weather weather = null; forecastCapacity = adjustCapacityForPeriodicSkew(forecastCapacity, timeslotRepo.getDateTimeForIndex(future), false); forecastCapacity =
private double computeProfileUsageChargePerSub (CapacityProfile profile, TariffSubscription subscription, CapacityOriginator capacityOriginator) { int timeslot = getTimeslotRepo().currentSerialNumber(); double totalCharge = 0.0; for (int i = 0; i < CapacityProfile.NUM_TIMESLOTS; ++i) { double totalTimeslotUsage = profile.getCapacity(i); double timeslotCharge = 0.0; double subTimeslotUsage = capacityOriginator.adjustCapacityForSubscription(timeslot, totalTimeslotUsage, subscription); timeslotCharge += subscription.getTariff().getUsageCharge(getTimeslotRepo().getTimeForIndex(timeslot), subTimeslotUsage, 0.0); // TODO: why cumulative usage is 0? totalCharge += timeslotCharge; timeslot += 1; } return totalCharge; }
Timeslot oldTs = timeslotRepo.findBySerialNumber(oldSerial); log.info("Deactivated timeslot " + oldSerial + ", start " + oldTs.getStartInstant().toString()); competition.getDeactivateTimeslotsAhead() - 1 + competition.getTimeslotsOpen()); Timeslot newTs = timeslotRepo.findBySerialNumber(newSerial); if (newTs == null) { log.info("newTS null in activateNextTimeslot"); long start = (current.getStartInstant().getMillis() + (newSerial - current.getSerialNumber()) * timeslotMillis); newTs = timeslotRepo.makeTimeslot(new Instant(start));
CustomerRecord (CustomerInfo customer, int population) { super(); this.customer = customer; this.subscribedPopulation = population; base = timeslotRepo.findBySerialNumber(0).getStartInstant(); }
DateTime now = timeslotRepo.getDateTimeForIndex(timeslot); int day = now.getDayOfWeek(); // 1=Monday, 7=Sunday int hour = now.getHourOfDay(); // 0-23
@Override public CapacityProfile getCurrentForecastPerSub (TariffSubscription sub) { int timeslot = timeslotRepo.currentSerialNumber(); return getForecastPerSubStartingAt(timeslot, sub); }
public void init (BrokerProxy proxy, int seedId, ContextService service) { log.info("init(" + seedId + ") " + getUsername()); timeslotsOpen = Competition.currentCompetition().getTimeslotsOpen(); this.brokerProxyService = proxy; //this.service = service; this.timeslotRepo = (TimeslotRepo)service.getBean("timeslotRepo"); this.weatherReportRepo = (WeatherReportRepo)service.getBean("weatherReportRepo"); this.weatherForecastRepo = (WeatherForecastRepo)service.getBean("weatherForecastRepo"); RandomSeedRepo randomSeedRepo = (RandomSeedRepo)service.getBean("randomSeedRepo"); // set up the random generator this.tsSeed = randomSeedRepo.getRandomSeed(MisoBuyer.class.getName(), seedId, "ts"); // compute offsets for daily and weekly seasonal data int ts = timeslotRepo.currentSerialNumber(); timeslotOffset = ts; DateTime start = timeslotRepo.getDateTimeForIndex(ts); dailyOffset = start.getHourOfDay(); weeklyOffset = (start.getDayOfWeek() - 1) * 24 + dailyOffset; timeseries = new ComposedTS(); timeseries.initialize(ts); }
@Override public void postEconomicControl (EconomicControlEvent event) { int tsIndex = event.getTimeslotIndex(); int current = timeslotRepo.currentTimeslot().getSerialNumber(); if (tsIndex < current) { log.warn("attempt to save old economic control for ts " + tsIndex + " during timeslot " + current); return; } List<EconomicControlEvent> tsList = pendingEconomicControls.get(tsIndex); if (null == tsList) { tsList = new ArrayList<EconomicControlEvent>(); pendingEconomicControls.put(tsIndex, tsList); } tsList.add(event); }
private void broadcastWeatherForecasts () { WeatherForecast forecast = null; try { forecast = weatherForecastRepo.currentWeatherForecast(); } catch (PowerTacException e) { log.error("Weather Service reports Weather Forecast Repo emtpy"); } if (forecast == null) { log.error("null weather-forecast for : " + timeslotRepo.currentSerialNumber() +" " + timeslotRepo.currentTimeslot()); // In the event of an error return a default List<WeatherForecastPrediction> currentPredictions = new ArrayList<WeatherForecastPrediction>(); for (int j = 1; j <= getForecastHorizon(); j++) { currentPredictions.add( new WeatherForecastPrediction(j, 0.0, 0.0, 0.0, 0.0)); } brokerProxyService.broadcastMessage(new WeatherForecast( timeslotRepo.currentSerialNumber(), currentPredictions)); } else { brokerProxyService.broadcastMessage(forecast); } }
@Override public CapacityProfile getCurrentForecast () { int timeslot = timeslotRepo.currentSerialNumber(); return getForecastForTimeslot(timeslot); }
enabledTimeslots = timeslotRepo.enabledTimeslots(); enabledTimeslots = new ArrayList<Timeslot>(timeslotRepo.enabledTimeslots());
@Override public void step () { for (EvCustomer customer : evCustomers) { customer.step(service.getTimeslotRepo().currentTimeslot()); } }
@Override public void step () { int serial = service.getTimeslotRepo().currentSerialNumber(); Timeslot ts = service.getTimeslotRepo().currentTimeslot(); // TODO - this code assumes that games start at midnight. Bad assumption. int day = (int) (serial / VillageConstants.HOURS_OF_DAY); int hour = ts.getStartTime().getHourOfDay(); Instant now = ts.getStartInstant(); weatherCheck(day, hour, now); checkCurtailment(serial, day, hour); consumePower(); // for (Household house: getHouses()) // house.test(); if (hour == 23) { for (String type: numberOfHouses.keySet()) { if (!(type.equals("NS"))) { log.info("Rescheduling " + type); rescheduleNextDay(type); } } } }
@Override public CapacityProfile getForecastForNextTimeslot () { int timeslot = timeslotRepo.currentSerialNumber(); return getForecastForTimeslot(timeslot + 1); }