Search in sources :

Example 16 with Schedule

use of de.avanux.smartapplianceenabler.schedule.Schedule in project SmartApplianceEnabler by camueller.

the class ApplianceTest method createRuntimeRequest_MaxRunningTime.

@Test
public void createRuntimeRequest_MaxRunningTime() {
    LocalDateTime now = toToday(0, 30, 0);
    Schedule schedule = new Schedule(3600, 7200, new TimeOfDay(1, 0, 0), new TimeOfDay(9, 0, 0));
    Interval interval = schedule.getTimeframe().getIntervals(now).get(0).getInterval();
    schedule.getTimeframe().setSchedule(schedule);
    RuntimeRequest runtimeRequest = this.appliance.createRuntimeRequest(interval, schedule.getMinRunningTime(), schedule.getMaxRunningTime(), now);
    Assert.assertEquals(1800, (int) runtimeRequest.getEarliestStart());
    Assert.assertEquals(30600, (int) runtimeRequest.getLatestEnd());
    Assert.assertEquals(3600, (int) runtimeRequest.getMinRunningTime());
    Assert.assertEquals(7200, (int) runtimeRequest.getMaxRunningTime());
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) TimeOfDay(de.avanux.smartapplianceenabler.schedule.TimeOfDay) Schedule(de.avanux.smartapplianceenabler.schedule.Schedule) Interval(org.joda.time.Interval) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval) Test(org.junit.Test)

Example 17 with Schedule

use of de.avanux.smartapplianceenabler.schedule.Schedule in project SmartApplianceEnabler by camueller.

the class ApplianceTest method createRuntimeRequest_MaxRunningTimeExceedsLatestEnd.

@Test
public void createRuntimeRequest_MaxRunningTimeExceedsLatestEnd() {
    LocalDateTime now = toToday(8, 0, 0);
    Schedule schedule = new Schedule(3600, 7200, new TimeOfDay(1, 0, 0), new TimeOfDay(9, 0, 0));
    Interval interval = schedule.getTimeframe().getIntervals(now).get(0).getInterval();
    schedule.getTimeframe().setSchedule(schedule);
    RuntimeRequest runtimeRequest = this.appliance.createRuntimeRequest(interval, schedule.getMinRunningTime(), schedule.getMaxRunningTime(), now);
    Assert.assertEquals(0, (int) runtimeRequest.getEarliestStart());
    Assert.assertEquals(3600, (int) runtimeRequest.getLatestEnd());
    Assert.assertEquals(3600, (int) runtimeRequest.getMinRunningTime());
    Assert.assertEquals(3600, (int) runtimeRequest.getMaxRunningTime());
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) TimeOfDay(de.avanux.smartapplianceenabler.schedule.TimeOfDay) Schedule(de.avanux.smartapplianceenabler.schedule.Schedule) Interval(org.joda.time.Interval) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval) Test(org.junit.Test)

Example 18 with Schedule

use of de.avanux.smartapplianceenabler.schedule.Schedule in project SmartApplianceEnabler by camueller.

the class RunningTimeMonitorTest method getRemainingMinRunningTimeOfCurrentTimeFrame.

