Search in sources :

Example 46 with LocalDateTime

use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.

the class ConsecutiveDaysTimeframeTest method getIntervals_AcrossWeeks_WithinInterval.

@Test
public void getIntervals_AcrossWeeks_WithinInterval() {
    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(7, 10, 0, 0);
    List<TimeframeInterval> intervals = timeRange.getIntervals(now);
    Assert.assertEquals(1, intervals.size());
    LocalDateTime start = startTimeOfDayOfWeek.toLastOccurrence(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 47 with LocalDateTime

use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.

the class ConsecutiveDaysTimeframeTest method getIntervals_AcrossWeeks_BeforeIntervalStart.

@Test
public void getIntervals_AcrossWeeks_BeforeIntervalStart() {
    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(3, 0, 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 48 with LocalDateTime

use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.

the class ConsecutiveDaysTimeframeTest method getIntervals_SameWeek_BeforeIntervalStart.

@Test
public void getIntervals_SameWeek_BeforeIntervalStart() {
    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(1, 0, 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 49 with LocalDateTime

use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.

the class SaeController method suggestRuntime.

/**
 * Suggest a runtime for immediate start.
 * @param applianceId
 * @return the suggested runtime in s; 0 if no timeframe interval was found; null if no appliance was found for the given id
 */
public Integer suggestRuntime(String applianceId) {
    logger.debug("{}: Received request to suggest runtime", applianceId);
    Appliance appliance = ApplianceManager.getInstance().findAppliance(applianceId);
    if (appliance != null) {
        LocalDateTime now = new LocalDateTime();
        List<TimeframeInterval> timeframeIntervals = Schedule.findTimeframeIntervals(now, null, appliance.getSchedules(), false, false);
        if (timeframeIntervals.size() > 0) {
            return timeframeIntervals.get(0).getTimeframe().getSchedule().getMinRunningTime();
        }
    } else {
        logger.error("{}: Appliance not found", applianceId);
        return null;
    }
    return 0;
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval)

Example 50 with LocalDateTime

use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.

the class IntegrationTest method testSwitchOnAndOff_startingCurrentDetectedDuringTimeframeInterval.

@Test
public void testSwitchOnAndOff_startingCurrentDetectedDuringTimeframeInterval() {
    String applianceId = "F-001";
    TestBuilder builder = new TestBuilder().appliance(applianceId).withMockSwitch(true).withMockMeter().withSchedule(10, 0, 18, 0, 3600, null).init();
    Appliance appliance = builder.getAppliance();
    StartingCurrentSwitch control = (StartingCurrentSwitch) appliance.getControl();
    Meter meter = appliance.getMeter();
    RunningTimeMonitor runningTimeMonitor = appliance.getRunningTimeMonitor();
    log("Check initial values");
    assertRunningTime(null, control, runningTimeMonitor, false, true, false, false, false, null, null, null);
    log("Detect starting current");
    LocalDateTime timeBeforeStartingCurrent = toToday(11, 29, 0);
    Mockito.when(meter.getAveragePower()).thenReturn(StartingCurrentSwitchDefaults.getPowerThreshold() + 1);
    control.detectStartingCurrent(timeBeforeStartingCurrent, meter);
    assertRunningTime(timeBeforeStartingCurrent, control, runningTimeMonitor, false, true, false, false, false, null, null, null);
    Assert.assertEquals(0, sempController.createDevice2EM(timeBeforeStartingCurrent).getPlanningRequest().size());
    LocalDateTime timeStartingCurrent = toToday(11, 30, 0);
    control.detectStartingCurrent(toToday(11, 30, 0), meter);
    assertRunningTime(timeStartingCurrent, control, runningTimeMonitor, false, false, false, false, true, 0, 3600, null);
    assertPlanningRequest(timeStartingCurrent, new Timeframe(applianceId, 0, 23400, 3599, 3600));
    log("Switch on");
    LocalDateTime timeSwitchOn = toToday(12, 0, 0);
    sempController.em2Device(timeSwitchOn, createEM2Device(applianceId, true));
    log("Check values after switch on");
    assertRunningTime(timeSwitchOn, control, runningTimeMonitor, true, true, true, false, true, 0, 3600, null);
    assertPlanningRequest(timeSwitchOn, new Timeframe(applianceId, 0, 21600, 3599, 3600));
    ApplianceStatus applianceStatusAfterSwitchOn = getApplianceStatus(timeSwitchOn);
    Assert.assertTrue(applianceStatusAfterSwitchOn.isOn());
    log("Switch off");
    LocalDateTime timeSwitchOff = toToday(13, 0, 0);
    sempController.em2Device(timeSwitchOff, createEM2Device(applianceId, false));
    log("Check values after switch off");
    assertRunningTime(timeSwitchOff, control, runningTimeMonitor, false, true, false, true, true, 3600, 0, null);
    Assert.assertEquals(0, sempController.createDevice2EM(timeSwitchOff).getPlanningRequest().size());
// TODO nochmal an/aus schalten
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) StartingCurrentSwitch(de.avanux.smartapplianceenabler.control.StartingCurrentSwitch) Meter(de.avanux.smartapplianceenabler.meter.Meter) ApplianceStatus(de.avanux.smartapplianceenabler.webservice.ApplianceStatus) TestBuilder(de.avanux.smartapplianceenabler.test.TestBuilder) Test(org.junit.Test)

Aggregations

LocalDateTime (org.joda.time.LocalDateTime)120 Test (org.junit.Test)73 Interval (org.joda.time.Interval)27 TimeframeInterval (de.avanux.smartapplianceenabler.schedule.TimeframeInterval)21 DateTime (org.joda.time.DateTime)18 TimeOfDay (de.avanux.smartapplianceenabler.schedule.TimeOfDay)17 Schedule (de.avanux.smartapplianceenabler.schedule.Schedule)12 LocalDate (org.joda.time.LocalDate)12 ArrayList (java.util.ArrayList)8 ConsecutiveDaysTimeframe (de.avanux.smartapplianceenabler.schedule.ConsecutiveDaysTimeframe)6 DayTimeframe (de.avanux.smartapplianceenabler.schedule.DayTimeframe)6 TimeOfDayOfWeek (de.avanux.smartapplianceenabler.schedule.TimeOfDayOfWeek)6 Date (java.util.Date)6 TestBuilder (de.avanux.smartapplianceenabler.test.TestBuilder)4 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)4 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)4 AccAccount (eu.bcvsolutions.idm.acc.entity.AccAccount)4 IdmAuthorizationPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto)4 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)4 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)4