reduce data stored in sample collection
This commit is contained in:
44
index.js
44
index.js
@@ -444,28 +444,22 @@ function collectSample() {
|
|||||||
} = frequencyOverTime[0] ?? {}
|
} = frequencyOverTime[0] ?? {}
|
||||||
const data = {
|
const data = {
|
||||||
time,
|
time,
|
||||||
frequencies: [...frequencies],
|
// frequencies: [...frequencies],
|
||||||
length,
|
length,
|
||||||
streamEnded: priorStreamEnded
|
streamEnded: priorStreamEnded
|
||||||
};
|
};
|
||||||
let hasSignal = false;
|
|
||||||
data.pairs = getChannels().map(([low, high], i) => {
|
data.pairs = getChannels().map(([low, high], i) => {
|
||||||
const lowAmp = frequencies[Math.round(low / length)];
|
const lowAmp = frequencies[Math.round(low / length)];
|
||||||
const highAmp = frequencies[Math.round(high / length)];
|
const highAmp = frequencies[Math.round(high / length)];
|
||||||
const isLow = lowAmp > AMPLITUDE_THRESHOLD;
|
|
||||||
const isHigh = highAmp > AMPLITUDE_THRESHOLD;
|
|
||||||
if(isLow || isHigh ) hasSignal = true;
|
|
||||||
return {
|
return {
|
||||||
channel: i,
|
|
||||||
lowHz: low,
|
|
||||||
highHz: high,
|
|
||||||
lowAmp,
|
lowAmp,
|
||||||
highAmp,
|
highAmp,
|
||||||
isMissing: !(isHigh || isLow),
|
|
||||||
isHigh: (isHigh && !isLow) || highAmp > lowAmp
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
data.hasSignal = hasSignal;
|
const hasSignal = data.hasSignal = data.pairs.some(p =>
|
||||||
|
p.lowAmp > AMPLITUDE_THRESHOLD ||
|
||||||
|
p.highAmp > AMPLITUDE_THRESHOLD
|
||||||
|
);
|
||||||
if(hasSignal) {
|
if(hasSignal) {
|
||||||
if(hadPriorSignal) {
|
if(hadPriorSignal) {
|
||||||
// continued bit stream
|
// continued bit stream
|
||||||
@@ -529,7 +523,7 @@ function GET_SEGMENT_BITS(streamStarted, segmentIndex) {
|
|||||||
heard: 0
|
heard: 0
|
||||||
}));
|
}));
|
||||||
samples.forEach(({pairs}) => {
|
samples.forEach(({pairs}) => {
|
||||||
pairs.forEach(({ highAmp, lowAmp, channel }) => {
|
pairs.forEach(({ highAmp, lowAmp }, channel) => {
|
||||||
sums[channel].high += highAmp;
|
sums[channel].high += highAmp;
|
||||||
sums[channel].low += lowAmp;
|
sums[channel].low += lowAmp;
|
||||||
if(highAmp > AMPLITUDE_THRESHOLD || lowAmp > AMPLITUDE_THRESHOLD) {
|
if(highAmp > AMPLITUDE_THRESHOLD || lowAmp > AMPLITUDE_THRESHOLD) {
|
||||||
@@ -929,15 +923,11 @@ function drawBitStart(ctx, color) {
|
|||||||
ctx.stroke();
|
ctx.stroke();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function hzAmplitude(hz, length, frequencies) {
|
|
||||||
var index = Math.round(hz / length);
|
|
||||||
return frequencies[index];
|
|
||||||
}
|
|
||||||
function getPercentY(percent) {
|
function getPercentY(percent) {
|
||||||
const { height } = receivedGraph;
|
const { height } = receivedGraph;
|
||||||
return (1 - percent) * height;
|
return (1 - percent) * height;
|
||||||
}
|
}
|
||||||
function drawFrequencyLineGraph(ctx, hz, color, lineWidth, dashed) {
|
function drawFrequencyLineGraph(ctx, channel, highLowIndex, color, lineWidth, dashed) {
|
||||||
const { width, height } = receivedGraph;
|
const { width, height } = receivedGraph;
|
||||||
const newest = frequencyOverTime[0].time;
|
const newest = frequencyOverTime[0].time;
|
||||||
const duration = SEGMENT_DURATION * MAX_BITS_DISPLAYED_ON_GRAPH;
|
const duration = SEGMENT_DURATION * MAX_BITS_DISPLAYED_ON_GRAPH;
|
||||||
@@ -948,10 +938,10 @@ function drawFrequencyLineGraph(ctx, hz, color, lineWidth, dashed) {
|
|||||||
}
|
}
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
for(let i = 0; i < frequencyOverTime.length; i++) {
|
for(let i = 0; i < frequencyOverTime.length; i++) {
|
||||||
const {frequencies, time, length} = frequencyOverTime[i];
|
const {pairs, time} = frequencyOverTime[i];
|
||||||
const x = getTimeX(time, newest);
|
const x = getTimeX(time, newest);
|
||||||
if(x === -1) continue;
|
if(x === -1) continue;
|
||||||
const amplitude = hzAmplitude(hz, length, frequencies);
|
const amplitude = pairs[channel][highLowIndex];
|
||||||
const y = getPercentY(amplitude / MAX_DATA);
|
const y = getPercentY(amplitude / MAX_DATA);
|
||||||
if(i === 0) ctx.moveTo(x, y); else ctx.lineTo(x, y);
|
if(i === 0) ctx.moveTo(x, y); else ctx.lineTo(x, y);
|
||||||
}
|
}
|
||||||
@@ -960,7 +950,7 @@ function drawFrequencyLineGraph(ctx, hz, color, lineWidth, dashed) {
|
|||||||
ctx.setLineDash([]);
|
ctx.setLineDash([]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function drawFrequencyDots(ctx, hz, color) {
|
function drawFrequencyDots(ctx, channel, highLowIndex, color) {
|
||||||
const newest = frequencyOverTime[0].time;
|
const newest = frequencyOverTime[0].time;
|
||||||
const radius = 2;
|
const radius = 2;
|
||||||
const border = 0.5;
|
const border = 0.5;
|
||||||
@@ -969,10 +959,10 @@ function drawFrequencyDots(ctx, hz, color) {
|
|||||||
ctx.lineWidth = border;
|
ctx.lineWidth = border;
|
||||||
const fullCircle = 2 * Math.PI;
|
const fullCircle = 2 * Math.PI;
|
||||||
for(let i = 0; i < frequencyOverTime.length; i++) {
|
for(let i = 0; i < frequencyOverTime.length; i++) {
|
||||||
const {frequencies, time, length} = frequencyOverTime[i];
|
const {pairs, time} = frequencyOverTime[i];
|
||||||
const x = getTimeX(time, newest);
|
const x = getTimeX(time, newest);
|
||||||
if(x === -1) continue;
|
if(x === -1) continue;
|
||||||
const amplitude = hzAmplitude(hz, length, frequencies);
|
const amplitude = pairs[channel][highLowIndex];
|
||||||
const y = getPercentY(amplitude / MAX_DATA);
|
const y = getPercentY(amplitude / MAX_DATA);
|
||||||
|
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
@@ -1132,10 +1122,12 @@ function drawFrequencyData() {
|
|||||||
drawBitDurationLines(ctx, 'rgba(255, 255, 0, .25)');
|
drawBitDurationLines(ctx, 'rgba(255, 255, 0, .25)');
|
||||||
drawBitStart(ctx, 'green');
|
drawBitStart(ctx, 'green');
|
||||||
const frequencies = getChannels();
|
const frequencies = getChannels();
|
||||||
frequencies.forEach(([low, high], i) => {
|
const high = 1;
|
||||||
const hue = channelHue(i, frequencies.length);
|
const low = 0
|
||||||
drawFrequencyLineGraph(ctx, high, `hsl(${hue}, 100%, 50%)`, 2, false);
|
frequencies.forEach((v, channel) => {
|
||||||
drawFrequencyLineGraph(ctx, low, `hsl(${hue}, 100%, 25%)`, 1, true);
|
const hue = channelHue(channel, frequencies.length);
|
||||||
|
drawFrequencyLineGraph(ctx, channel, high, `hsl(${hue}, 100%, 50%)`, 2, false);
|
||||||
|
drawFrequencyLineGraph(ctx, channel, low, `hsl(${hue}, 100%, 25%)`, 1, true);
|
||||||
});
|
});
|
||||||
drawSegmentIndexes(ctx);
|
drawSegmentIndexes(ctx);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user