@Test @Ignore public void references2() { TimeScale linearScale = TimeScales.linearAbsoluteScale(); Instant start = TimeScalesTest.create(2013, 5, 10, 16, 13, 44, 100); TimeInterval timeInterval = TimeInterval.between(start, start.plus(Duration.ofSeconds(5))); TimeAxis timeAxis = linearScale.references(timeInterval, 2, 11); assertAxisEquals(timeInterval, new ArrayDouble(4.0/50.0, 9.0/50.0, 14.0/50.0, 19.0/50.0, 24.0/50.0, 29.0/50.0, 34.0/50.0, 39.0/50.0, 44.0/50.0, 49.0/50.0), Arrays.asList(TimeScalesTest.create(2013, 5, 10, 16, 13, 44, 500), TimeScalesTest.create(2013, 5, 10, 16, 13, 45, 0), TimeScalesTest.create(2013, 5, 10, 16, 13, 45, 500), TimeScalesTest.create(2013, 5, 10, 16, 13, 46, 0), TimeScalesTest.create(2013, 5, 10, 16, 13, 46, 500), TimeScalesTest.create(2013, 5, 10, 16, 13, 47, 0), TimeScalesTest.create(2013, 5, 10, 16, 13, 47, 500), TimeScalesTest.create(2013, 5, 10, 16, 13, 48, 0), TimeScalesTest.create(2013, 5, 10, 16, 13, 48, 500), TimeScalesTest.create(2013, 5, 10, 16, 13, 49, 0)), Arrays.asList("2013/05/10 16:13:44.5", "16:13:45.0", ".5", "16:13:46.0", ".5", "16:13:47.0", ".5", "16:13:48.0", ".5", "16:13:49.0"), 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);  }