Search in sources :

Example 11 with TimeOfDay

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

the class DayTimeframeTest method getIntervals_AllDayOfWeek_BeforeIntervalStart.

@Test
public void getIntervals_AllDayOfWeek_BeforeIntervalStart() {
    DayTimeframe timeframe = new DayTimeframe(new TimeOfDay(10, 0, 0), new TimeOfDay(12, 0, 0));
    List<TimeframeInterval> intervals = timeframe.getIntervals(toToday(9, 0, 0));
    Assert.assertEquals(7, intervals.size());
    Assert.assertEquals(new Interval(toToday(10, 0, 0).toDateTime(), toToday(12, 0, 0).toDateTime()), intervals.get(0).getInterval());
    Assert.assertEquals(new Interval(toDay(1, 10, 0, 0).toDateTime(), toDay(1, 12, 0, 0).toDateTime()), intervals.get(1).getInterval());
    Assert.assertEquals(new Interval(toDay(2, 10, 0, 0).toDateTime(), toDay(2, 12, 0, 0).toDateTime()), intervals.get(2).getInterval());
    Assert.assertEquals(new Interval(toDay(3, 10, 0, 0).toDateTime(), toDay(3, 12, 0, 0).toDateTime()), intervals.get(3).getInterval());
    Assert.assertEquals(new Interval(toDay(4, 10, 0, 0).toDateTime(), toDay(4, 12, 0, 0).toDateTime()), intervals.get(4).getInterval());
    Assert.assertEquals(new Interval(toDay(5, 10, 0, 0).toDateTime(), toDay(5, 12, 0, 0).toDateTime()), intervals.get(5).getInterval());
    Assert.assertEquals(new Interval(toDay(6, 10, 0, 0).toDateTime(), toDay(6, 12, 0, 0).toDateTime()), intervals.get(6).getInterval());
}
Also used : TimeOfDay(de.avanux.smartapplianceenabler.schedule.TimeOfDay) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval) DayTimeframe(de.avanux.smartapplianceenabler.schedule.DayTimeframe) Interval(org.joda.time.Interval) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval) Test(org.junit.Test)

Example 12 with TimeOfDay

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

the class SempControllerTest method getPlanningRequest_intervalAlreadyActive.

@Test
public void getPlanningRequest_intervalAlreadyActive() {
    Identification identification = new Identification();
    identification.setDeviceId(DEVICE_ID);
    DeviceInfo deviceInfo = new DeviceInfo();
    deviceInfo.setIdentification(identification);
    setDeviceInfo(deviceInfo);
    Appliance appliance = new Appliance();
    appliance.setId(DEVICE_ID);
    LocalDateTime now = toToday(9, 30, 0);
    int remainingMaxRunningTime = 1800;
    Schedule schedule = new Schedule(600, null, new TimeOfDay(now.minusSeconds(1)), new TimeOfDay(now.plusSeconds(remainingMaxRunningTime)));
    de.avanux.smartapplianceenabler.schedule.Timeframe timeframe = schedule.getTimeframe();
    timeframe.setSchedule(schedule);
    RunningTimeMonitor runningTimeMonitor = mock(RunningTimeMonitor.class);
    when(runningTimeMonitor.getSchedules()).thenReturn(Collections.singletonList(schedule));
    when(runningTimeMonitor.getActiveTimeframeInterval()).thenReturn(timeframe.getIntervals(now).get(0));
    when(runningTimeMonitor.getRemainingMinRunningTimeOfCurrentTimeFrame(now)).thenReturn(schedule.getMinRunningTime());
    when(runningTimeMonitor.getRemainingMaxRunningTimeOfCurrentTimeFrame(now)).thenReturn(schedule.getMaxRunningTime());
    appliance.setRunningTimeMonitor(runningTimeMonitor);
    Appliances appliances = new Appliances();
    appliances.setAppliances(Collections.singletonList(appliance));
    ApplianceManager.getInstanceWithoutTimer().setAppliances(appliances);
    Device2EM device2EM = sempController.createDevice2EM(now);
    List<PlanningRequest> planningRequests = device2EM.getPlanningRequest();
    Assert.assertEquals(1, planningRequests.size());
    List<Timeframe> timeframes = planningRequests.get(0).getTimeframes();
    Assert.assertEquals(3, timeframes.size());
    assertTimeframe(timeframes.get(0), 0, 1800, 599, 600);
    assertTimeframe(timeframes.get(1), 86399, 88200, 599, 600);
    assertTimeframe(timeframes.get(2), 172799, 174600, 599, 600);
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) TimeOfDay(de.avanux.smartapplianceenabler.schedule.TimeOfDay) Schedule(de.avanux.smartapplianceenabler.schedule.Schedule) Test(org.junit.Test)

Example 13 with TimeOfDay

use of de.avanux.smartapplianceenabler.schedule.TimeOfDay 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 14 with TimeOfDay

use of de.avanux.smartapplianceenabler.schedule.TimeOfDay 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 15 with TimeOfDay

use of de.avanux.smartapplianceenabler.schedule.TimeOfDay 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)

Aggregations

TimeOfDay (de.avanux.smartapplianceenabler.schedule.TimeOfDay)25 Test (org.junit.Test)23 Schedule (de.avanux.smartapplianceenabler.schedule.Schedule)17 TimeframeInterval (de.avanux.smartapplianceenabler.schedule.TimeframeInterval)16 Interval (org.joda.time.Interval)15 LocalDateTime (org.joda.time.LocalDateTime)11 DayTimeframe (de.avanux.smartapplianceenabler.schedule.DayTimeframe)8 ArrayList (java.util.ArrayList)2 Timeframe (de.avanux.smartapplianceenabler.schedule.Timeframe)1