Plotly.js: How to avoid overlapping contour lines? - javascript

Below is an example for creating a contour plot with plotly.js. Some of the contour lines overlap.
How can I alter the plotly settings to avoid that (e.g. increase resolution, switch contouring algorithm)? If I plot the same data using conrec.js the contours do not overlap.
A. Conrec.js (this works, no overlap)
Source code for the example:
https://github.com/jasondavies/conrec.js/tree/master/example
B. Plotly.js (does not work: overlapping contours)
Source code for the example:
https://jsfiddle.net/jwmdw3o1/
Resources:
https://cdn.plot.ly/plotly-latest.min.js
https://github.com/mbostock/d3/raw/v1.10.1/d3.js
Html:
<div id="graph"></div>
JavaScript:
var zData = createData();
var xData = d3.range(0, zData.length);
var yData = d3.range(0, zData[0].length);
var data = [ {
z: zData,
x: xData,
y: yData,
type: 'contour',
colorscale: 'Jet',
showscale: false,
autocontour: false,
contours: {
start: -5,
end: 3,
size: 0.5
}
}];
var layout = {
margin: {
b: 0,
l: 0,
r: 0,
t: 0
},
height: 600,
width: 600,
title: '',
xaxis: {
ticks: '',
showticklabels: false
},
yaxis: {
ticks: '',
showticklabels: false
}
};
Plotly.newPlot('graph', data, layout, {displayModeBar: false});
function createData(){
var data = [
[
0.4,
0.4,
0.7,
-1.0,
-0.1,
0.6,
-0.4,
0.6,
-0.4,
1.3,
0.7,
-0.4,
1.1,
1.3,
0.6,
0.1,
-0.0,
-0.8,
-0.8,
-1.0
],
[
0.4,
-0.4,
0.4,
-1.2,
-0.7,
0.4,
-0.9,
0.5,
-0.9,
1.2,
0.5,
-1.0,
1.3,
1.1,
0.5,
-0.0,
-0.1,
-1.2,
-1.0,
-0.9
],
[
0.7,
0.4,
0.1,
-1.2,
-0.2,
0.5,
-0.6,
0.6,
-0.2,
0.9,
0.6,
-0.5,
1.1,
0.8,
0.6,
0.1,
-0.4,
-0.9,
-0.7,
-0.8
],
[
-1.0,
-1.2,
-1.2,
-4.4,
-1.9,
-0.8,
-2.2,
-1.0,
-2.2,
0.0,
-0.3,
-2.0,
-0.2,
0.2,
-0.8,
-1.6,
-1.9,
-2.4,
-2.3,
-2.6
],
[
-0.1,
-0.7,
-0.2,
-1.9,
-2.0,
-0.5,
-1.9,
-0.3,
-1.7,
0.4,
-0.2,
-1.9,
0.3,
0.4,
-0.3,
-0.8,
-0.9,
-2.1,
-1.8,
-2.0
],
[
0.6,
0.4,
0.5,
-0.8,
-0.5,
-0.1,
-0.8,
0.6,
-0.5,
1.0,
0.5,
-0.7,
0.8,
1.0,
0.5,
0.1,
-0.3,
-0.9,
-0.7,
-1.1
],
[
-0.4,
-0.9,
-0.6,
-2.2,
-1.9,
-0.8,
-2.7,
-0.6,
-2.0,
0.3,
-0.3,
-2.3,
-0.0,
-0.0,
-0.6,
-1.1,
-1.3,
-2.4,
-2.0,
-2.2
],
[
0.6,
0.5,
0.6,
-1.0,
-0.3,
0.6,
-0.6,
0.1,
-0.8,
1.3,
0.8,
-0.8,
1.1,
1.3,
0.4,
0.1,
0.1,
-0.8,
-1.0,
-1.0
],
[
-0.4,
-0.9,
-0.2,
-2.2,
-1.7,
-0.5,
-2.0,
-0.8,
-2.9,
0.3,
-0.4,
-2.2,
-0.0,
-0.0,
-0.7,
-0.7,
-1.3,
-2.4,
-2.1,
-2.6
],
[
1.3,
1.2,
0.9,
0.0,
0.4,
1.0,
0.3,
1.3,
0.3,
1.1,
1.0,
0.2,
0.7,
1.9,
0.9,
-0.2,
0.3,
0.1,
-0.4,
-0.2
],
[
0.7,
0.5,
0.6,
-0.3,
-0.2,
0.5,
-0.3,
0.8,
-0.4,
1.0,
0.3,
-0.3,
1.0,
1.1,
0.6,
0.1,
0.3,
-0.7,
-0.5,
-0.6
],
[
-0.4,
-1.0,
-0.5,
-2.0,
-1.9,
-0.7,
-2.3,
-0.8,
-2.2,
0.2,
-0.3,
-2.7,
0.0,
-0.0,
-0.6,
-1.0,
-1.1,
-2.3,
-2.1,
-2.4
],
[
1.1,
1.3,
1.1,
-0.2,
0.3,
0.8,
-0.0,
1.1,
-0.0,
0.7,
1.0,
0.0,
1.6,
0.8,
1.0,
0.8,
0.7,
-0.2,
-0.2,
-0.2
],
[
1.3,
1.1,
0.8,
0.2,
0.4,
1.0,
-0.0,
1.3,
-0.0,
1.9,
1.1,
-0.0,
0.8,
1.2,
1.1,
0.0,
0.2,
-0.1,
-0.4,
0.0
],
[
0.6,
0.5,
0.6,
-0.8,
-0.3,
0.5,
-0.6,
0.4,
-0.7,
0.9,
0.6,
-0.6,
1.0,
1.1,
-0.2,
0.1,
-0.0,
-0.9,
-0.6,
-1.2
],
[
0.1,
-0.0,
0.1,
-1.6,
-0.8,
0.1,
-1.1,
0.1,
-0.7,
-0.2,
0.1,
-1.0,
0.8,
0.0,
0.1,
-0.6,
-0.4,
-1.2,
-1.3,
-1.4
],
[
-0.0,
-0.1,
-0.4,
-1.9,
-0.9,
-0.3,
-1.3,
0.1,
-1.3,
0.3,
0.3,
-1.1,
0.7,
0.2,
-0.0,
-0.4,
-1.3,
-1.4,
-1.6,
-1.9
],
[
-0.8,
-1.2,
-0.9,
-2.4,
-2.1,
-0.9,
-2.4,
-0.8,
-2.4,
0.1,
-0.7,
-2.3,
-0.2,
-0.1,
-0.9,
-1.2,
-1.4,
-3.0,
-2.3,
-2.5
],
[
-0.8,
-1.0,
-0.7,
-2.3,
-1.8,
-0.7,
-2.0,
-1.0,
-2.1,
-0.4,
-0.5,
-2.1,
-0.2,
-0.4,
-0.6,
-1.3,
-1.6,
-2.3,
-2.3,
-2.4
],
[
-1.0,
-0.9,
-0.8,
-2.6,
-2.0,
-1.1,
-2.2,
-1.0,
-2.6,
-0.2,
-0.6,
-2.4,
-0.2,
0.0,
-1.2,
-1.4,
-1.9,
-2.5,
-2.4,
-3.3
]
];
return data;
}

