Commit bbf98847 authored by Luc Maisonobe's avatar Luc Maisonobe

Validated burst and fixed step selectors.

parent e362aac3
......@@ -80,8 +80,8 @@ public class BurstSelector implements DatesSelector {
this.highRateStep = highRateStep;
this.burstPeriod = burstPeriod;
this.alignmentTimeScale = alignmentTimeScale;
this.last = AbsoluteDate.PAST_INFINITY;
this.first = AbsoluteDate.PAST_INFINITY;
this.last = null;
this.first = null;
this.lastSize = 0;
}
......@@ -91,28 +91,55 @@ public class BurstSelector implements DatesSelector {
final List<AbsoluteDate> selected = new ArrayList<>();
for (AbsoluteDate next = start.durationFrom(last) > highRateStep ? start : last.shiftedBy(highRateStep);
boolean reset = first == null || start.durationFrom(first) > burstPeriod;
for (AbsoluteDate next = reset ? start : last.shiftedBy(highRateStep);
next.compareTo(end) <= 0;
next = last.shiftedBy(highRateStep)) {
if (reset) {
first = null;
lastSize = 0;
reset = false;
}
if (lastSize == maxBurstSize) {
// we have exceeded burst size, we have to wait for next burst
last = first.shiftedBy(burstPeriod - highRateStep);
// we have exceeded burst size, jump to next burst
next = first.shiftedBy(burstPeriod);
first = null;
lastSize = 0;
} else {
if (lastSize == 0) {
if (alignmentTimeScale != null) {
// align date to time scale
final double t = next.getComponents(alignmentTimeScale).getTime().getSecondsInLocalDay();
final double dt = burstPeriod * FastMath.round(t / burstPeriod) - t;
next = next.shiftedBy(dt);
if (next.compareTo(end) > 0) {
// next burst is out of current interval
break;
}
}
if (first == null && alignmentTimeScale != null) {
// align date to time scale
final double t = next.getComponents(alignmentTimeScale).getTime().getSecondsInLocalDay();
final double dt = burstPeriod * FastMath.round(t / burstPeriod) - t;
next = next.shiftedBy(dt);
if (next.compareTo(start) < 0) {
// alignment shifted date before interval
next = next.shiftedBy(burstPeriod);
}
}
if (next.compareTo(start) >= 0) {
if (next.compareTo(end) <= 0) {
// the date is within range, select it
if (first == null) {
first = next;
lastSize = 0;
}
first = next;
selected.add(next);
++lastSize;
} else {
// we have exceeded date range
break;
}
selected.add(next);
last = next;
++lastSize;
}
last = next;
}
return selected;
......
......@@ -50,7 +50,7 @@ public class FixedStepSelector implements DatesSelector {
public FixedStepSelector(final double step, final TimeScale alignmentTimeScale) {
this.step = step;
this.alignmentTimeScale = alignmentTimeScale;
this.last = AbsoluteDate.PAST_INFINITY;
this.last = null;
}
/** {@inheritDoc} */
......@@ -59,17 +59,33 @@ public class FixedStepSelector implements DatesSelector {
final List<AbsoluteDate> selected = new ArrayList<>();
for (AbsoluteDate next = start.durationFrom(last) > step ? start : last.shiftedBy(step);
final boolean reset = last == null || start.durationFrom(last) > step;
for (AbsoluteDate next = reset ? start : last.shiftedBy(step);
next.compareTo(end) <= 0;
next = last.shiftedBy(step)) {
if (alignmentTimeScale != null) {
// align date to time scale
final double t = next.getComponents(alignmentTimeScale).getTime().getSecondsInLocalDay();
final double dt = step * FastMath.round(t / step) - t;
next = next.shiftedBy(dt);
if (next.compareTo(start) < 0) {
// alignment shifted date before interval
next = next.shiftedBy(step);
}
}
if (next.compareTo(start) >= 0) {
if (next.compareTo(end) <= 0) {
// the date is within range, select it
selected.add(next);
} else {
// we have exceeded date range
break;
}
}
selected.add(next);
last = next;
}
return selected;
......
/* Copyright 2002-2018 CS Systèmes d'Information
* Licensed to CS Systèmes d'Information (CS) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* CS licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.orekit.time;
import java.util.List;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.orekit.Utils;
public class BurstSelectorStepTest {
@Test
public void testNoAlign() {
final TimeScale utc = TimeScalesFactory.getUTC();
final DatesSelector selector = new BurstSelector(3, 10.0, 60.0, null);
final AbsoluteDate t0 = new AbsoluteDate("2003-02-25T00:00:27.0", utc);
final AbsoluteDate t1 = t0.shiftedBy(71);
final List<AbsoluteDate> list = selector.selectDates(t0, t1);
Assert.assertEquals(5, list.size());
Assert.assertEquals( 27.0, list.get(0).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
Assert.assertEquals( 37.0, list.get(1).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
Assert.assertEquals( 47.0, list.get(2).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
Assert.assertEquals( 87.0, list.get(3).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
Assert.assertEquals( 97.0, list.get(4).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
}
@Test
public void testAlignUTCBefore() {
final TimeScale utc = TimeScalesFactory.getUTC();
final DatesSelector selector = new BurstSelector(2, 10.0, 30.0, utc);
final AbsoluteDate t0 = new AbsoluteDate("2003-02-25T00:00:27.0", utc);
final AbsoluteDate t1 = t0.shiftedBy(62);
final List<AbsoluteDate> list = selector.selectDates(t0, t1);
Assert.assertEquals(4, list.size());
Assert.assertEquals( 30.0, list.get(0).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
Assert.assertEquals( 40.0, list.get(1).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
Assert.assertEquals( 60.0, list.get(2).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
Assert.assertEquals( 70.0, list.get(3).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
}
@Test
public void testAlignUTCAfter() {
final TimeScale utc = TimeScalesFactory.getUTC();
final DatesSelector selector = new BurstSelector(3, 10.0, 60.0, utc);
final AbsoluteDate t0 = new AbsoluteDate("2003-02-25T00:00:27.0", utc);
final AbsoluteDate t1 = t0.shiftedBy(2);
final AbsoluteDate t2 = t1.shiftedBy(98);
final List<AbsoluteDate> list1 = selector.selectDates(t0, t1);
Assert.assertEquals(0, list1.size());
final List<AbsoluteDate> list2 = selector.selectDates(t1, t2);
Assert.assertEquals(4, list2.size());
Assert.assertEquals( 60.0, list2.get(0).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
Assert.assertEquals( 70.0, list2.get(1).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
Assert.assertEquals( 80.0, list2.get(2).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
Assert.assertEquals(120.0, list2.get(3).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
}
@Test
public void testInterruptedStream() {
final TimeScale utc = TimeScalesFactory.getUTC();
final DatesSelector selector = new BurstSelector(3, 10.0, 60.0, null);
final AbsoluteDate t0 = new AbsoluteDate("2003-02-25T00:00:27.0", utc);
final AbsoluteDate t1 = t0.shiftedBy(71);
final AbsoluteDate t2 = t1.shiftedBy(30);
final List<AbsoluteDate> list1 = selector.selectDates(t0, t1);
Assert.assertEquals(5, list1.size());
final List<AbsoluteDate> list2 = selector.selectDates(t1, t2);
Assert.assertEquals(1, list2.size());
Assert.assertEquals(10.0, list2.get(0).durationFrom(list1.get(list1.size() - 1)), 1.0e-15);
}
@Test
public void testMissedHighRateNoReset() {
final TimeScale utc = TimeScalesFactory.getUTC();
final DatesSelector selector = new BurstSelector(3, 10.0, 60.0, null);
final AbsoluteDate t0 = new AbsoluteDate("2003-02-25T00:00:27.0", utc);
final AbsoluteDate t1 = t0.shiftedBy(71);
final AbsoluteDate t2 = t1.shiftedBy(30);
final AbsoluteDate t3 = t2.shiftedBy(15);
final List<AbsoluteDate> list1 = selector.selectDates(t0, t1);
Assert.assertEquals(5, list1.size());
final List<AbsoluteDate> list2 = selector.selectDates(t2, t3);
Assert.assertEquals(1, list2.size());
Assert.assertEquals(40.0, list2.get(0).durationFrom(list1.get(list1.size() - 1)), 1.0e-15);
}
@Test
public void testResetStream() {
final TimeScale utc = TimeScalesFactory.getUTC();
final DatesSelector selector = new BurstSelector(3, 10.0, 60.0, null);
final AbsoluteDate t0 = new AbsoluteDate("2003-02-25T00:00:27.0", utc);
final AbsoluteDate t1 = t0.shiftedBy(71);
final AbsoluteDate t2 = t1.shiftedBy(50);
final AbsoluteDate t3 = t2.shiftedBy(15);
final List<AbsoluteDate> list1 = selector.selectDates(t0, t1);
Assert.assertEquals(5, list1.size());
final List<AbsoluteDate> list2 = selector.selectDates(t2, t3);
Assert.assertEquals(2, list2.size());
Assert.assertEquals( 0.0, list2.get(0).durationFrom(t2), 1.0e-15);
Assert.assertEquals(10.0, list2.get(1).durationFrom(t2), 1.0e-15);
}
@Test
public void testShortInterval() {
final TimeScale utc = TimeScalesFactory.getUTC();
final DatesSelector selector = new BurstSelector(3, 10.0, 60.0, null);
final AbsoluteDate t0 = new AbsoluteDate("2003-02-25T00:00:27.0", utc);
final AbsoluteDate t1 = t0.shiftedBy(71);
final AbsoluteDate t2 = t1.shiftedBy(8);
final List<AbsoluteDate> list1 = selector.selectDates(t0, t1);
Assert.assertEquals(5, list1.size());
final List<AbsoluteDate> list2 = selector.selectDates(t1, t2);
Assert.assertEquals(0, list2.size());
}
@Before
public void setUp() {
Utils.setDataRoot("regular-data");
}
}
/* Copyright 2002-2018 CS Systèmes d'Information
* Licensed to CS Systèmes d'Information (CS) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* CS licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.orekit.time;
import java.util.List;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.orekit.Utils;
public class FixedStepSelectorTest {
@Test
public void testNoAlign() {
final TimeScale utc = TimeScalesFactory.getUTC();
final DatesSelector selector = new FixedStepSelector(10.0, null);
final AbsoluteDate t0 = new AbsoluteDate("2003-02-25T00:00:27.0", utc);
final AbsoluteDate t1 = t0.shiftedBy(91);
final List<AbsoluteDate> list = selector.selectDates(t0, t1);
Assert.assertEquals(10, list.size());
Assert.assertEquals( 27.0, list.get(0).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
Assert.assertEquals( 37.0, list.get(1).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
Assert.assertEquals( 47.0, list.get(2).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
Assert.assertEquals( 57.0, list.get(3).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
Assert.assertEquals( 67.0, list.get(4).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
Assert.assertEquals( 77.0, list.get(5).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
Assert.assertEquals( 87.0, list.get(6).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
Assert.assertEquals( 97.0, list.get(7).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
Assert.assertEquals(107.0, list.get(8).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
Assert.assertEquals(117.0, list.get(9).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
}
@Test
public void testAlignUTCBefore() {
final TimeScale utc = TimeScalesFactory.getUTC();
final DatesSelector selector = new FixedStepSelector(5.0, utc);
final AbsoluteDate t0 = new AbsoluteDate("2003-02-25T00:00:27.0", utc);
final AbsoluteDate t1 = t0.shiftedBy(17);
final List<AbsoluteDate> list = selector.selectDates(t0, t1);
Assert.assertEquals(3, list.size());
Assert.assertEquals( 30.0, list.get(0).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
Assert.assertEquals( 35.0, list.get(1).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
Assert.assertEquals( 40.0, list.get(2).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
}
@Test
public void testAlignUTCAfter() {
final TimeScale utc = TimeScalesFactory.getUTC();
final DatesSelector selector = new FixedStepSelector(10.0, utc);
final AbsoluteDate t0 = new AbsoluteDate("2003-02-25T00:00:27.0", utc);
final AbsoluteDate t1 = t0.shiftedBy(2);
final AbsoluteDate t2 = t1.shiftedBy(89);
final List<AbsoluteDate> list1 = selector.selectDates(t0, t1);
Assert.assertEquals(0, list1.size());
final List<AbsoluteDate> list2 = selector.selectDates(t1, t2);
Assert.assertEquals(9, list2.size());
Assert.assertEquals( 30.0, list2.get(0).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
Assert.assertEquals( 40.0, list2.get(1).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
Assert.assertEquals( 50.0, list2.get(2).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
Assert.assertEquals( 60.0, list2.get(3).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
Assert.assertEquals( 70.0, list2.get(4).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
Assert.assertEquals( 80.0, list2.get(5).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
Assert.assertEquals( 90.0, list2.get(6).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
Assert.assertEquals(100.0, list2.get(7).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
Assert.assertEquals(110.0, list2.get(8).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
}
@Test
public void testInterruptedStream() {
final TimeScale utc = TimeScalesFactory.getUTC();
final DatesSelector selector = new FixedStepSelector(10.0, null);
final AbsoluteDate t0 = new AbsoluteDate("2003-02-25T00:00:27.0", utc);
final AbsoluteDate t1 = t0.shiftedBy(91);
final AbsoluteDate t2 = t1.shiftedBy(30);
final List<AbsoluteDate> list1 = selector.selectDates(t0, t1);
Assert.assertEquals(10, list1.size());
final List<AbsoluteDate> list2 = selector.selectDates(t1, t2);
Assert.assertEquals(3, list2.size());
Assert.assertEquals(10.0, list2.get(0).durationFrom(list1.get(list1.size() - 1)), 1.0e-15);
}
@Test
public void testResetStream() {
final TimeScale utc = TimeScalesFactory.getUTC();
final DatesSelector selector = new FixedStepSelector(10.0, null);
final AbsoluteDate t0 = new AbsoluteDate("2003-02-25T00:00:27.0", utc);
final AbsoluteDate t1 = t0.shiftedBy(91);
final AbsoluteDate t2 = t1.shiftedBy(30);
final AbsoluteDate t3 = t2.shiftedBy(15);
final List<AbsoluteDate> list1 = selector.selectDates(t0, t1);
Assert.assertEquals(10, list1.size());
final List<AbsoluteDate> list2 = selector.selectDates(t2, t3);
Assert.assertEquals(2, list2.size());
Assert.assertEquals( 0.0, list2.get(0).durationFrom(t2), 1.0e-15);
Assert.assertEquals(10.0, list2.get(1).durationFrom(t2), 1.0e-15);
}
@Test
public void testShortInterval() {
final TimeScale utc = TimeScalesFactory.getUTC();
final DatesSelector selector = new FixedStepSelector(10.0, null);
final AbsoluteDate t0 = new AbsoluteDate("2003-02-25T00:00:27.0", utc);
final AbsoluteDate t1 = t0.shiftedBy(91);
final AbsoluteDate t2 = t1.shiftedBy(8);
final List<AbsoluteDate> list1 = selector.selectDates(t0, t1);
Assert.assertEquals(10, list1.size());
final List<AbsoluteDate> list2 = selector.selectDates(t1, t2);
Assert.assertEquals(0, list2.size());
}
@Before
public void setUp() {
Utils.setDataRoot("regular-data");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment