Search in sources :

Example 6 with Range

use of controlP5.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 7 with Range

use of controlP5.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)

Example 8 with Range

use of controlP5.Range in project metron by apache.

the class WindowProcessorTest method testRepeatWithWeekendExclusion.

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

Example 9 with Range

use of controlP5.Range in project metron by apache.

the class WindowLookbackTest method test.

public State test(String windowSelector, Date now, Optional<Map<String, Object>> config, Assertions... assertions) {
    List<Range<Long>> windowIntervals = WindowProcessor.process(windowSelector).toIntervals(now.getTime());
    String stellarStatement = "PROFILE_WINDOW('" + windowSelector + "', now" + (config.isPresent() ? ", config" : "") + ")";
    Map<String, Object> variables = new HashMap<>();
    variables.put("now", now.getTime());
    if (config.isPresent()) {
        variables.put("config", config.get());
    }
    StellarProcessor stellar = new StellarProcessor();
    List<ProfilePeriod> periods = (List<ProfilePeriod>) stellar.parse(stellarStatement, new DefaultVariableResolver(k -> variables.get(k), k -> variables.containsKey(k)), resolver, context);
    State state = new State(windowIntervals, periods);
    for (Assertions assertion : assertions) {
        assertTrue(assertion.test(state), assertion.name());
    }
    return state;
}
Also used : StellarProcessor(org.apache.metron.stellar.common.StellarProcessor) ProfilePeriod(org.apache.metron.profiler.ProfilePeriod) Range(org.apache.commons.lang3.Range) Assertions(org.junit.jupiter.api.Assertions) DefaultVariableResolver(org.apache.metron.stellar.dsl.DefaultVariableResolver)

Example 10 with Range

use of controlP5.Range in project sirix by sirixdb.

the class AbstractSunburstGUI method style.

/**
 * Style menu.
 */
protected void style() {
    final Group ctrl = mControlP5.addGroup("menu", 15, 25, 35);
    ctrl.setColorLabel(mParent.color(255));
    ctrl.setColorBackground(mParent.color(100));
    ctrl.close();
    mParent.colorMode(PConstants.RGB, 255, 255, 255);
    final int backgroundColor = 0x99ffffff;
    int i = 0;
    for (final Slider slider : mSliders) {
        slider.setGroup(ctrl);
        slider.setId(i);
        final Label label = slider.getCaptionLabel();
        label.toUpperCase(true);
        label.setColor(mParent.color(0));
        label.setColorBackground(backgroundColor);
        final ControllerStyle style = label.getStyle();
        style.padding(4, 0, 1, 3);
        style.marginTop = -4;
        style.marginLeft = 0;
        style.marginRight = -14;
        slider.plugTo(mControl);
        i++;
    }
    i = 0;
    for (final Range range : mRanges) {
        range.setGroup(ctrl);
        range.setId(i);
        final Label label = range.getCaptionLabel();
        label.toUpperCase(true);
        label.setColor(mParent.color(0));
        label.setColorBackground(backgroundColor);
        final ControllerStyle style = label.getStyle();
        style.padding(4, 0, 1, 3);
        style.marginTop = -4;
        range.plugTo(mControl);
        i++;
    }
    i = 0;
    for (final Toggle toggle : mToggles) {
        toggle.setGroup(ctrl);
        toggle.setId(i);
        final Label label = toggle.getCaptionLabel();
        label.setColor(mParent.color(0));
        label.setColorBackground(backgroundColor);
        final ControllerStyle style = label.getStyle();
        style.padding(4, 3, 1, 3);
        style.marginTop = -19;
        style.marginLeft = 18;
        style.marginRight = 5;
        toggle.plugTo(mControl);
        i++;
    }
    mParent.colorMode(PConstants.HSB, 360, 100, 100);
    mParent.textLeading(14);
    mParent.textAlign(PConstants.LEFT, PConstants.TOP);
    mParent.cursor(PConstants.CROSS);
}
Also used : Group(controlP5.Group) ControllerStyle(controlP5.ControllerStyle) Slider(controlP5.Slider) Toggle(controlP5.Toggle) Label(controlP5.Label) Range(controlP5.Range)

Aggregations

Range (org.apache.commons.lang3.Range)11 Date (java.util.Date)9 Test (org.junit.jupiter.api.Test)9 Range (controlP5.Range)3 Slider (controlP5.Slider)3 Toggle (controlP5.Toggle)3 SimpleDateFormat (java.text.SimpleDateFormat)2 ControllerStyle (controlP5.ControllerStyle)1 Group (controlP5.Group)1 Label (controlP5.Label)1 List (java.util.List)1 ItemStack (net.minecraft.item.ItemStack)1 ProfilePeriod (org.apache.metron.profiler.ProfilePeriod)1 StellarProcessor (org.apache.metron.stellar.common.StellarProcessor)1 DefaultVariableResolver (org.apache.metron.stellar.dsl.DefaultVariableResolver)1 Test (org.junit.Test)1 Assertions (org.junit.jupiter.api.Assertions)1 Cut (org.sbolstandard.core2.Cut)1 GenericLocation (org.sbolstandard.core2.GenericLocation)1 Location (org.sbolstandard.core2.Location)1