Adapting the line options with "smoothing: 0" resolves this:
var data = [ {
...
line: {
smoothing: 0
}
...
}];
https://plot.ly/javascript/reference/#contour-line

Related

How can I get the beats per minute using FFT on the amplitude data?

I checked all the answers on stackoverflow regarding this topic, but any solution does not work with my dataset.
The dataset consists of 600 amplitudes sampled at 60 samples per second.
In this dataset, there are 13 beats in 10 seconds.
So the result should be around 78 beats per minute.
I know I could use peak detection in various ways, but I wish to know if there is a way to detect it using FFT (fftjs).
I also tried this great approach Peak signal detection in realtime timeseries data
but it doesn't seem to work well with this dataset.
$(function() {
function out(array) {
$("#console").html($("#console").html() + "<br/><br/>" + JSON.stringify(array));
//console.log(JSON.stringify(array));
}
var fft = new FFT({samplingRate:60});
///////////////////////////////////////////////////
//// INPUT DATA
///////////////////////////////////////////////////
// If you test sine curve, please change flag WAVEFORM_TEST to true.
var WAVEFORM_TEST = false;
var real = [];
if (WAVEFORM_TEST) {
N = 320;
k = 40;
// frequency = (k/N)
for (i = 0; i<N; i++){
real.push(Math.sin((2 * Math.PI * k * i) / N ));
}
} else {
real = [.5,.5,-.7000000000000001,-.9,-.9,-.1,.10000000000000003,.10000000000000003,-.8000000000000002,-.8000000000000002,.8999999999999999,-4,-6.3,-3.5,1.7999999999999996,5.199999999999999,5.199999999999999,5.7,2,2,.6,-.10000000000000003,-1.1,-2.8,-1.2999999999999998,1.0000000000000002,1.0000000000000002,-2.3000000000000003,-4.5,-4.5,-.20000000000000007,1.0000000000000004,1.0000000000000004,.8000000000000003,-.6,-.6,-.3000000000000001,.4000000000000001,.6000000000000002,.10000000000000009,-.6,-.6,-.8999999999999999,-.20000000000000004,-.20000000000000004,1.1,1.4,1.0999999999999999,.6,.10000000000000006,-.6000000000000001,-.8,.19999999999999993,.19999999999999993,-1.9000000000000001,-1.5999999999999999,-1.5999999999999999,1.6,-3.3,-6.3,-3.6,2.1000000000000005,5.999999999999999,5.999999999999999,4,4,1.2000000000000002,-.6000000000000001,-.6000000000000001,-.9,-.9000000000000001,-.9000000000000001,2.5000000000000004,2.9000000000000004,-1.1000000000000003,-1.1000000000000003,-4.3,-1.8,-1.8,.09999999999999998,.09999999999999998,0,.9000000000000001,1.9000000000000004,2.4,2.3,1.5999999999999996,1.5999999999999996,.30000000000000004,-.20000000000000007,-.20000000000000007,-.4,-.4,.30000000000000004,2.6,2.4000000000000004,.9999999999999999,-.8,-1.6,-1.6,-.5000000000000001,-1.2999999999999998,-1.2999999999999998,2.4000000000000004,2.1999999999999997,2.1999999999999997,-8.100000000000001,-6.4,-.6,-.6,6,6,4.4,-.49999999999999994,-.49999999999999994,-.7999999999999998,-1,-1,-1.2,1.4000000000000004,3.4,3.4,-3.6,-4.199999999999999,-4.199999999999999,.7999999999999999,.7999999999999999,1.9,.9000000000000001,.9000000000000001,.30000000000000004,0,0,0,-.10000000000000003,-.7000000000000001,-.7000000000000001,.20000000000000004,.9,.9,1.9000000000000001,1.9000000000000001,1.9,.9000000000000001,0,0,-1.6,-.7000000000000001,-.7000000000000001,-1.5,1.5,1.5,3.3,1.3877787807814457e-16,-6.7,-2.1,3.4,3.4,6.300000000000001,2.7,2.7,.19999999999999987,.30000000000000004,.30000000000000004,.5,-.6000000000000001,1.1,3,.6000000000000001,-4.7,-4.7,-6.4,0,0,.9000000000000002,.9000000000000002,.4999999999999999,1.4000000000000001,1.3,1.3,-.1,-.1,-.6000000000000001,-.8,-.30000000000000004,-.30000000000000004,.7000000000000002,.8000000000000002,.8000000000000002,1.6,1.0999999999999999,.5,-.1,-.1,-.8,-.5000000000000001,-1.1,-1.1,-1.2000000000000002,4.400000000000001,4.400000000000001,.5,-5.999999999999999,-2.9000000000000004,3.0999999999999996,6.300000000000001,6.300000000000001,6.300000000000001,2.6999999999999997,2.6999999999999997,1.5,-.8000000000000002,-.8000000000000002,-1.9,.09999999999999998,1.6,1.6,-4.3999999999999995,-5.300000000000001,-5.300000000000001,.3999999999999999,1.9999999999999998,1.9999999999999998,2.2,2,2,.5,-.2,-.2,-.3000000000000001,-.5,-.5,-.6,-.20000000000000004,-.20000000000000004,1.4,1.4,1.5000000000000002,.9000000000000001,.8,.8,-.7000000000000001,-1.4000000000000004,-1.4000000000000004,-.9999999999999999,-1.3,-.3,-.3,2.7,2.7,-7.700000000000001,-6,-.2999999999999998,-.2999999999999998,7.200000000000001,6.300000000000001,6.300000000000001,2,2,.19999999999999996,-2.2,-2.2,-.5,2.1,2.4,2.4,-4.9,-3.8000000000000007,-1.3,.29999999999999993,.30000000000000004,.30000000000000004,.5,.5,.8,-.4000000000000001,-.4000000000000001,-1.4999999999999998,-1.5000000000000002,-1.5000000000000002,-1.6,-1.3000000000000003,-1.3000000000000003,-.1,1.5999999999999999,1.4,.9,1.2999999999999998,1.8,1.6,1.6,-1,-1,-1.5999999999999999,-2.7755575615628914e-17,-2.7755575615628914e-17,-.9000000000000001,1.5,2.5,2.5,-6.699999999999999,-5.4,-5.4,5.2,6.7,6.7,2.6,.8999999999999999,.8999999999999999,.1,-.9999999999999999,-1.7,-1,1.4,2,-1.5,-4.3,-4.3,-.6000000000000001,.8999999999999999,.8999999999999999,.8,.8,.4,.2,.10000000000000003,.10000000000000003,-.4,-.7999999999999999,-.7999999999999999,-1.2000000000000002,-.30000000000000004,-.30000000000000004,1.2,1.1,1.1,.6,.3,.3999999999999999,.3999999999999999,-.20000000000000004,-.20000000000000004,-1.1,-.30000000000000004,-.30000000000000004,-.4,-.3000000000000001,2.6999999999999997,1.7000000000000002,-3.7999999999999994,-6.8,-6.8,2.1000000000000005,2.1000000000000005,5.8,4.3,4.3,2.1,.20000000000000004,-.9,-1.7000000000000002,-2.0000000000000004,-.4,-.4,1.1,1.1,-2.6999999999999997,-2.7,-.29999999999999993,-.29999999999999993,1.2999999999999998,1.2999999999999998,.8,.09999999999999998,.2,.2,-.1,-.30000000000000004,-.30000000000000004,-.9,-.9,-.9,-.2,.7000000000000001,1,1,1,1.4,1.4,.2,.2,-1.1,-1.4000000000000001,-1.4000000000000001,0,-.5000000000000001,-.5000000000000001,0,1.9,-3.5000000000000004,-3.5000000000000004,-5.199999999999999,-5.199999999999999,.40000000000000024,5.8,5.8,4.7,1.1,.1,.1,-1.5000000000000002,-1.7000000000000004,-1.7000000000000004,2,1.7,1.7,-4.6000000000000005,-4.6000000000000005,-3.6,.40000000000000013,.40000000000000013,1.4000000000000001,1.3,.8,.8,.30000000000000004,-.10000000000000003,-.10000000000000003,-.8,-1.1,-1.1,-1.1,.8000000000000002,1.3000000000000003,1.3000000000000003,.4,.2,.2,1.0000000000000002,1.0000000000000002,.4,-1.4000000000000001,-.4,-.4,-.7,-1.3000000000000003,-1.3000000000000003,2.4,-1.5,-1.5,-6.300000000000001,-1.5,-1.5,6.2,6.2,3.1000000000000005,1.2,.8000000000000002,.8000000000000002,-.29999999999999993,-.7999999999999999,-.7999999999999999,1,2,2,-5,-5,-3.5,-.6000000000000001,1.4,1.8,1.8,.7999999999999999,-8.326672684688674e-17,-8.326672684688674e-17,-.30000000000000004,-.30000000000000004,-.6,-.8999999999999999,-1.0000000000000002,-1.1000000000000003,-.8,-.8,-.2,1.5999999999999999,2.4000000000000004,2.4000000000000004,1.1,1.1,-.4,-1.7,-1.7,0,-.8,-1,-1,3,-1.0999999999999999,-1.0999999999999999,-6.6000000000000005,-1.5,-1.5,6,5.500000000000001,5.500000000000001,1.9,.20000000000000007,.20000000000000007,-.7,-1,-1,.7000000000000001,2.3,2.3,-4.6000000000000005,-5,-2.4,-2.4,1.2999999999999998,1.2000000000000002,1.2000000000000002,.7,.7,.8,.10000000000000009,.10000000000000009,-.8,-1.4000000000000001,-1.4000000000000001,-1.4000000000000001,0,1.4,1.4,2.1,1.3,.4,-.5,-.5,-1.3,-1,-1.5000000000000002,-1.5999999999999999,.8000000000000002,3.8,3.8,-4.6,-7.3,-7.3,1.7999999999999998,1.7999999999999998,6.1000000000000005,4.3,2.3,.9000000000000001,0,-.8,-.8,-1.3,-.1,-.1,1.4000000000000001,-3,-5.2,-5.2,-.7999999999999999,.8999999999999998,.8999999999999998,1.1,.5,.5,.3,.3,.2,-.1,-.1,-.5999999999999999,-.7,-.4,-.4,.9000000000000001,.9000000000000001,1.5999999999999999,1.3000000000000003,1.3000000000000003,.1,-1.4000000000000001,-1,-1.4000000000000001,-2,.4000000000000001,3,.8999999999999999,-4.8,-4.8,-3.6000000000000005,2.5999999999999996,2.5999999999999996,6.3,4.1,1.6];
}
var imaginary = new Array(real.length);
imaginary.fill(0);
original = real.slice(0);
///////////////////////////////////////////////////
//// OUTPUT
///////////////////////////////////////////////////
out('Original source (real array)');
out(original);
fft.calc(60, real, imaginary);
out('FFT');
out(real);
out(imaginary);
var amplitude = fft.amplitude(real, imaginary);
out("amplitude");
out(amplitude);
var power = fft.power(real, imaginary);
out("power");
out(power);
var phase = fft.phase(real, imaginary);
out("phase");
out(phase);
var frequencies = fft.frequencies(real, imaginary, 60);
out("frequencies");
out(frequencies);
var periods = fft.periods(real, imaginary, 60);
out("periods");
out(periods);
var data1 = [{
name: 'original source',
y: original
}];
var data2 = [{
name: 'real array',
y: real
}, {
name: 'imaginary array',
y: imaginary
}];
var data3 = [{
name: 'amplitude array',
x: frequencies,
y: amplitude
}, {
name: 'phase array',
x: frequencies,
y: phase
}];
Plotly.plot('stage1', data1, {
title: 'original source',
xaxis: {
title: 'index'
}
});
Plotly.plot('stage2', data2, {
title: 'FFT',
xaxis: {
title: 'index'
}
});
Plotly.plot('stage3', data3, {
title: 'amplitude, phase vs frequency',
xaxis: {
title: 'frequencies'
}
});
out('iFFT');
fft.calc(-1, real, imaginary);
out(real);
out(imaginary);
});
<script src="https://cdn.rawgit.com/hotstaff/jquery.fft/master/jquery.fft.js"></script>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<body>
<H2>Example</H2>
<div id="stage1"></div>
<div id="stage2"></div>
<div id="stage3"></div>
<div id="console"></div>
</body>
I knew there was a way!
In the third graph, you will see that the highest peak is the average BPM of the sample.
In other words: thinking about the whole sample as a complex wave, with an FFT we get a "dissection" of the frequencies of the sample.
So the strongest one is the main wave you can see with your eyes in the sample data. And it's exactly the average BPM of the sample.
$(function() {
function out(array) {
$("#console").html($("#console").html() + "<br/><br/>" + JSON.stringify(array));
//console.log(JSON.stringify(array));
}
var fft = new FFT(512);
///////////////////////////////////////////////////
//// INPUT DATA
///////////////////////////////////////////////////
// If you test sine curve, please change flag WAVEFORM_TEST to true.
var WAVEFORM_TEST = false;
var real = [];
if (WAVEFORM_TEST) {
N = 320;
k = 40;
// frequency = (k/N)
for (i = 0; i < N; i++) {
real.push(Math.sin((2 * Math.PI * k * i) / N));
}
} else {
real = [.5, .5, -.7000000000000001, -.9, -.9, -.1, .10000000000000003, .10000000000000003, -.8000000000000002, -.8000000000000002, .8999999999999999, -4, -6.3, -3.5, 1.7999999999999996, 5.199999999999999, 5.199999999999999, 5.7, 2, 2, .6, -.10000000000000003, -1.1, -2.8, -1.2999999999999998, 1.0000000000000002, 1.0000000000000002, -2.3000000000000003, -4.5, -4.5, -.20000000000000007, 1.0000000000000004, 1.0000000000000004, .8000000000000003, -.6, -.6, -.3000000000000001, .4000000000000001, .6000000000000002, .10000000000000009, -.6, -.6, -.8999999999999999, -.20000000000000004, -.20000000000000004, 1.1, 1.4, 1.0999999999999999, .6, .10000000000000006, -.6000000000000001, -.8, .19999999999999993, .19999999999999993, -1.9000000000000001, -1.5999999999999999, -1.5999999999999999, 1.6, -3.3, -6.3, -3.6, 2.1000000000000005, 5.999999999999999, 5.999999999999999, 4, 4, 1.2000000000000002, -.6000000000000001, -.6000000000000001, -.9, -.9000000000000001, -.9000000000000001, 2.5000000000000004, 2.9000000000000004, -1.1000000000000003, -1.1000000000000003, -4.3, -1.8, -1.8, .09999999999999998, .09999999999999998, 0, .9000000000000001, 1.9000000000000004, 2.4, 2.3, 1.5999999999999996, 1.5999999999999996, .30000000000000004, -.20000000000000007, -.20000000000000007, -.4, -.4, .30000000000000004, 2.6, 2.4000000000000004, .9999999999999999, -.8, -1.6, -1.6, -.5000000000000001, -1.2999999999999998, -1.2999999999999998, 2.4000000000000004, 2.1999999999999997, 2.1999999999999997, -8.100000000000001, -6.4, -.6, -.6, 6, 6, 4.4, -.49999999999999994, -.49999999999999994, -.7999999999999998, -1, -1, -1.2, 1.4000000000000004, 3.4, 3.4, -3.6, -4.199999999999999, -4.199999999999999, .7999999999999999, .7999999999999999, 1.9, .9000000000000001, .9000000000000001, .30000000000000004, 0, 0, 0, -.10000000000000003, -.7000000000000001, -.7000000000000001, .20000000000000004, .9, .9, 1.9000000000000001, 1.9000000000000001, 1.9, .9000000000000001, 0, 0, -1.6, -.7000000000000001, -.7000000000000001, -1.5, 1.5, 1.5, 3.3, 1.3877787807814457e-16, -6.7, -2.1, 3.4, 3.4, 6.300000000000001, 2.7, 2.7, .19999999999999987, .30000000000000004, .30000000000000004, .5, -.6000000000000001, 1.1, 3, .6000000000000001, -4.7, -4.7, -6.4, 0, 0, .9000000000000002, .9000000000000002, .4999999999999999, 1.4000000000000001, 1.3, 1.3, -.1, -.1, -.6000000000000001, -.8, -.30000000000000004, -.30000000000000004, .7000000000000002, .8000000000000002, .8000000000000002, 1.6, 1.0999999999999999, .5, -.1, -.1, -.8, -.5000000000000001, -1.1, -1.1, -1.2000000000000002, 4.400000000000001, 4.400000000000001, .5, -5.999999999999999, -2.9000000000000004, 3.0999999999999996, 6.300000000000001, 6.300000000000001, 6.300000000000001, 2.6999999999999997, 2.6999999999999997, 1.5, -.8000000000000002, -.8000000000000002, -1.9, .09999999999999998, 1.6, 1.6, -4.3999999999999995, -5.300000000000001, -5.300000000000001, .3999999999999999, 1.9999999999999998, 1.9999999999999998, 2.2, 2, 2, .5, -.2, -.2, -.3000000000000001, -.5, -.5, -.6, -.20000000000000004, -.20000000000000004, 1.4, 1.4, 1.5000000000000002, .9000000000000001, .8, .8, -.7000000000000001, -1.4000000000000004, -1.4000000000000004, -.9999999999999999, -1.3, -.3, -.3, 2.7, 2.7, -7.700000000000001, -6, -.2999999999999998, -.2999999999999998, 7.200000000000001, 6.300000000000001, 6.300000000000001, 2, 2, .19999999999999996, -2.2, -2.2, -.5, 2.1, 2.4, 2.4, -4.9, -3.8000000000000007, -1.3, .29999999999999993, .30000000000000004, .30000000000000004, .5, .5, .8, -.4000000000000001, -.4000000000000001, -1.4999999999999998, -1.5000000000000002, -1.5000000000000002, -1.6, -1.3000000000000003, -1.3000000000000003, -.1, 1.5999999999999999, 1.4, .9, 1.2999999999999998, 1.8, 1.6, 1.6, -1, -1, -1.5999999999999999, -2.7755575615628914e-17, -2.7755575615628914e-17, -.9000000000000001, 1.5, 2.5, 2.5, -6.699999999999999, -5.4, -5.4, 5.2, 6.7, 6.7, 2.6, .8999999999999999, .8999999999999999, .1, -.9999999999999999, -1.7, -1, 1.4, 2, -1.5, -4.3, -4.3, -.6000000000000001, .8999999999999999, .8999999999999999, .8, .8, .4, .2, .10000000000000003, .10000000000000003, -.4, -.7999999999999999, -.7999999999999999, -1.2000000000000002, -.30000000000000004, -.30000000000000004, 1.2, 1.1, 1.1, .6, .3, .3999999999999999, .3999999999999999, -.20000000000000004, -.20000000000000004, -1.1, -.30000000000000004, -.30000000000000004, -.4, -.3000000000000001, 2.6999999999999997, 1.7000000000000002, -3.7999999999999994, -6.8, -6.8, 2.1000000000000005, 2.1000000000000005, 5.8, 4.3, 4.3, 2.1, .20000000000000004, -.9, -1.7000000000000002, -2.0000000000000004, -.4, -.4, 1.1, 1.1, -2.6999999999999997, -2.7, -.29999999999999993, -.29999999999999993, 1.2999999999999998, 1.2999999999999998, .8, .09999999999999998, .2, .2, -.1, -.30000000000000004, -.30000000000000004, -.9, -.9, -.9, -.2, .7000000000000001, 1, 1, 1, 1.4, 1.4, .2, .2, -1.1, -1.4000000000000001, -1.4000000000000001, 0, -.5000000000000001, -.5000000000000001, 0, 1.9, -3.5000000000000004, -3.5000000000000004, -5.199999999999999, -5.199999999999999, .40000000000000024, 5.8, 5.8, 4.7, 1.1, .1, .1, -1.5000000000000002, -1.7000000000000004, -1.7000000000000004, 2, 1.7, 1.7, -4.6000000000000005, -4.6000000000000005, -3.6, .40000000000000013, .40000000000000013, 1.4000000000000001, 1.3, .8, .8, .30000000000000004, -.10000000000000003, -.10000000000000003, -.8, -1.1, -1.1, -1.1, .8000000000000002, 1.3000000000000003, 1.3000000000000003, .4, .2, .2, 1.0000000000000002, 1.0000000000000002, .4, -1.4000000000000001, -.4, -.4, -.7, -1.3000000000000003, -1.3000000000000003, 2.4, -1.5, -1.5, -6.300000000000001, -1.5, -1.5, 6.2, 6.2, 3.1000000000000005, 1.2, .8000000000000002, .8000000000000002, -.29999999999999993, -.7999999999999999, -.7999999999999999, 1, 2, 2, -5, -5, -3.5, -.6000000000000001, 1.4, 1.8, 1.8, .7999999999999999, -8.326672684688674e-17, -8.326672684688674e-17, -.30000000000000004, -.30000000000000004, -.6, -.8999999999999999, -1.0000000000000002, -1.1000000000000003, -.8, -.8, -.2, 1.5999999999999999, 2.4000000000000004, 2.4000000000000004, 1.1, 1.1, -.4, -1.7, -1.7, 0, -.8, -1, -1, 3, -1.0999999999999999, -1.0999999999999999, -6.6000000000000005, -1.5, -1.5, 6, 5.500000000000001, 5.500000000000001, 1.9, .20000000000000007, .20000000000000007, -.7, -1, -1, .7000000000000001, 2.3, 2.3, -4.6000000000000005, -5, -2.4, -2.4, 1.2999999999999998, 1.2000000000000002, 1.2000000000000002, .7, .7, .8, .10000000000000009, .10000000000000009, -.8, -1.4000000000000001, -1.4000000000000001, -1.4000000000000001, 0, 1.4, 1.4, 2.1, 1.3, .4, -.5, -.5, -1.3, -1, -1.5000000000000002, -1.5999999999999999, .8000000000000002, 3.8, 3.8, -4.6, -7.3, -7.3, 1.7999999999999998, 1.7999999999999998, 6.1000000000000005, 4.3, 2.3, .9000000000000001, 0, -.8, -.8, -1.3, -.1, -.1, 1.4000000000000001, -3, -5.2, -5.2, -.7999999999999999, .8999999999999998, .8999999999999998, 1.1, .5, .5, .3, .3, .2, -.1, -.1, -.5999999999999999, -.7, -.4, -.4, .9000000000000001, .9000000000000001, 1.5999999999999999, 1.3000000000000003, 1.3000000000000003, .1, -1.4000000000000001, -1, -1.4000000000000001, -2, .4000000000000001, 3, .8999999999999999, -4.8, -4.8, -3.6000000000000005, 2.5999999999999996, 2.5999999999999996, 6.3, 4.1, 1.6];
}
var imaginary = new Array(real.length);
imaginary.fill(0);
original = real.slice(real.length - 512);
///////////////////////////////////////////////////
//// OUTPUT
///////////////////////////////////////////////////
out('Original source (real array)');
out(original);
fft = new FFT(original.length, 60);
fft.forward(original);
out('FFT');
out(fft.spectrum);
time = Array(512).fill(0).map((a, b) => b / 60);
var data1 = [{
name: 'original source',
y: original,
x: time
}];
sn = Array(256).fill(0).map((a, b) => b);
fftdata = Array.from(fft.spectrum);
var data2 = [{
name: 'fft data',
y: fftdata,
x: sn //freqs
}];
sn3 = Array(256).fill(0).map((a, b) => 60 * b * 30 / 256);
var data3 = [{
name: 'BPM',
y: fftdata.slice(5, 20),
x: sn3.slice(5, 20)
}];
font = {
family: "Times New Roman",
size: 18
};
Plotly.newPlot('stage1', data1, {
title: 'Sensor data',
xaxis: {
title: 'seconds'
},
yaxis: {
title: 'signal'
},
font: font
});
Plotly.newPlot('stage2', data2, {
title: 'FFT data',
xaxis: {
title: 'bin #'
},
yaxis: {
title: 'signal'
},
font: font
});
Plotly.newPlot('stage3', data3, {
title: 'BPM',
xaxis: {
title: 'BPM'
},
yaxis: {
title: 'Amplitude'
},
font: font
});
});
<script src="https://dyns.gq/test/zfft.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/plotly.js#2.16.5/dist/plotly.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<body>
<H2>Example</H2>
<div id="stage1"></div>
<div id="stage2"></div>
<div id="stage3"></div>
<div id="console"></div>
</body>

