@Test @Ignore public void references5MsPeriod4() { TimeScale linearScale = TimeScales.linearAbsoluteScale(); Instant start = TimeScalesTest.create( 2014 , 12 , 24 , 22 , 59 , 59 , 989 ); TimeInterval timeInterval = TimeInterval.between(start, start.plus(Duration.ofMillis( 18 ) ) ); TimeAxis timeAxis = linearScale.references( timeInterval, 4 , 4 ); assertAxisEquals( timeInterval, new ArrayDouble( 1.0/18.0, 6.0/18.0, 11.0/18.0, 16.0/18.0 ), Arrays.asList( TimeScalesTest.create( 2014 , 12 , 24 , 22 , 59 , 59 , 990 ), TimeScalesTest.create( 2014 , 12 , 24 , 22 , 59 , 59 , 995 ), TimeScalesTest.create( 2014 , 12 , 24 , 23 , 0 , 0 , 0 ), TimeScalesTest.create( 2014 , 12 , 24 , 23 , 0 , 0 , 5 ) ), Arrays.asList( "2014/12/24 22:59:59.990", ".995", "23:00:00.000", ".005" ), timeAxis); }
@Override public TimeAxis references(TimeInterval range, int minRefs, int maxRefs) { if ( (maxRefs < minRefs) || (minRefs < 0 ) || (maxRefs < 0) ) { throw new IllegalArgumentException( "Invalid references range: " + minRefs + " < # references < " + maxRefs ); } double minPeriodInSec; if( maxRefs == 0){ minPeriodInSec = 0.0; }else{ minPeriodInSec = range.getStart().until(range.getEnd(), ChronoUnit.SECONDS) / maxRefs; } TimeScales.TimePeriod timePeriod = TimeScales.toTimePeriod(minPeriodInSec); timePeriod = TimeScales.nextDown(timePeriod); List<Instant> references = TimeScales.createReferences(range, timePeriod); while(references.size() > maxRefs) { timePeriod = TimeScales.nextUp(timePeriod); references = TimeScales.createReferences(range, timePeriod); } if (references.size() < minRefs) { throw new RuntimeException("Can't create the requested amount of references. Could only create: " + references.size() + ", minimum required: " + minRefs ); } double[] normalized = new double[references.size()]; for (int i = 0; i < references.size(); i++) { normalized[i] = TimeScales.normalize(references.get(i), range); } ArrayDouble normalizedValues = new ArrayDouble(normalized); return new TimeAxis(range, references, normalizedValues, TimeScales.trimLabels(TimeScales.createLabels(references))); }
LinearAbsoluteTimeScale implements TimeScale { @Override public TimeAxis references(TimeInterval range, int minRefs, int maxRefs) { if ( (maxRefs < minRefs) || (minRefs < 0 ) || (maxRefs < 0) ) { throw new IllegalArgumentException( "Invalid references range: " + minRefs + " < # references < " + maxRefs ); } double minPeriodInSec; if( maxRefs == 0){ minPeriodInSec = 0.0; }else{ minPeriodInSec = range.getStart().until(range.getEnd(), ChronoUnit.SECONDS) / maxRefs; } TimeScales.TimePeriod timePeriod = TimeScales.toTimePeriod(minPeriodInSec); timePeriod = TimeScales.nextDown(timePeriod); List<Instant> references = TimeScales.createReferences(range, timePeriod); while(references.size() > maxRefs) { timePeriod = TimeScales.nextUp(timePeriod); references = TimeScales.createReferences(range, timePeriod); } if (references.size() < minRefs) { throw new RuntimeException("Can't create the requested amount of references. Could only create: " + references.size() + ", minimum required: " + minRefs ); } double[] normalized = new double[references.size()]; for (int i = 0; i < references.size(); i++) { normalized[i] = TimeScales.normalize(references.get(i), range); } ArrayDouble normalizedValues = new ArrayDouble(normalized); return new TimeAxis(range, references, normalizedValues, TimeScales.trimLabels(TimeScales.createLabels(references))); } }
LinearAbsoluteTimeScale implements TimeScale { @Override public TimeAxis references(TimeInterval range, int minRefs, int maxRefs) { if ( (maxRefs < minRefs) || (minRefs < 0 ) || (maxRefs < 0) ) { throw new IllegalArgumentException( "Invalid references range: " + minRefs + " < # references < " + maxRefs ); } double minPeriodInSec; if( maxRefs == 0){ minPeriodInSec = 0.0; }else{ minPeriodInSec = range.getStart().until(range.getEnd(), ChronoUnit.SECONDS) / maxRefs; } TimeScales.TimePeriod timePeriod = TimeScales.toTimePeriod(minPeriodInSec); timePeriod = TimeScales.nextDown(timePeriod); List<Instant> references = TimeScales.createReferences(range, timePeriod); while(references.size() > maxRefs) { timePeriod = TimeScales.nextUp(timePeriod); references = TimeScales.createReferences(range, timePeriod); } if (references.size() < minRefs) { throw new RuntimeException("Can't create the requested amount of references. Could only create: " + references.size() + ", minimum required: " + minRefs ); } double[] normalized = new double[references.size()]; for (int i = 0; i < references.size(); i++) { normalized[i] = TimeScales.normalize(references.get(i), range); } ArrayDouble normalizedValues = new ArrayDouble(normalized); return new TimeAxis(range, references, normalizedValues, TimeScales.trimLabels(TimeScales.createLabels(references))); }  }
LinearAbsoluteTimeScale implements TimeScale { @Override public TimeAxis references(TimeInterval range, int minRefs, int maxRefs) { if ( (maxRefs < minRefs) || (minRefs < 0 ) || (maxRefs < 0) ) { throw new IllegalArgumentException( "Invalid references range: " + minRefs + " < # references < " + maxRefs ); } double minPeriodInSec; if( maxRefs == 0){ minPeriodInSec = 0.0; }else{ minPeriodInSec = range.getStart().until(range.getEnd(), ChronoUnit.SECONDS) / maxRefs; } TimeScales.TimePeriod timePeriod = TimeScales.toTimePeriod(minPeriodInSec); timePeriod = TimeScales.nextDown(timePeriod); List<Instant> references = TimeScales.createReferences(range, timePeriod); while(references.size() > maxRefs) { timePeriod = TimeScales.nextUp(timePeriod); references = TimeScales.createReferences(range, timePeriod); } if (references.size() < minRefs) { throw new RuntimeException("Can't create the requested amount of references. Could only create: " + references.size() + ", minimum required: " + minRefs ); } double[] normalized = new double[references.size()]; for (int i = 0; i < references.size(); i++) { normalized[i] = TimeScales.normalize(references.get(i), range); } ArrayDouble normalizedValues = new ArrayDouble(normalized); return new TimeAxis(range, references, normalizedValues, TimeScales.trimLabels(TimeScales.createLabels(references))); }  @Override double scaleNormalizedTime(double value, double newMinValue, double newMaxValue); @Override double scaleTimestamp(Instant value, TimeInterval timeInterval, double newMinValue, double newMaxValue); @Override TimeAxis references(TimeInterval range, int minRefs, int maxRefs); }
LinearAbsoluteTimeScale implements TimeScale { @Override public TimeAxis references(TimeInterval range, int minRefs, int maxRefs) { if ( (maxRefs < minRefs) || (minRefs < 0 ) || (maxRefs < 0) ) { throw new IllegalArgumentException( "Invalid references range: " + minRefs + " < # references < " + maxRefs ); } double minPeriodInSec; if( maxRefs == 0){ minPeriodInSec = 0.0; }else{ minPeriodInSec = range.getStart().until(range.getEnd(), ChronoUnit.SECONDS) / maxRefs; } TimeScales.TimePeriod timePeriod = TimeScales.toTimePeriod(minPeriodInSec); timePeriod = TimeScales.nextDown(timePeriod); List<Instant> references = TimeScales.createReferences(range, timePeriod); while(references.size() > maxRefs) { timePeriod = TimeScales.nextUp(timePeriod); references = TimeScales.createReferences(range, timePeriod); } if (references.size() < minRefs) { throw new RuntimeException("Can't create the requested amount of references. Could only create: " + references.size() + ", minimum required: " + minRefs ); } double[] normalized = new double[references.size()]; for (int i = 0; i < references.size(); i++) { normalized[i] = TimeScales.normalize(references.get(i), range); } ArrayDouble normalizedValues = new ArrayDouble(normalized); return new TimeAxis(range, references, normalizedValues, TimeScales.trimLabels(TimeScales.createLabels(references))); }  @Override double scaleNormalizedTime(double value, double newMinValue, double newMaxValue); @Override double scaleTimestamp(Instant value, TimeInterval timeInterval, double newMinValue, double newMaxValue); @Override TimeAxis references(TimeInterval range, int minRefs, int maxRefs);  }