Exemple #1
0
        /// <summary>
        /// Computes a time-sensitive top-k aggregate using snapshot semantics based on a key selector with the provided ordering comparer.
        /// </summary>
        public IAggregate <TSource, SortedMultiSet <TSource>, List <RankedEvent <TSource> > > TopK <TOrderValue>(Expression <Func <TSource, TOrderValue> > orderer, IComparerExpression <TOrderValue> comparer, int k)
        {
            Invariant.IsNotNull(orderer, nameof(orderer));
            Invariant.IsNotNull(comparer, nameof(comparer));
            Invariant.IsPositive(k, nameof(k));
            var orderComparer = comparer.TransformInput(orderer);
            var aggregate     = new TopKAggregate <TSource>(k, orderComparer, this.Properties.QueryContainer);

            return(aggregate.SkipNulls().ApplyFilter(this.Filter));
        }
        /// <summary>
        /// Passes a truncated version of each event, where the event is truncated by a maximum event length.
        /// </summary>
        public static IStreamable <TKey, TPayload> ClipEventDuration <TKey, TPayload>(
            this IStreamable <TKey, TPayload> source,
            long limit)
        {
            Invariant.IsNotNull(source, nameof(source));
            Invariant.IsPositive(limit, nameof(limit));

            return(source.Properties.IsConstantDuration && limit < source.Properties.ConstantDurationLength.Value
                ? AlterEventDuration(source, limit)
                : new ClipByConstantStreamable <TKey, TPayload>(source, limit));
        }
        /// <summary>
        /// Changes the Vs and Ve of each event.
        /// </summary>
        /// <typeparam name="TKey">Key type of the stream</typeparam>
        /// <typeparam name="TPayload">Data type of the stream</typeparam>
        /// <param name="source">source stream</param>
        /// <param name="startTimeSelector">Function which recomputes the event start time</param>
        /// <param name="duration">Amount to alter the durations by</param>
        /// <returns>The altered stream</returns>
        public static IStreamable <TKey, TPayload> AlterEventLifetime <TKey, TPayload>(
            this IStreamable <TKey, TPayload> source,
            Expression <Func <long, long> > startTimeSelector,
            long duration)
        {
            Invariant.IsNotNull(source, nameof(source));
            Invariant.IsNotNull(startTimeSelector, nameof(startTimeSelector));
            Invariant.IsPositive(duration, nameof(duration));

            return(new AlterLifetimeStreamable <TKey, TPayload>(source, startTimeSelector, Expression.Lambda <Func <long> >(Expression.Constant(duration))));
        }
        /// <summary>
        /// Changes the Ve of each event according to the duration provided
        /// </summary>
        /// <param name="source">Source stream</param>
        /// <param name="duration"></param>
        public static IStreamable <TKey, TPayload> AlterEventDuration <TKey, TPayload>(
            this IStreamable <TKey, TPayload> source,
            long duration)
        {
            Invariant.IsNotNull(source, nameof(source));
            Invariant.IsPositive(duration, nameof(duration));

            return(source is IFusibleStreamable <TKey, TPayload> s
                ? s.FuseSetDurationConstant(duration)
                : (IStreamable <TKey, TPayload>) new AlterLifetimeStreamable <TKey, TPayload>(source, null, Expression.Lambda <Func <long> >(Expression.Constant(duration))));
        }
        /// <summary>
        /// Adjusts the lifetime of incoming events to snap the start and end time of each event to quantized boundaries.
        /// The function is similar to a hopping lifetime expression, except that all start edges are either moved
        /// earlier or stay the same, and all end edges either move later or stay the same.
        /// </summary>
        /// <typeparam name="TKey">Type of (mapping) key in the stream</typeparam>
        /// <typeparam name="TPayload">Type of payload in the stream</typeparam>
        /// <param name="source">Input stream</param>
        /// <param name="windowSize">Window size</param>
        /// <param name="period">Period (or hop size)</param>
        /// <param name="offset">Offset from the start of time</param>
        /// <returns>Result (output) stream</returns>
        public static IStreamable <TKey, TPayload> QuantizeLifetime <TKey, TPayload>(
            this IStreamable <TKey, TPayload> source,
            long windowSize,
            long period,
            long offset = 0)
        {
            Invariant.IsNotNull(source, nameof(source));
            Invariant.IsPositive(windowSize, nameof(windowSize));
            Invariant.IsPositive(period, nameof(period));

            return(new QuantizeLifetimeStreamable <TKey, TPayload>(source, windowSize, period, period, offset));
        }
Exemple #6
0
        public MultiUnionStreamable(IStreamable <TKey, TSource>[] sources, bool register = true, bool guaranteedDisjoint = false)
            : base(sources.Skip(1).Select(o => o.Properties).Aggregate(sources[0].Properties, (r, p) => r.Union(p)))
        {
            Invariant.IsNotNull(sources, "sources");
            Invariant.IsPositive(sources.Length, "sources.Length");
            Invariant.IsNotNull(sources[0], "sources[0]");

            this.Sources           = sources;
            this.registerScheduler = register;

            if (guaranteedDisjoint)
            {
                this.constructor = (l, r, b) => new DisjointUnionStreamable <TKey, TSource>(l, r, b);
            }
            else
            {
                this.constructor = (l, r, b) => new UnionStreamable <TKey, TSource>(l, r, b);
            }
        }
        /// <summary>
        /// Adjusts the lifetime of incoming events to snap the start and end time of each event to quantized boundaries,
        /// except that the start times are progressively spaced through the window.
        /// The function is similar to a hopping lifetime expression, except that all start edges are either moved
        /// earlier or stay the same, and all end edges either move later or stay the same.
        /// </summary>
        /// <typeparam name="TKey">Type of (mapping) key in the stream</typeparam>
        /// <typeparam name="TPayload">Type of payload in the stream</typeparam>
        /// <param name="source">Input stream</param>
        /// <param name="windowSize">Window size</param>
        /// <param name="period">Period (or hop size)</param>
        /// <param name="progress">Interval at which progressive results within a window are requested</param>
        /// <param name="offset">Offset from the start of time</param>
        /// <returns>Result (output) stream</returns>
        public static IStreamable <TKey, TPayload> ProgressiveQuantizeLifetime <TKey, TPayload>(
            this IStreamable <TKey, TPayload> source,
            long windowSize,
            long period,
            long progress,
            long offset = 0)
        {
            Invariant.IsNotNull(source, nameof(source));
            Invariant.IsPositive(windowSize, nameof(windowSize));
            Invariant.IsPositive(period, nameof(period));
            Invariant.IsPositive(progress, nameof(progress));
            if (period % progress != 0)
            {
                throw new ArgumentException("Progress interval must be a proper divisor of the period.");
            }
            if (period <= progress)
            {
                throw new ArgumentException("Progress interval must be strictly smaller than the period.");
            }

            return(new QuantizeLifetimeStreamable <TKey, TPayload>(source, windowSize, period, progress, offset));
        }