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());
}
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());
}
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());
}
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;
}
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);
}
Aggregations