Sort a 2D array based on a product of two indices

I'm trying to sort an array of lists, where each list contains 6 float point numbers, based on the product of the 5th and 6th values of each list.
I need this :
const name =
[ [ -0.83, 0.34, -0.44, -0.82, -0.93, -0.29 ]
, [ 0.85, 0.02, 0.32, -0.58, -0.7, 0.01 ]
, [ -0.83, -0.15, -0.47, 0.44, -0.35, 0.35 ]
, [ -0.09, -0.62, -0.19, -0.86, 0.15, 0.04 ]
, [ -0.65, -0.99, -0.41, -0.45, -0.16, 0.38 ]
, [ 0.47, 0.64, -0.15, -0.59, -0.41, 0.54 ]
, [ 0.32, -0.15, -0.97, 0.35, 0.72, -0.15 ]
]
to be this:
const name =
[ [ 0.47, 0.64, -0.15, -0.59, -0.41, 0.54 ]
, [ -0.83, -0.15, -0.47, 0.44, -0.35, 0.35 ]
, [ 0.32, -0.15, -0.97, 0.35, 0.72, -0.15 ]
, [ -0.65, -0.99, -0.41, -0.45, -0.16, 0.38 ]
, [ 0.85, 0.02, 0.32, -0.58, -0.7, 0.01 ]
, [ -0.09, -0.62, -0.19, -0.86, 0.15, 0.04 ]
, [ -0.83, 0.34, -0.44, -0.82, -0.93, -0.29 ]
]
Here is my code so far:
function product(name) {
return name.sort((a,b) => (a[4] - b[4]) * (a[5] - b[5]));
}
I think you meant to compare the products of each array, not the product of the differences.
function product(name) {
return name.sort((a, b) => (a[4] * a[5]) - (b[4] * b[5]));
}
let a = [[-0.83, 0.34, -0.44, -0.82, -0.93, -0.29],
[0.85, 0.02, 0.32, -0.58, -0.7, 0.01],
[-0.83, -0.15, -0.47, 0.44, -0.35, 0.35],
[-0.09, -0.62, -0.19, -0.86, 0.15, 0.04],
[-0.65, -0.99, -0.41, -0.45, -0.16, 0.38],
[0.47, 0.64, -0.15, -0.59, -0.41, 0.54],
[0.32, -0.15, -0.97, 0.35, 0.72, -0.15]];
console.log(product(a));
Output:
[ [ 0.47, 0.64, -0.15, -0.59, -0.41, 0.54 ],
[ -0.83, -0.15, -0.47, 0.44, -0.35, 0.35 ],
[ 0.32, -0.15, -0.97, 0.35, 0.72, -0.15 ],
[ -0.65, -0.99, -0.41, -0.45, -0.16, 0.38 ],
[ 0.85, 0.02, 0.32, -0.58, -0.7, 0.01 ],
[ -0.09, -0.62, -0.19, -0.86, 0.15, 0.04 ],
[ -0.83, 0.34, -0.44, -0.82, -0.93, -0.29 ] ]