@Test
public void getRemainingMinRunningTimeOfCurrentTimeFrame() {
    Schedule schedule = new Schedule(7200, null, new TimeOfDay(11, 0, 0), new TimeOfDay(17, 0, 0));
    runningTimeMonitor.setSchedules(Collections.singletonList(schedule));
    Assert.assertNull("Timeframe not yet started should return NULL", runningTimeMonitor.getRemainingMinRunningTimeOfCurrentTimeFrame(toToday(10, 0, 0)));
    runningTimeMonitor.updateActiveTimeframeInterval(toToday(11, 00, 0));
    Assert.assertEquals("With timeframe started but device switched off max running time should be returned", 7200, runningTimeMonitor.getRemainingMinRunningTimeOfCurrentTimeFrame(toToday(11, 30, 0)).intValue());
    runningTimeMonitor.setRunning(true, toToday(12, 10, 0));
    Assert.assertEquals("With timeframe started and device switched on max running time should be reduced by 5 minutes", 6900, runningTimeMonitor.getRemainingMinRunningTimeOfCurrentTimeFrame(toToday(12, 15, 0)).intValue());
    runningTimeMonitor.setRunning(false, toToday(13, 10, 0));
    Assert.assertEquals("With timeframe started and device switched off running time of one hour remains", 3600, runningTimeMonitor.getRemainingMinRunningTimeOfCurrentTimeFrame(toToday(13, 15, 0)).intValue());
    runningTimeMonitor.setRunning(true, toToday(16, 10, 0));
    Assert.assertEquals("Running time may exceed LatestEnd", 3300, runningTimeMonitor.getRemainingMinRunningTimeOfCurrentTimeFrame(toToday(16, 15, 0)).intValue());
    Assert.assertEquals("Running time left right before LatestEnd", 601, runningTimeMonitor.getRemainingMinRunningTimeOfCurrentTimeFrame(toToday(16, 59, 59)).intValue());
    runningTimeMonitor.setRunning(false, toToday(17, 0, 0));
    runningTimeMonitor.updateActiveTimeframeInterval(toToday(17, 0, 1));
    Assert.assertNull("With timeframe expired running time should return NULL", runningTimeMonitor.getRemainingMinRunningTimeOfCurrentTimeFrame(toToday(17, 0, 0)));
}
Also used : TimeOfDay(de.avanux.smartapplianceenabler.schedule.TimeOfDay) Schedule(de.avanux.smartapplianceenabler.schedule.Schedule) Test(org.junit.Test)

Example 19 with Schedule

use of de.avanux.smartapplianceenabler.schedule.Schedule in project SmartApplianceEnabler by camueller.

the class RunningTimeMonitor method activateTimeframeInterval.

public void activateTimeframeInterval(LocalDateTime now, Integer runtime) {
    activeTimeframeInterval = null;
    Schedule schedule = new Schedule(runtime, null, new TimeOfDay(now), new TimeOfDay(now));
    Interval interval = new Interval(now.toDateTime(), now.plusSeconds(runtime).toDateTime());
    Timeframe timeframe = schedule.getTimeframe();
    activateTimeframeInterval(now, new TimeframeInterval(timeframe, interval));
}
Also used : TimeOfDay(de.avanux.smartapplianceenabler.schedule.TimeOfDay) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval) Timeframe(de.avanux.smartapplianceenabler.schedule.Timeframe) Schedule(de.avanux.smartapplianceenabler.schedule.Schedule) Interval(org.joda.time.Interval) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval)

Example 20 with Schedule

use of de.avanux.smartapplianceenabler.schedule.Schedule in project SmartApplianceEnabler by camueller.

the class ScheduleTest method getCurrentOrNextTimeframeInterval_timeFrameNotValidForDow.

@Test
public void getCurrentOrNextTimeframeInterval_timeFrameNotValidForDow() {
    LocalDateTime now = toToday(9, 0, 0);
    List<Schedule> schedules = new ArrayList<Schedule>();
    // Timeframe only valid yesterday
    schedules.add(new Schedule(true, 7200, null, new TimeOfDay(10, 0, 0), new TimeOfDay(14, 0, 0), Collections.singletonList(now.minusDays(1).get(DateTimeFieldType.dayOfWeek()))));
    // Timeframe only valid tomorrow
    schedules.add(new Schedule(true, 7200, null, new TimeOfDay(15, 0, 0), new TimeOfDay(18, 0, 0), Collections.singletonList(now.plusDays(1).get(DateTimeFieldType.dayOfWeek()))));
    Assert.assertEquals(new Interval(toDay(1, 15, 0, 0).toDateTime(), toDay(1, 18, 0, 0).toDateTime()), Schedule.getCurrentOrNextTimeframeInterval(now, schedules, false, false).getInterval());
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) TimeOfDay(de.avanux.smartapplianceenabler.schedule.TimeOfDay) Schedule(de.avanux.smartapplianceenabler.schedule.Schedule) ArrayList(java.util.ArrayList) Interval(org.joda.time.Interval) Test(org.junit.Test)

Aggregations

Schedule (de.avanux.smartapplianceenabler.schedule.Schedule)21 TimeOfDay (de.avanux.smartapplianceenabler.schedule.TimeOfDay)17 Test (org.junit.Test)17 LocalDateTime (org.joda.time.LocalDateTime)12 TimeframeInterval (de.avanux.smartapplianceenabler.schedule.TimeframeInterval)9 Interval (org.joda.time.Interval)8 ArrayList (java.util.ArrayList)4 Timeframe (de.avanux.smartapplianceenabler.schedule.Timeframe)1