/// <summary> /// Expands the view to use a time bound window. Time bound windows are sliding windows that extend the /// specified time interval into the past based on the system time. Provide a time period as parameter. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="esperQuery">The esper query.</param> /// <param name="timeSpan">The time span.</param> /// <param name="batched">if set to <c>true</c> [batched].</param> /// <returns></returns> public static EsperQuery <T> WithDuration <T>(this EsperQuery <T> esperQuery, TimeSpan timeSpan, bool batched = false) { var timePeriodExpression = timeSpan.ToTimePeriodExpression(); var windowName = batched ? "time_batch" : "time"; return(esperQuery.FilterView(() => View.Create("win", windowName, timePeriodExpression))); }
/// <summary> /// Expands the view to keep a sliding window of events. This view is a moving (sliding) length /// window extending the specified number of elements into the past. The view takes a single /// expression as a parameter providing a numeric size value that defines the window size. /// <para/> /// If batch is specified, then the window buffers events (tumbling window) and releases them /// when the given number of events has been collected. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="esperQuery">The esper query.</param> /// <param name="length">The length.</param> /// <param name="batched">if set to <c>true</c> [batched].</param> /// <returns></returns> public static EsperQuery <T> WithLength <T>(this EsperQuery <T> esperQuery, int length, bool batched = false) { var windowName = batched ? "length_batch" : "length"; return(esperQuery.FilterView(() => View.Create("win", windowName, new ConstantExpression(length)))); }
/// <summary> /// Expands the view to use a time and length bound window. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="esperQuery">The esper query.</param> /// <param name="timeSpan">The time span.</param> /// <param name="length">The length.</param> /// <param name="flowControlKeywords">The flow control keywords.</param> /// <returns></returns> public static EsperQuery <T> WithDurationAndLength <T>(this EsperQuery <T> esperQuery, TimeSpan timeSpan, int length, string flowControlKeywords = null) { var timePeriodExpression = timeSpan.ToTimePeriodExpression(); var lengthExpression = new ConstantExpression(length); if (flowControlKeywords == null) { return(esperQuery.FilterView(() => View.Create("win", "time_length_batch", timePeriodExpression, lengthExpression))); } // we want to take this apart and turn this into something people can use without having to know // the keywords. an enumeration might work well here with the values being accepted as params on // function call. var flowControlExpression = new ConstantExpression(flowControlKeywords); return(esperQuery.FilterView(() => View.Create("win", "time_length_batch", timePeriodExpression, lengthExpression, flowControlExpression))); }
/// <summary> /// Generates a view that groups events into sub-views by the value returned by the /// combination of values returned by a list of properties. /// <para/> /// The properties return one or more group keys, by which the view creates sub-views for each distinct group key. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="esperQuery">The esper query.</param> /// <param name="properties">The property or expression.</param> /// <returns></returns> public static EsperQuery <T> GroupData <T>(this EsperQuery <T> esperQuery, params string[] properties) { if (properties == null) { throw new ArgumentException("at least one property must be provided"); } return(esperQuery.FilterView(() => View.Create("std", "group", properties.Select(p => new PropertyValueExpression(p)).Cast <Expression>().ToArray()))); }
/// <summary> /// Generates a view that calculates univariate statistics on a numeric expression. The view takes a /// single value property as a parameter plus any number of optional additional properties to return properties /// of the last event. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="esperQuery">The esper query.</param> /// <param name="properties">The property or expression.</param> /// <returns></returns> public static EsperQuery <UnivariateStatistics> Univariate <T>(this EsperQuery <T> esperQuery, params string[] properties) { if (properties == null || properties.Length < 1) { throw new ArgumentException("at least one property must be provided"); } return(esperQuery.FilterView <T, UnivariateStatistics>(() => View.Create("stat", "uni", properties.Select(p => new PropertyValueExpression(p)).Cast <Expression>().ToArray()))); }
/// <summary> /// Generates a view that calculates the weighted average given a property returning values to compute the average /// for and a property returning weight. The view takes two value properties as parameters plus any number of optional /// additional properties to return properties of the last event. The value expressions must return numeric values. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="esperQuery">The esper query.</param> /// <param name="properties">The property or expression.</param> /// <returns></returns> public static EsperQuery <CorrelationStatistics> WeightedAverage <T>(this EsperQuery <T> esperQuery, params string[] properties) { if (properties == null || properties.Length < 2) { throw new ArgumentException("at least two property must be provided"); } return(esperQuery.FilterView <T, CorrelationStatistics>(() => View.Create("stat", "weighted_average", properties.Select(p => new PropertyValueExpression(p)).Cast <Expression>().ToArray()))); }
/// <summary> /// Generates a view that includes only the most recent among events having the same value for /// the result of the sepcified list of properties. /// <para /> /// This view acts as a length window of size 1 for each distinct value returned by a property, or combination /// of values returned by multiple properties. It thus posts as old events the prior event of the same value(s), /// if any. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="esperQuery">The esper query.</param> /// <param name="expressions">The expressions.</param> /// <returns></returns> /// <exception cref="System.ArgumentException">at least one property must be provided</exception> public static EsperQuery <T> Unique <T>(this EsperQuery <T> esperQuery, params System.Linq.Expressions.Expression <Func <T, object> >[] expressions) { if (expressions == null) { throw new ArgumentException("at least one property must be provided"); } return(esperQuery.FilterView(() => View.Create("std", "unique", expressions.Select(e => LinqToSoda.LinqToSodaExpression(e)).ToArray()))); }
/// <summary> /// Generates a view that sorts by values returned by the specified expression or list of expressions and keeps /// only the top (or bottom) events up to the given size. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="esperQuery">The esper query.</param> /// <param name="size">The size.</param> /// <param name="sortCriteria">The sort criteria.</param> /// <returns></returns> /// <exception cref="System.ArgumentException">at least one property must be provided</exception> public static EsperQuery <T> Sorted <T>(this EsperQuery <T> esperQuery, int size, params SortCriteria[] sortCriteria) { if (sortCriteria == null || sortCriteria.Length < 1) { throw new ArgumentException("at least one sort criteria must be provided"); } var expressionList = new List <Expression>(); expressionList.Add( new ConstantExpression(size)); expressionList.AddRange( sortCriteria.Select(s => s.ToSodaExpression())); return(esperQuery.FilterView(() => View.Create("ext", "sort", expressionList))); }
/// <summary> /// Generates a view retains only the most recent among events having the same value for the criteria /// expression(s), sorted by sort criteria expressions and keeps only the top events up to the given size. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="esperQuery">The esper query.</param> /// <param name="uniqueProperties">The unique properties.</param> /// <param name="size">The size.</param> /// <param name="sortCriteria">The sort criteria.</param> /// <returns></returns> /// <exception cref="System.ArgumentException">at least one property must be provided</exception> public static EsperQuery <T> Ranked <T>(this EsperQuery <T> esperQuery, IEnumerable <string> uniqueProperties, int size, params SortCriteria[] sortCriteria) { if (uniqueProperties == null || uniqueProperties.Count() < 1) { throw new ArgumentException("at least one unique property must be provided"); } if (sortCriteria == null || sortCriteria.Length < 1) { throw new ArgumentException("at least one sort criteria must be provided"); } var expressionList = new List <Expression>(); expressionList.AddRange( uniqueProperties.Select(p => new PropertyValueExpression(p)).Cast <Expression>()); expressionList.Add( new ConstantExpression(size)); expressionList.AddRange( sortCriteria.Select(s => s.ToSodaExpression())); return(esperQuery.FilterView(() => View.Create("ext", "rank", expressionList))); }
/// <summary> /// Generates a view that retains only the first arriving event. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="esperQuery">The esper query.</param> /// <returns></returns> public static EsperQuery <T> First <T>(this EsperQuery <T> esperQuery) { return(esperQuery.FilterView(() => View.Create("std", "firstevent"))); }
/// <summary> /// Expands the view to keep the first Count events. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="esperQuery">The esper query.</param> /// <param name="length">The length.</param> /// <returns></returns> public static EsperQuery <T> KeepFirst <T>(this EsperQuery <T> esperQuery, int length) { return(esperQuery.FilterView(() => View.Create("win", "firstlength", new ConstantExpression(length)))); }
/// <summary> /// Generates a view that orders events that arrive out-of-order, using timestamp-values /// provided by an expression, and by comparing that timestamp value to engine system time. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="esperQuery">The esper query.</param> /// <param name="property">The property to use for the timestamp.</param> /// <param name="timePeriod">the time period specifying the time interval that an arriving event should maximally be held, in order to consider older events arriving at a later time</param> /// <returns></returns> /// <exception cref="System.ArgumentException">at least one property must be provided</exception> public static EsperQuery <T> TimeOrdered <T>(this EsperQuery <T> esperQuery, string property, TimeSpan timePeriod) { return(esperQuery.FilterView(() => View.Create("ext", "time_order", new PropertyValueExpression(property), timePeriod.ToTimePeriodExpression()))); }
/// <summary> /// Expands the view to keep events that occur within the specified duration. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="esperQuery">The esper query.</param> /// <param name="duration">The duration.</param> /// <returns></returns> public static EsperQuery <T> KeepFirst <T>(this EsperQuery <T> esperQuery, TimeSpan duration) { var timePeriodExpression = duration.ToTimePeriodExpression(); return(esperQuery.FilterView(() => View.Create("win", "firsttime", timePeriodExpression))); }
/// <summary> /// Expands the view to keep events (tumbling window) until the given expression is satisfied. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="esperQuery">The esper query.</param> /// <param name="expression">The expression.</param> /// <returns></returns> public static EsperQuery <T> KeepUntil <T>(this EsperQuery <T> esperQuery, System.Linq.Expressions.Expression <Func <T, bool> > expression) { return(esperQuery.FilterView(() => View.Create("win", "expr_batch", LinqToSoda.LinqToSodaExpression(expression)))); }
/// <summary> /// Generates a view that counts the number of events received from a stream or view plus /// any additional event properties or expression values listed as parameters. The count is /// then output to the observer. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="esperQuery">The esper query.</param> /// <returns></returns> public static EsperQuery <T> Counting <T>(this EsperQuery <T> esperQuery) { return(esperQuery.FilterView(() => View.Create("std", "size"))); }
/// <summary> /// Expands the view to keep all events. The view does not remove events from the /// data window, unless used with a named window and the on delete clause. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="esperQuery">The esper query.</param> /// <returns></returns> public static EsperQuery <T> KeepAll <T>(this EsperQuery <T> esperQuery) { return(esperQuery.FilterView(() => View.Create("win", "keepall"))); }
/// <summary> /// Expands the view to use a time-accumulating. This data window view is a specialized moving (sliding) /// time window that differs from the regular time window in that it accumulates events until no more events /// arrive within a given time interval, and only then releases the accumulated events as a remove stream. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="esperQuery">The esper query.</param> /// <param name="timeSpan">The time span.</param> /// <returns></returns> public static EsperQuery <T> WithAccumlation <T>(this EsperQuery <T> esperQuery, TimeSpan timeSpan) { var timePeriodExpression = timeSpan.ToTimePeriodExpression(); return(esperQuery.FilterView(() => View.Create("win", "time_accum", timePeriodExpression))); }