How to replace decimal number in array with lodash

i want to replace decimal number in my array list with empty string "". How i can do that with lodash?
Here my array example:
[ 0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1, 1.05, 1.1, 1.15, 1.2, 1.25, 1.3, 1.35, 1.4, 1.45, 1.5, 1.55, 1.6, 1.65, 1.7, 1.75, 1.8, 1.85, 1.9, 1.95, 2, 2.05, 2.1, 2.15, 2.2, 2.25, 2.3, 2.35, 2.4, 2.45, 2.5, 2.55, 2.6, 2.65, 2.7, 2.75, 2.8, 2.85, 2.9, 2.95, 3, 3.05, 3.1, 3.15, 3.2, 3.25, 3.3, 3.35, 3.4, 3.45, 3.5, 3.55, 3.6, 3.65, 3.7, 3.75, 3.8, 3.85, 3.9, 3.95, 4, 4.05, 4.1, 4.15, 4.2, 4.25, 4.3, 4.35, 4.4, 4.45, 4.5, 4.55, 4.6, 4.65, 4.7, 4.75, 4.8, 4.85, 4.9, 4.95, 5, 5.05, 5.1, 5.15, 5.2, 5.25, 5.3, 5.35, 5.4, 5.45, 5.5, 5.55, 5.6, 5.65, 5.7, 5.75, 5.8, 5.85, 5.9, 5.95, 6, 6.05, 6.1, 6.15, 6.2, 6.25, 6.3, 6.35, 6.4, 6.45, 6.5, 6.55, 6.6, 6.65, 6.7, 6.75, 6.8, 6.85, 6.9, 6.95, 7, 7.05, 7.1, 7.15, 7.2, 7.25, 7.3, 7.35]
result i want:
["0", "", "", ..., "", "", "1", "", "", ..., "", "", "2", etc... ]
Just check if there is a dot after you convert to string
var data = [0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1, 1.05, 1.1, 1.15, 1.2, 1.25, 1.3, 1.35, 1.4, 1.45, 1.5, 1.55, 1.6, 1.65, 1.7, 1.75, 1.8, 1.85, 1.9, 1.95, 2, 2.05, 2.1, 2.15, 2.2, 2.25, 2.3, 2.35, 2.4, 2.45, 2.5, 2.55, 2.6, 2.65, 2.7, 2.75, 2.8, 2.85, 2.9, 2.95, 3, 3.05, 3.1, 3.15, 3.2, 3.25, 3.3, 3.35, 3.4, 3.45, 3.5, 3.55, 3.6, 3.65, 3.7, 3.75, 3.8, 3.85, 3.9, 3.95, 4, 4.05, 4.1, 4.15, 4.2, 4.25, 4.3, 4.35, 4.4, 4.45, 4.5, 4.55, 4.6, 4.65, 4.7, 4.75, 4.8, 4.85, 4.9, 4.95, 5, 5.05, 5.1, 5.15, 5.2, 5.25, 5.3, 5.35, 5.4, 5.45, 5.5, 5.55, 5.6, 5.65, 5.7, 5.75, 5.8, 5.85, 5.9, 5.95, 6, 6.05, 6.1, 6.15, 6.2, 6.25, 6.3, 6.35, 6.4, 6.45, 6.5, 6.55, 6.6, 6.65, 6.7, 6.75, 6.8, 6.85, 6.9, 6.95, 7, 7.05, 7.1, 7.15, 7.2, 7.25, 7.3, 7.35]
.map((e) => {
let str = '' + e;
return str.includes('.') ? '' : str
});
console.log(data)
Just wanted to add on answer from #charlietfl. This is another variation. I believe it has slightly higher performance, since there's no string creation operation on each tick.
var data = [0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1, 1.05, 1.1, 1.15, 1.2, 1.25, 1.3, 1.35, 1.4, 1.45, 1.5, 1.55, 1.6, 1.65, 1.7, 1.75, 1.8, 1.85, 1.9, 1.95, 2, 2.05, 2.1, 2.15, 2.2, 2.25, 2.3, 2.35, 2.4, 2.45, 2.5, 2.55, 2.6, 2.65, 2.7, 2.75, 2.8, 2.85, 2.9, 2.95, 3, 3.05, 3.1, 3.15, 3.2, 3.25, 3.3, 3.35, 3.4, 3.45, 3.5, 3.55, 3.6, 3.65, 3.7, 3.75, 3.8, 3.85, 3.9, 3.95, 4, 4.05, 4.1, 4.15, 4.2, 4.25, 4.3, 4.35, 4.4, 4.45, 4.5, 4.55, 4.6, 4.65, 4.7, 4.75, 4.8, 4.85, 4.9, 4.95, 5, 5.05, 5.1, 5.15, 5.2, 5.25, 5.3, 5.35, 5.4, 5.45, 5.5, 5.55, 5.6, 5.65, 5.7, 5.75, 5.8, 5.85, 5.9, 5.95, 6, 6.05, 6.1, 6.15, 6.2, 6.25, 6.3, 6.35, 6.4, 6.45, 6.5, 6.55, 6.6, 6.65, 6.7, 6.75, 6.8, 6.85, 6.9, 6.95, 7, 7.05, 7.1, 7.15, 7.2, 7.25, 7.3, 7.35]
.map((e) => {
return e % 1 === 0 ? e : '';
});
console.log(data)

