@Test @Ignore public void references1MsPeriod4() { TimeScale linearScale = TimeScales.linearAbsoluteScale(); Instant start = TimeScalesTest.create( 2014 , 11 , 13 , 10 , 31 , 23 , 53 ); int MS_INTERVAL = 4321; TimeInterval timeInterval = TimeInterval.between(start, start.plus(Duration.ofMillis( MS_INTERVAL ) ) ); TimeAxis timeAxis = linearScale.references( timeInterval, 2 , 99999999 ); double[] normalValues = new double[ MS_INTERVAL+1 ]; for ( int i=0 ; i<=MS_INTERVAL ; i++ ) { normalValues[ i ] = ((double)(i)/MS_INTERVAL); } ArrayList< Instant > times = new ArrayList< Instant >(); ArrayList< String > labels = new ArrayList< String >(); times.add( TimeScalesTest.create( 2014 , 11 , 13 , 10 , 31 , 23 , 53 ) ); labels.add( "2014/11/13 10:31:23.053" ); int timeLeft = MS_INTERVAL; int hour = 10; int minute = 31; int second = 23; int ms = 53; while( timeLeft > 0 ) { timeLeft--; ms++; String nextLabel = "." + formatNumericalString( ms%1000 , 3 ); boolean useFullLabel = false; if ( ms >= 1000 ) { second += (int)(ms/1000); ms %= 1000; useFullLabel = true; } if ( second >= 60 ) { minute += (int)(second/60); second %= 60; useFullLabel = true; } if ( minute >= 60 ) { hour += (int)(minute/60); minute %= 60; useFullLabel = true; } times.add( TimeScalesTest.create( 2014 , 11 , 13 , hour , minute , second , ms ) ); if ( useFullLabel ) { String fullLabel = formatNumericalString( hour , 2 ) + ":" + formatNumericalString( minute , 2 ) + ":" + formatNumericalString( second , 2 ) + "." + formatNumericalString( ms , 3 ); labels.add( fullLabel ); } else { labels.add( nextLabel ); } } assertAxisEquals(timeInterval, new ArrayDouble( normalValues ), times, labels, 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);  }