Search in sources :

Example 16 with TimeframeInterval

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

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

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

the class ConsecutiveDaysTimeframeTest method getIntervals_SameWeek_WithinInterval.

@Test
public void getIntervals_SameWeek_WithinInterval() {
    TimeOfDayOfWeek startTimeOfDayOfWeek = new TimeOfDayOfWeek(5, 15, 0, 0);
    TimeOfDayOfWeek endTimeOfDayOfWeek = new TimeOfDayOfWeek(7, 20, 0, 0);
    ConsecutiveDaysTimeframe timeRange = new ConsecutiveDaysTimeframe(startTimeOfDayOfWeek, endTimeOfDayOfWeek);
    LocalDateTime now = toDayOfWeek(5, 18, 0, 0);
    List<TimeframeInterval> intervals = timeRange.getIntervals(now);
    Assert.assertEquals(1, intervals.size());
    LocalDateTime start = startTimeOfDayOfWeek.toNextOccurrence(now);
    assertDateTime(start, intervals.get(0).getInterval().getStart().toLocalDateTime());
    assertDateTime(endTimeOfDayOfWeek.toNextOccurrence(start), intervals.get(0).getInterval().getEnd().toLocalDateTime());
}
Also used : TimeOfDayOfWeek(de.avanux.smartapplianceenabler.schedule.TimeOfDayOfWeek) LocalDateTime(org.joda.time.LocalDateTime) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval) ConsecutiveDaysTimeframe(de.avanux.smartapplianceenabler.schedule.ConsecutiveDaysTimeframe) Test(org.junit.Test)

Example 19 with TimeframeInterval

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

the class ConsecutiveDaysTimeframeTest method getIntervals_AcrossWeeks_AfterIntervalEnd.

@Test
public void getIntervals_AcrossWeeks_AfterIntervalEnd() {
    TimeOfDayOfWeek startTimeOfDayOfWeek = new TimeOfDayOfWeek(6, 15, 0, 0);
    TimeOfDayOfWeek endTimeOfDayOfWeek = new TimeOfDayOfWeek(1, 20, 0, 0);
    ConsecutiveDaysTimeframe timeRange = new ConsecutiveDaysTimeframe(startTimeOfDayOfWeek, endTimeOfDayOfWeek);
    LocalDateTime now = toDayOfWeek(1, 21, 0, 0);
    List<TimeframeInterval> intervals = timeRange.getIntervals(now);
    Assert.assertEquals(1, intervals.size());
    LocalDateTime start = startTimeOfDayOfWeek.toNextOccurrence(now);
    assertDateTime(start, intervals.get(0).getInterval().getStart().toLocalDateTime());
    assertDateTime(endTimeOfDayOfWeek.toNextOccurrence(start), intervals.get(0).getInterval().getEnd().toLocalDateTime());
}
Also used : TimeOfDayOfWeek(de.avanux.smartapplianceenabler.schedule.TimeOfDayOfWeek) LocalDateTime(org.joda.time.LocalDateTime) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval) ConsecutiveDaysTimeframe(de.avanux.smartapplianceenabler.schedule.ConsecutiveDaysTimeframe) Test(org.junit.Test)

Example 20 with TimeframeInterval

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

the class DayTimeframeTest method getIntervals_DayOfWeekNotMatching_BeforeIntervalStart.

@Test
public void getIntervals_DayOfWeekNotMatching_BeforeIntervalStart() {
    DayTimeframe timeframe = new DayTimeframe(new TimeOfDay(10, 0, 0), new TimeOfDay(12, 0, 0), Collections.singletonList(3));
    LocalDateTime now = toDayOfWeek(1, 9, 0, 0);
    List<TimeframeInterval> intervals = timeframe.getIntervals(now);
    Assert.assertEquals(1, intervals.size());
    Assert.assertEquals(new Interval(toDayOfWeek(now, 3, 10, 0, 0).toDateTime(), toDayOfWeek(now, 3, 12, 0, 0).toDateTime()), intervals.get(0).getInterval());
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) 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)

Aggregations

TimeframeInterval (de.avanux.smartapplianceenabler.schedule.TimeframeInterval)22 Test (org.junit.Test)17 LocalDateTime (org.joda.time.LocalDateTime)16 TimeOfDay (de.avanux.smartapplianceenabler.schedule.TimeOfDay)12 Interval (org.joda.time.Interval)10 DayTimeframe (de.avanux.smartapplianceenabler.schedule.DayTimeframe)9 ConsecutiveDaysTimeframe (de.avanux.smartapplianceenabler.schedule.ConsecutiveDaysTimeframe)6 TimeOfDayOfWeek (de.avanux.smartapplianceenabler.schedule.TimeOfDayOfWeek)6 Schedule (de.avanux.smartapplianceenabler.schedule.Schedule)4 Timeframe (de.avanux.smartapplianceenabler.schedule.Timeframe)1