How use database in Javascript and JSF?

I'm trying to follow the #BalusC advice here.
(I'm writing here now because it's unrelated with previous question).
So I need to get data from my database and show in chart using JavaScript, this is an example.
I'm just doing this sample so I can understand how to show some data from the server side to the client side.
My bean:
#ManagedBean(name="reportc")
#ViewScoped
public class ReportControl implements Serializable {
private static final long serialVersionUID = 3269125738504434502L;
private String[] dataAsJson = {"1.3", "2.1", "1.3", "2.2", "1.4", "2.7", "1.5", "2.1", "1.6", "2.4", "1.9", "2.1"};
public String getDataAsJson() {
Gson gson = new Gson();
return gson.toJson(dataAsJson);
}
}
To help understand the spline-plot-bands.js file.
<!DOCTYPE html>
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
...
<h:head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<h:outputScript>var data = ${reportc.dataAsJson};</h:outputScript>
<h:outputScript name="javascript/highchart/spline-plot-bands.js" />
</h:head>
<h:body>
<h:outputScript name="javascript/highchart/highcharts.js" />
<h:outputScript name="javascript/highchart/modules/exporting.js" />
<div id="container" style="width: 800px; height: 400px; margin: 0 auto"></div>
</h:body>
</html>
As you can see in the spline-plot-bands.js file.
All that matters for me is this part (I guess):
series: [{
name: 'Hestavollane',
data: [4.3, 5.1, 4.3, 5.2, 5.4, 4.7, 3.5, 4.1, 5.6, 7.4, 6.9, 7.1,
7.9, 7.9, 7.5, 6.7, 7.7, 7.7, 7.4, 7.0, 7.1, 5.8, 5.9, 7.4,
8.2, 8.5, 9.4, 8.1, 10.9, 10.4, 10.9, 12.4, 12.1, 9.5, 7.5,
7.1, 7.5, 8.1, 6.8, 3.4, 2.1, 1.9, 2.8, 2.9, 1.3, 4.4, 4.2,
3.0, 3.0]
}, {
name: 'Voll',
data: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1, 0.0, 0.3, 0.0,
0.0, 0.4, 0.0, 0.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.6, 1.2, 1.7, 0.7, 2.9, 4.1, 2.6, 3.7, 3.9, 1.7, 2.3,
3.0, 3.3, 4.8, 5.0, 4.8, 5.0, 3.2, 2.0, 0.9, 0.4, 0.3, 0.5, 0.4]
}]
How could I send something like this from my server side to this javascript ?
I think I'm close to find out how to use gson, javascript with jsf, but I still don't get it how to finish this.
Could someone help me with this ?
The JS expects a double[], but you're feeding a String[]. Fix it accordingly:
private double[] hestavollane = {
4.3, 5.1, 4.3, 5.2, 5.4, 4.7, 3.5, 4.1, 5.6, 7.4, 6.9, 7.1,
7.9, 7.9, 7.5, 6.7, 7.7, 7.7, 7.4, 7.0, 7.1, 5.8, 5.9, 7.4,
8.2, 8.5, 9.4, 8.1, 10.9, 10.4, 10.9, 12.4, 12.1, 9.5, 7.5,
7.1, 7.5, 8.1, 6.8, 3.4, 2.1, 1.9, 2.8, 2.9, 1.3, 4.4, 4.2,
3.0, 3.0
};
private double[] voll = {
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1, 0.0, 0.3, 0.0,
0.0, 0.4, 0.0, 0.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.6, 1.2, 1.7, 0.7, 2.9, 4.1, 2.6, 3.7, 3.9, 1.7, 2.3,
3.0, 3.3, 4.8, 5.0, 4.8, 5.0, 3.2, 2.0, 0.9, 0.4, 0.3, 0.5, 0.4
};
public String getDataAsJson() {
Map<String, Object> data = new HashMap<String, Object>();
data.put("hestavollane", hestavollane);
data.put("voll", voll);
return new Gson().toJson(data);
}
And edit your spline-plot-bands.js file to use it instead of the hardcoded values:
series: [{
name: 'Hestavollane',
data: data.hestavollane
}, {
name: 'Voll',
data: data.voll
}]
The key part of the linked article that you need is this:
<h:outputScript>var data = ${reportc.dataAsJson};</h:outputScript>

