Search in sources :

Example 11 with Schedule

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

the class ScheduleTest method findTimeframeIntervals_multipleSchedules_differentDaysOfWeek.

@Test
public void findTimeframeIntervals_multipleSchedules_differentDaysOfWeek() {
    List<Schedule> schedules = new ArrayList<Schedule>();
    addSchedule(schedules, 3600, 10, 0, 12, 0, dowList(3));
    addSchedule(schedules, 3600, 12, 0, 14, 0, dowList(2, 4));
    addSchedule(schedules, 3600, 14, 0, 16, 0, dowList(1, 5));
    LocalDateTime now = toDayOfWeek(1, 9, 0);
    List<TimeframeInterval> timeframeIntervals = Schedule.findTimeframeIntervals(now, null, schedules, false, true);
    Assert.assertEquals(5, timeframeIntervals.size());
    Assert.assertEquals(toIntervalByDow(now, 1, 14, 0, 1, 16, 0), timeframeIntervals.get(0).getInterval());
    Assert.assertEquals(toIntervalByDow(now, 2, 12, 0, 2, 14, 0), timeframeIntervals.get(1).getInterval());
    Assert.assertEquals(toIntervalByDow(now, 3, 10, 0, 3, 12, 0), timeframeIntervals.get(2).getInterval());
    Assert.assertEquals(toIntervalByDow(now, 4, 12, 0, 4, 14, 0), timeframeIntervals.get(3).getInterval());
    Assert.assertEquals(toIntervalByDow(now, 5, 14, 0, 5, 16, 0), timeframeIntervals.get(4).getInterval());
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) Schedule(de.avanux.smartapplianceenabler.schedule.Schedule) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 12 with Schedule

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

the class TestBuilder method withSchedule.

public TestBuilder withSchedule(int startHour, int startMinute, int endHour, int endMinute, int minRunningTime, Integer maxRunningTime) {
    List<Schedule> schedules = getAppliance().getSchedules();
    if (schedules == null) {
        schedules = new ArrayList<>();
        getAppliance().setSchedules(schedules);
    }
    schedules.add(new Schedule(minRunningTime, maxRunningTime, new TimeOfDay(startHour, startMinute, 0), new TimeOfDay(endHour, endMinute, 0)));
    return this;
}
Also used : TimeOfDay(de.avanux.smartapplianceenabler.schedule.TimeOfDay) Schedule(de.avanux.smartapplianceenabler.schedule.Schedule)

Example 13 with Schedule

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

the class ApplianceTest method getRuntimeRequest_TimeFrameAlreadyStartedAndActive_NotSufficient.

@Test
public void getRuntimeRequest_TimeFrameAlreadyStartedAndActive_NotSufficient() {
    int nowSeconds = 10;
    LocalDateTime now = toToday(11, 0, nowSeconds);
    Schedule schedule = new Schedule(3600, null, new TimeOfDay(8, 0, 0), new TimeOfDay(12, 0, 0));
    TimeframeInterval activeTimeframeInterval = schedule.getTimeframe().getIntervals(now).get(0);
    List<RuntimeRequest> runtimeRequests = this.appliance.getRuntimeRequests(now, Collections.singletonList(schedule), activeTimeframeInterval, true, 3600 - nowSeconds, null);
    Assert.assertEquals(3, runtimeRequests.size());
    Assert.assertEquals(new RuntimeRequest(0, 3600 - nowSeconds, 3600 - nowSeconds, null), runtimeRequests.get(0));
    Assert.assertEquals(new RuntimeRequest(75600 - nowSeconds, 90000 - nowSeconds, 3600, null), runtimeRequests.get(1));
    Assert.assertEquals(new RuntimeRequest(162000 - nowSeconds, 176400 - nowSeconds, 3600, null), runtimeRequests.get(2));
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) TimeOfDay(de.avanux.smartapplianceenabler.schedule.TimeOfDay) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval) Schedule(de.avanux.smartapplianceenabler.schedule.Schedule) Test(org.junit.Test)

Example 14 with Schedule

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

the class ApplianceTest method createRuntimeRequest_TimeFrameOverMidnight_AfterMidnight.

@Test
public void createRuntimeRequest_TimeFrameOverMidnight_AfterMidnight() {
    LocalDateTime now = toToday(0, 30, 0);
    Schedule schedule = new Schedule(7200, null, new TimeOfDay(20, 0, 0), new TimeOfDay(4, 0, 0));
    Interval interval = schedule.getTimeframe().getIntervals(now).get(0).getInterval();
    RuntimeRequest runtimeRequest = this.appliance.createRuntimeRequest(interval, schedule.getMinRunningTime(), null, now);
    Assert.assertEquals(0, (int) runtimeRequest.getEarliestStart());
    Assert.assertEquals(12600, (int) runtimeRequest.getLatestEnd());
    Assert.assertEquals(7200, (int) runtimeRequest.getMinRunningTime());
    Assert.assertNull(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 15 with Schedule

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

the class ApplianceTest method createRuntimeRequest.

@Test
public void createRuntimeRequest() {
    LocalDateTime now = toToday(0, 30, 0);
    Schedule schedule = new Schedule(7200, null, 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(), null, now);
    Assert.assertEquals(1800, (int) runtimeRequest.getEarliestStart());
    Assert.assertEquals(30600, (int) runtimeRequest.getLatestEnd());
    Assert.assertEquals(7200, (int) runtimeRequest.getMinRunningTime());
    Assert.assertNull(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)

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