Search in sources :

Example 1 with Range

use of ucar.ma2.Range in project metron by apache.

the class WindowProcessorTest method testRepeatWithWeekdayExclusion.

@Test
public void testRepeatWithWeekdayExclusion() throws ParseException {
    Window w = WindowProcessor.process("30 minute window every 24 hours from 7 days ago excluding weekdays");
    Date now = new Date();
    // avoid DST impacts if near Midnight
    now.setHours(6);
    List<Range<Long>> intervals = w.toIntervals(now.getTime());
    assertEquals(2, intervals.size());
}
Also used : Range(org.apache.commons.lang3.Range) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 2 with Range

use of ucar.ma2.Range in project metron by apache.

the class WindowProcessorTest method testSparse.

@Test
public void testSparse() {
    for (String text : new String[] { "30 minute window every 1 hour from 2 hours ago to 30 minutes ago", "30 minute window every 1 hour starting from 2 hours ago to 30 minutes ago", "30 minute window every 1 hour starting from 2 hours ago until 30 minutes ago", "30 minute window for every 1 hour starting from 2 hours ago until 30 minutes ago" }) {
        Window w = WindowProcessor.process(text);
        /*
    A window size of 30 minutes
    Starting 2 hour ago and continuing until 30 minutes ago
    window 1: ( now - 2 hour, now - 2 hour + 30 minutes)
    window 2: (now - 1 hour, now - 1 hour + 30 minutes)
     */
        Date now = new Date();
        List<Range<Long>> intervals = w.toIntervals(now.getTime());
        assertEquals(2, intervals.size());
        assertEquals(now.getTime() - TimeUnit.HOURS.toMillis(2), intervals.get(0).getMinimum());
        assertEquals(now.getTime() - TimeUnit.HOURS.toMillis(2) + TimeUnit.MINUTES.toMillis(30), intervals.get(0).getMaximum());
        assertEquals(now.getTime() - TimeUnit.HOURS.toMillis(1), intervals.get(1).getMinimum());
        assertEquals(now.getTime() - TimeUnit.HOURS.toMillis(1) + TimeUnit.MINUTES.toMillis(30), intervals.get(1).getMaximum());
    }
}
Also used : Range(org.apache.commons.lang3.Range) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 3 with Range

use of ucar.ma2.Range in project metron by apache.

the class WindowProcessorTest method testBaseCase.

@Test
public void testBaseCase() {
    for (String text : new String[] { "1 hour", "1 hour(s)", "1 hours" }) {
        Window w = WindowProcessor.process(text);
        Date now = new Date();
        List<Range<Long>> intervals = w.toIntervals(now.getTime());
        assertEquals(1, intervals.size());
        assertEquals(now.getTime(), (long) intervals.get(0).getMaximum());
        assertEquals(now.getTime() - TimeUnit.HOURS.toMillis(1), (long) intervals.get(0).getMinimum());
    }
}
Also used : Range(org.apache.commons.lang3.Range) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 4 with Range

use of ucar.ma2.Range in project metron by apache.

the class WindowProcessorTest method testRepeatTilNow.

@Test
public void testRepeatTilNow() {
    Window w = WindowProcessor.process("30 minute window every 1 hour from 3 hours ago");
    /*
    A window size of 30 minutes
    Starting 3 hours ago and continuing until now
    window 1: ( now - 3 hour, now - 3 hour + 30 minutes)
    window 2: ( now - 2 hour, now - 2 hour + 30 minutes)
    window 3: ( now - 1 hour, now - 1 hour + 30 minutes)
     */
    Date now = new Date();
    List<Range<Long>> intervals = w.toIntervals(now.getTime());
    assertEquals(3, intervals.size());
    assertTimeEquals(now.getTime() - TimeUnit.HOURS.toMillis(3), intervals.get(0).getMinimum());
    assertTimeEquals(now.getTime() - TimeUnit.HOURS.toMillis(3) + TimeUnit.MINUTES.toMillis(30), intervals.get(0).getMaximum());
    assertTimeEquals(now.getTime() - TimeUnit.HOURS.toMillis(2), intervals.get(1).getMinimum());
    assertTimeEquals(now.getTime() - TimeUnit.HOURS.toMillis(2) + TimeUnit.MINUTES.toMillis(30), intervals.get(1).getMaximum());
    assertTimeEquals(now.getTime() - TimeUnit.HOURS.toMillis(1), intervals.get(2).getMinimum());
    assertTimeEquals(now.getTime() - TimeUnit.HOURS.toMillis(1) + TimeUnit.MINUTES.toMillis(30), intervals.get(2).getMaximum());
}
Also used : Range(org.apache.commons.lang3.Range) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 5 with Range

use of ucar.ma2.Range in project metron by apache.

the class WindowProcessorTest method testRepeatWithInclusionExclusion.

@Test
public void testRepeatWithInclusionExclusion() throws ParseException {
    Window w = WindowProcessor.process("30 minute window every 24 hours from 7 days ago including holidays:us excluding weekends");
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm");
    Date now = sdf.parse("2017/12/26 12:00");
    List<Range<Long>> intervals = w.toIntervals(now.getTime());
    assertEquals(1, intervals.size());
}
Also used : Range(org.apache.commons.lang3.Range) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Aggregations

Range (org.apache.commons.lang3.Range)11 Date (java.util.Date)9 Test (org.junit.jupiter.api.Test)9 Variable (ucar.nc2.Variable)9 Array (ucar.ma2.Array)8 Range (ucar.ma2.Range)8 InvalidRangeException (ucar.ma2.InvalidRangeException)7 Attribute (ucar.nc2.Attribute)6 Point (java.awt.Point)5 HashMap (java.util.HashMap)5 IOException (java.io.IOException)4 ArrayFloat (ucar.ma2.ArrayFloat)4 ArrayShort (ucar.ma2.ArrayShort)4 DataType (ucar.ma2.DataType)4 NetcdfDataset (ucar.nc2.dataset.NetcdfDataset)4 Range (controlP5.Range)3 Slider (controlP5.Slider)3 Toggle (controlP5.Toggle)3 Rectangle (java.awt.Rectangle)3 BandedSampleModel (java.awt.image.BandedSampleModel)3