Mercurial > hg > ugly-duckling
changeset 302:c6dd5752f7f7
Change to new StreamingResponse type.
author | Lucas Thompson <dev@lucas.im> |
---|---|
date | Fri, 12 May 2017 01:40:21 +0100 |
parents | fff3a4fba992 |
children | dc415a620b15 |
files | src/app/services/feature-extraction/FeatureReducers.ts |
diffstat | 1 files changed, 13 insertions(+), 84 deletions(-) [+] |
line wrap: on
line diff
--- a/src/app/services/feature-extraction/FeatureReducers.ts Wed May 10 17:45:06 2017 +0100 +++ b/src/app/services/feature-extraction/FeatureReducers.ts Fri May 12 01:40:21 2017 +0100 @@ -1,15 +1,12 @@ /** * Created by lucast on 26/04/2017. */ -import {StreamingResponse} from 'piper/StreamingService'; -import {Feature, FeatureList} from 'piper/Feature'; -import {SampleType} from 'piper'; -import { - VectorFeatures, MatrixFeatures, TrackFeature, TrackFeatures -} from "piper/HigherLevelUtilities"; +import {StreamingResponse} from "piper/StreamingService"; export const arrayReducer = <T>(acc: T[], val: T[]): T[] => { - acc.push.apply(acc, val); + for (let i = 0, len = val.length; i < len; ++i) { + acc.push(val[i]); + } return acc; }; @@ -26,80 +23,12 @@ }; export const streamingResponseReducer = (acc: StreamingResponse, - val: StreamingResponse, - i: number): StreamingResponse => - { - if (acc.features.shape !== val.features.shape) { - throw new Error(`Unexpected feature shape ${val.features.shape} (expected ${acc.features.shape})`); - } - - acc.processedBlockCount = val.processedBlockCount; - - const isOneSamplePerStep = acc.outputDescriptor.configured.sampleType === - SampleType.OneSamplePerStep; - - let incoming, collected; - - console.log("i = " + i + ", shape = " + acc.features.shape + ", count = " + acc.processedBlockCount); - - switch (acc.features.shape) { - - case "vector": - incoming = val.features.collected as VectorFeatures; - collected = acc.features.collected as VectorFeatures; - if (isOneSamplePerStep) { - // for one sample per step vectors we know there will be - // totalBlockCount number of samples - so pre-allocate the - // Float32Array when we know the totalBlockCount (after - // receiving the first feature) - if (i === 1) { - const newBlock = new Float32Array(acc.totalBlockCount); - newBlock[0] = collected.data[0]; - collected.data = newBlock; - } - collected.data = inPlaceTypedArrayReducer( - collected.data, - incoming.data, - i - ); - } else { - // if not OneSamplePerStep we have to make a new array each time - collected.data = typedArrayReducer( - collected.data, - incoming.data - ); - } - break; - - case "matrix": - incoming = val.features.collected as MatrixFeatures; - collected = acc.features.collected as MatrixFeatures; - collected.data = arrayReducer<Float32Array>( - collected.data, - incoming.data - ); - break; - - case "list": - incoming = val.features.collected as FeatureList; - collected = acc.features.collected as FeatureList; - acc.features.collected = arrayReducer<Feature>( - collected, - incoming - ); - break; - - case "tracks": - incoming = val.features.collected as TrackFeatures; - collected = acc.features.collected as TrackFeatures; - acc.features.collected = arrayReducer<TrackFeature>( - collected, incoming - ); - break; - - default: - throw new Error('Invalid feature output. Aborting'); - } - - return acc; - }; + val: StreamingResponse): + StreamingResponse => { + acc.progress = val.progress; + if (val.configuration) { + acc.configuration = val.configuration; + } + arrayReducer(acc.features, val.features); + return acc; +};