Store only alternative lowest and highest values from a stream into an array

I have a stream of decimal values coming from a continuous stream. These values start at a particular value going up to some maximum value then decreasing down to some minimum value(kind of like a wave). The maximum and minimum the values go are not always the same but the guaranteed thing is the values always go up then decrease then again go up and decrease and so on.
for example, the stream of values may look like:
0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.2,
1.1, 1.0, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1, 0.0, 0.1,
0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.0, 0.9, 0.8, 0.7, 0.6, 0.5,
0.4, 0.3, 0.2, 0.1, 0.0 ...
The requirement I need is to store all the alternating lowest and highest values into an array.
So in the above sample, the final result array should be:
[0.3, 1.3, 0.0, 1.1, 0.0, ...]
This is the pseudo-code for the algorithm I tried for:
var x;
var arr = [];
//listen to stream
//on stream event
void onEvent(double val) {
if (x == null) {
x = val;
}
if (val > x) {
if (arr.lastItem < val) {
arr.push(val);
}
} else {
if (arr.lastItem > val) {
arr.push(val);
}
}
x=val;
}
The final resulting arr is not the expected outcome.
What is the better solution?
You can do something like this:
const stream = [0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.2,
1.1, 1.0, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1, 0.0, 0.1,
0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.0, 0.9, 0.8, 0.7, 0.6, 0.5,
0.4, 0.3, 0.2, 0.1, 0.0
];
const output = [];
let prevValue = null;
let isGoingUp = false;
function onEvent(value) {
if (output.length < 2) {
output.push(value);
if (output.length === 2) {
isGoingUp = output[0] < output[1];
prevValue = value;
}
return;
}
if (isGoingUp) {
if (value > prevValue) {
output[output.length - 1] = value;
} else if (value < prevValue) {
output.push(value);
isGoingUp = false;
}
} else {
if (value < prevValue) {
output[output.length - 1] = value;
} else if (value > prevValue) {
output.push(value);
isGoingUp = true;
}
}
prevValue = value;
}
stream.forEach(onEvent);
console.log(output);
What this does is to keep track if the stream is going up or down (the current value is bigger or smaller than the previous) and replace the last value in the output array when the stream is going down and the current value is smaller than the last value in the output or the stream is going up and the current value is bigger.
Hopefully this can be done much simpler but this is a solution. We simply create a while loop that continues while there are still values available. We then find the min and max values then remove them from the values list. We then create a new pair of min and max values. Once we have all min and max values we map them to an array of double values as you need.
public static void main(String[] args) {
List<Double> values = new ArrayList<>(Arrays.asList(
0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.2,
1.1, 1.0, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1, 0.0, 0.1,
0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.0, 0.9, 0.8,
0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1, 0.0
));
List<Pair> pairs = new ArrayList<>();
while (!values.isEmpty()) {
Double min = values.stream().min(Double::compareTo)
.orElseThrow(IllegalStateException::new);
Double max = values.stream().max(Double::compareTo)
.orElseThrow(IllegalStateException::new);
pairs.add(new Pair(min, max));
values.remove(min);
values.remove(max);
}
double[] valuesSorted = pairs.stream()
.map(pair -> new double[] { pair.getMin(), pair.getMax() })
.flatMapToDouble(Arrays::stream)
.toArray();
}
static class Pair {
private final double min;
private final double max;
Pair(double min, double max) {
this.min = min;
this.max = max;
}
public double getMin() {
return min;
}
public double getMax() {
return max;
}
#Override
public String toString() {
return "Pair{" +
"min=" + min +
", max=" + max +
'}';
}
}
Output
[0.0, 1.3, 0.0, 1.2, 0.1, 1.2, 0.1, 1.1, 0.1, 1.1, 0.2, 1.1, 0.2, 1.0, 0.2, 1.0, 0.3, 1.0, 0.3, 1.0, 0.3, 0.9, 0.3, 0.9, 0.4, 0.9, 0.4, 0.9, 0.4, 0.8, 0.4, 0.8, 0.5, 0.8, 0.5, 0.8, 0.5, 0.7, 0.5, 0.7, 0.6, 0.7, 0.6, 0.7, 0.6, 0.6]

Categories

Resources