public static Expression GetReduceExpression(string query, Type itemType) { EvoQLBuilder builder = new EvoQLBuilder(query); ParameterExpression parameterExpression; EvoQLExpression parse; var filterexpr = builder.GetFilterExpression(out parse, out parameterExpression); var get = parse.Tree as GetExpression; //var interval = get.Interval == null ? null : new IntervalTypes?( TryParseEnum(get.Interval, IntervalTypes.None) ); //var select = TryParseEnum(get.Select, SelectTypes.Count); var groupBySortDirection = get.GroupByDescending.HasValue ? (get.GroupByDescending == true ? new OrderTypes?(OrderTypes.Descending): new OrderTypes?(OrderTypes.Ascending)) : null; var groupOverSortDirection = get.GroupOverDescending.HasValue ? (get.GroupOverDescending == true ? new OrderTypes?(OrderTypes.Descending) : new OrderTypes?(OrderTypes.Ascending)) : null; var dimensions = new ReduceDimension[] { new ReduceDimension { GroupBy = get.GroupBy, OrderBy = new SelectDescriptor { SourcePath = get.GroupByOrderBy }, Order = groupBySortDirection, Take = get.GroupByTake, Interval = get.GroupByInterval }, new ReduceDimension { GroupBy = get.GroupOver, OrderBy = new SelectDescriptor { SourcePath = get.GroupOverOrderBy }, Order = groupOverSortDirection, Take = get.GroupOverTake, Interval = get.GroupOverInterval } }; //foreach (var d in dimensions) if (d.GroupBy == GroupByTypes.Date) d.Interval = interval; var aggregate = get.Select == "Count" ? "Count" : "Sum"; var sourcePath = get.Select == "Count" ? null : get.Select; var reduceexpr = ReduceExpressionGeneration.GetMapreduceExpression(filterexpr, new SelectDescriptor { TargetPath = get.Select, SourcePath = sourcePath, Aggregate = aggregate }, dimensions, itemType); return(reduceexpr); }
/// <summary> /// transforms 2D matrix to 1D row or column vector by taking sum, minimum, maximum or mean value over all the rows /// </summary> /// <param name="src">The source 2D matrix</param> /// <param name="dst">The destination vector. /// Its size and type is defined by dim and dtype parameters</param> /// <param name="dim">The dimension index along which the matrix is reduced. /// 0 means that the matrix is reduced to a single row and 1 means that the matrix is reduced to a single column</param> /// <param name="rtype"></param> /// <param name="dtype">When it is negative, the destination vector will have /// the same type as the source matrix, otherwise, its type will be CV_MAKE_TYPE(CV_MAT_DEPTH(dtype), mtx.channels())</param> public static void Reduce(InputArray src, OutputArray dst, ReduceDimension dim, ReduceTypes rtype, int dtype) { if (src == null) throw new ArgumentNullException("src"); if (dst == null) throw new ArgumentNullException("dst"); src.ThrowIfDisposed(); dst.ThrowIfNotReady(); NativeMethods.core_reduce(src.CvPtr, dst.CvPtr, (int)dim, (int)rtype, dtype); dst.Fix(); GC.KeepAlive(src); }
/// <summary> /// transforms 2D matrix to 1D row or column vector by taking sum, minimum, maximum or mean value over all the rows /// </summary> /// <param name="dim">The dimension index along which the matrix is reduced. /// 0 means that the matrix is reduced to a single row and 1 means that the matrix is reduced to a single column</param> /// <param name="rtype"></param> /// <param name="dtype">When it is negative, the destination vector will have /// the same type as the source matrix, otherwise, its type will be CV_MAKE_TYPE(CV_MAT_DEPTH(dtype), mtx.channels())</param> /// <returns></returns> public Mat Reduce(ReduceDimension dim, ReduceOperation rtype, int dtype) { var dst = new Mat(); Cv2.Reduce(this, dst, dim, rtype, dtype); return dst; }