Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip operation #102

Open
asubb opened this issue Feb 14, 2021 · 0 comments
Open

Skip operation #102

asubb opened this issue Feb 14, 2021 · 0 comments

Comments

@asubb
Copy link
Member

asubb commented Feb 14, 2021

Sometimes it might be convenient to shift the beginning of the stream by skipping certain amount of time.

Reference implementation for Sample type for finite stream, with added proper sample measurement it would be easy to generalize the implementation:

@Serializable
class SkipStreamParams(
    val timeToSkip: Long,
    val timeUnit: TimeUnit
) : BeanParams()

class SkipStream(
    override val input: FiniteStream<Sample>,
    override val parameters: SkipStreamParams,
) : AbstractOperationBeanStream<Sample, Sample>(input), SinglePartitionBean, SingleBean<Sample>, FiniteStream<Sample> {

    override fun operationSequence(input: Sequence<Sample>, sampleRate: Float): Sequence<Sample> {
        val toSkipSamplesCount = timeToSampleIndexCeil(parameters.timeToSkip, parameters.timeUnit, sampleRate).toInt()
        return input.drop(toSkipSamplesCount)
    }

    override fun samplesCount(): Long = input.samplesCount()

    override fun length(timeUnit: TimeUnit): Long = input.length()
}

fun FiniteStream<Sample>.skip(timeToSkip: Long, timeUnit: TimeUnit): FiniteStream<Sample> =
    SkipStream(this, SkipStreamParams(timeToSkip, timeUnit))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant