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)); }
@Override public String initialize (Competition competition, List<String> completedInits) { super.init(); aheadDays = new CopyOnWriteArrayList<DateTime>(); serverProps.configureMe(this); weatherReqInterval = Math.min(24, weatherReqInterval); simulationBaseTime = competition.getSimulationBaseTime().toDateTime(); if (weatherData != null && (weatherData.endsWith(".xml") || weatherData.endsWith(".state"))) { log.info("read from file in blocking mode"); blocking = true; } if (!blocking) { DateTime dateTime = timeslotRepo.currentTimeslot().getStartTime(); // Get the first 3 days of weather, blocking! for (int i = 0; i < daysAhead; i++) { WeatherRequester weatherRequester = new WeatherRequester(dateTime); weatherRequester.run(); dateTime = dateTime.plusDays(1); } } return "WeatherService"; }
@Override public void activate (Instant time, int phaseNumber) { long msec = time.getMillis(); if (msec % (getWeatherReqInterval() * TimeService.HOUR) != 0) { log.info("WeatherService reports not time to grab weather data."); } else { log.info("Timeslot " + timeslotRepo.currentTimeslot().getId() + " WeatherService reports time to make request for weather data"); DateTime dateTime = timeslotRepo.currentTimeslot().getStartTime(); if (blocking) { WeatherRequester wr = new WeatherRequester(dateTime); wr.run(); } else { aheadDays.add(dateTime.plusDays(daysAhead)); while (aheadDays.size() > 0) { WeatherRequester wr = new WeatherRequester(aheadDays.remove(0)); new Thread(wr).start(); } } } broadcastWeatherReports(); broadcastWeatherForecasts(); }
/** * Runs the model forward one step */ public void step (Timeslot timeslot) { int day = timeslot.getStartTime().getDayOfWeek(); int hour = timeslot.getStartTime().getHourOfDay(); // find the current active subscription TariffSubscription sub = null; List<TariffSubscription> subs = service.getTariffSubscriptionRepo(). findActiveSubscriptionsForCustomer(customerInfo); if (null == subs || subs.size() == 0) { log.error("No subscriptions found for " + name); return; } else { sub = subs.get(0); } driving = false; // Always do handleRegulations first, setRegulation last handleRegulation(day, hour, sub); makeDayPlanning(hour, day); doActivities(day, hour); double[] loads = getLoads(day, hour); consumePower(loads, sub); setRegulation(loads[2], loads[3], sub); }
@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 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 / OfficeComplexConstants.HOURS_OF_DAY); int hour = ts.getStartTime().getHourOfDay(); Instant now = ts.getStartInstant(); weatherCheck(day, hour, now); // checkRevokedSubscriptions(); checkCurtailment(serial, day, hour); consumePower(); // for (Office office: getOffices()) // office.test(); if (hour == 23) { for (String type: numberOfOffices.keySet()) { if (!(type.equals("NS"))) { log.info("Rescheduling " + type); rescheduleNextDay(type); } } } }