Skip to content

Commit

Permalink
Added use of valid samples in last chunk to display values correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffersoncasimir committed Dec 6, 2023
1 parent 64b93b5 commit 70ece73
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,13 @@ class EEGLabSeriesProvider extends Component<CProps> {
Promise.race(racers(fetchJSON, chunksURL, '/index.json')).then(
({json, url}) => {
if (json) {
const {channelMetadata, shapes, timeInterval, seriesRange} = json;
const {channelMetadata, shapes, timeInterval, seriesRange, validSamples} = json;
this.store.dispatch(
setDatasetMetadata({
chunksURL: url,
channelMetadata,
shapes,
validSamples,
timeInterval,
seriesRange,
limit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import {Group} from '@visx/group';
import {colorOrder} from '../../color';

const LineMemo = R.memoizeWith(
({amplitudeScale, filters, channelIndex, traceIndex,
chunkIndex, isStacked, DCOffset, numChannels,
numChunks, previousPoint}) =>
`${amplitudeScale},${filters.join('-')},`
({amplitudeScale, interval, filters,
channelIndex, traceIndex, chunkIndex,
isStacked, DCOffset, numChannels,
numChunks, previousPoint,
}) =>
`${amplitudeScale},${interval.join('-')},${filters.join('-')},`
+ `${channelIndex}-${traceIndex}-${chunkIndex},`
+ `${isStacked},${DCOffset},${numChannels},`
+ `${numChunks},${previousPoint}`,
Expand Down Expand Up @@ -152,7 +154,7 @@ const LineChunk = ({
top={-p0[1]}
>
<Group
transform={'translate(' + p0[0] + ' 0)' +
transform={'translate(' + p0[0] + ' 0) ' +
'scale(' + chunkLength + ' ' + chunkHeight + ')'
}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const createFetchChunksEpic = (fromState: (any) => State) => (
Rx.map(([, state]) => fromState(state)),
Rx.debounceTime(UPDATE_DEBOUNCE_TIME),
Rx.concatMap(({bounds, dataset, channels}) => {
const {chunksURL, shapes, timeInterval} = dataset;
const {chunksURL, shapes, validSamples, timeInterval} = dataset;
if (!chunksURL) {
return of();
}
Expand All @@ -123,19 +123,25 @@ export const createFetchChunksEpic = (fromState: (any) => State) => (
const shapeChunks =
shapes.map((shape) => shape[shape.length - 2]);

const chunkIntervals : chunkIntervals[] = shapeChunks
const valuesPerChunk =
shapes.map((shape) => shape[shape.length - 1]);

const chunkIntervals = shapeChunks
.map((numChunks, downsampling) => {
const recordingDuration = Math.abs(
timeInterval[1] - timeInterval[0]
);

const filledChunks = (numChunks - 1) +
(validSamples[downsampling] / valuesPerChunk[downsampling]);

const i0 =
(numChunks *
(filledChunks *
Math.floor(bounds.interval[0] - bounds.domain[0])
) / recordingDuration;

const i1 =
(numChunks *
(filledChunks *
Math.ceil(bounds.interval[1] - bounds.domain[0])
) / recordingDuration;

Expand All @@ -145,7 +151,11 @@ export const createFetchChunksEpic = (fromState: (any) => State) => (
];

return {
interval: interval,
interval:
[
Math.floor(i0),
Math.min(Math.ceil(i1), filledChunks),
],
numChunks: numChunks,
downsampling,
};
Expand All @@ -164,12 +174,16 @@ export const createFetchChunksEpic = (fromState: (any) => State) => (
const chunkPromises = R.range(...finestChunks.interval).flatMap(
(chunkIndex) => {
const numChunks = finestChunks.numChunks;

const filledChunks = (numChunks - 1) +
(validSamples[finestChunks.downsampling] / valuesPerChunk[finestChunks.downsampling]);

const chunkInterval = [
timeInterval[0] +
(chunkIndex / numChunks) *
(chunkIndex / filledChunks) *
(timeInterval[1] - timeInterval[0]),
timeInterval[0] +
((chunkIndex + 1) / numChunks) *
((chunkIndex + 1) / filledChunks) *
(timeInterval[1] - timeInterval[0]),
];
if (chunkInterval[0] <= bounds.interval[1]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export type Action =
chunksURL: string,
channelNames: string[],
shapes: number[][],
validSamples: number[],
timeInterval: [number, number],
seriesRange: [number, number],
limit: number,
Expand All @@ -46,6 +47,7 @@ export type State = {
activeEpoch: number | null,
physioFileID: number | null,
shapes: number[][],
validSamples: number[],
timeInterval: [number, number],
seriesRange: [number, number],
};
Expand All @@ -68,6 +70,7 @@ export const datasetReducer = (
offsetIndex: 1,
limit: DEFAULT_MAX_CHANNELS,
shapes: [],
validSamples: [],
timeInterval: [0, 1],
seriesRange: [-1, 2],
},
Expand Down

0 comments on commit 70ece73

Please sign in to comment.