예제 #1
0
 /// <summary> Clears all the previously loaded information, such as the default values </summary>
 public void Clear()
 {
     Items.ClearAll();
     Aggregations.ClearAll();
     WebContent.Clear();
     Results.ClearAll();
 }
예제 #2
0
        private string ToSql(ISqlFormatter sql, IList <IColumn> select,
                             IFilterParameters filterParams, IEnumerable <Filter> outerFilters,
                             long skip, int take)
        {
            if (Aggregations.Count == 1)
            {
                return(Aggregations[0].ToSql(sql, select, outerFilters.Concat(Filters), filterParams, OrderBy, skip, take));
            }

            var ordering = "a0.Value0 desc";

            if (select != null && OrderBy.Count != 0)
            {
                ordering = string.Join(", ", OrderBy.Select(FindOrderingColumn));
            }

            return(_aggregatedTemplate(new
            {
                skipAndTake = sql.SkipAndTake(skip, take),
                Aggregations = Aggregations.Select(x =>
                                                   x.ToSql(sql, select, outerFilters.Concat(Filters), filterParams)),
                Select = select,
                ordering
            }));
        }
 private static HtmlBuilder Contents(
     this HtmlBuilder hb,
     Context context,
     SiteSettings ss,
     View view)
 {
     if (view.RequestSearchCondition(ss: ss))
     {
         return(hb.Span(
                    css: "label",
                    action: () => hb
                    .Text(text: Displays.NoDataSearchCondition(context: context))));
     }
     else
     {
         var aggregations = new Aggregations(
             context: context,
             ss: ss,
             view: view);
         return(aggregations?.TotalCount != 0
             ? hb
                .Total(
                    context: context,
                    aggregations: aggregations)
                .Overdue(
                    context: context,
                    aggregations: aggregations)
                .Parts(
                    context: context,
                    ss: ss,
                    aggregations: aggregations)
             : hb.Span(css: "label", action: () => hb
                       .Text(text: Displays.NoData(context: context))));
     }
 }
예제 #4
0
 /// <inheritdoc />
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         if (Type != null)
         {
             hashCode = hashCode * 59 + Type.GetHashCode();
         }
         if (Enabled != null)
         {
             hashCode = hashCode * 59 + Enabled.GetHashCode();
         }
         if (Groups != null)
         {
             hashCode = hashCode * 59 + Groups.GetHashCode();
         }
         if (GroupsArray != null)
         {
             hashCode = hashCode * 59 + GroupsArray.GetHashCode();
         }
         if (Aggregations != null)
         {
             hashCode = hashCode * 59 + Aggregations.GetHashCode();
         }
         if (GroupsSrc != null)
         {
             hashCode = hashCode * 59 + GroupsSrc.GetHashCode();
         }
         return(hashCode);
     }
 }
예제 #5
0
        /**
         * Attempts to cast a given INode into an Aggregation.
         * Resources that have an aggregation type as their rdf:type
         * are recognized as well-formed aggregations.
         * @param resource  the INode to cast
         * @return the Aggregation or null if INode is not a well-formed aggregation
         */
        public static IAggregation asAggregation(IResource resource)
        {
            if (resource == null)
            {
                return(null);
            }
            IEnumerator <IResource> it = resource.getObjects(RDF.PropertyType).GetEnumerator();

            //JenaUtil.setGraphReadOptimization(true);
            try
            {
                while (it.MoveNext())
                {
                    IResource type = it.Current;
                    if (type.isUri())
                    {
                        if (Aggregations.getName((IResource)type) != null)
                        {
                            it.Dispose();
                            return(new AggregationImpl(resource, resource.getModel()));
                        }
                    }
                }
            }
            finally
            {
                //JenaUtil.setGraphReadOptimization(false);
            }
            return(null);
        }
예제 #6
0
 private static HtmlBuilder Total(this HtmlBuilder hb, Aggregations aggregations)
 {
     return(hb
            .Span(css: "label", action: () => hb
                  .Text(text: Displays.Quantity()))
            .Span(css: "data", action: () => hb
                  .Text(text: aggregations.TotalCount.ToString())));
 }
예제 #7
0
        /// <summary>
        /// 別の集団を選択する
        /// <paramref name="aggregationName"/>集団が存在しない場合は新しく生成する
        /// </summary>
        /// <param name="aggregationName">集団名</param>
        public static void ChangeAggregation(string aggregationName)
        {
            if (HasAggregation(aggregationName) == false)
            {
                Aggregations.Add(aggregationName, new Aggregation(null, aggregationName));
            }

            CurrentAggregationName = aggregationName;
        }
예제 #8
0
        /// <summary>
        /// 集団を消去する
        /// </summary>
        /// <param name="aggregationName">集団名</param>
        /// <returns>消去に成功したかどうか</returns>
        public static bool DeleteAggregation(string aggregationName)
        {
            if (aggregationName == DefaultAggregationName)
            {
                return(false);
            }

            return(Aggregations.Remove(aggregationName));
        }
        private static HtmlBuilder Parts(
            this HtmlBuilder hb, Context context, SiteSettings ss, Aggregations aggregations)
        {
            var allowedColumns = Permissions.AllowedColumns(ss);

            aggregations.AggregationCollection
            .Where(o => o.Target.IsNullOrEmpty() || allowedColumns.Contains(o.Target))
            .Where(o => o.GroupBy == "[NotGroupBy]" || allowedColumns.Contains(o.GroupBy))
            .Where(o => o.Data.Count > 0)
            .ForEach(aggregation =>
            {
                var html    = string.Empty;
                var groupBy = ss.GetColumn(
                    context: context,
                    columnName: aggregation.GroupBy);
                var targetColumn = ss.GetColumn(
                    context: context,
                    columnName: aggregation.Target);
                var linkedLabelHash = LinkedLabelHash(
                    context: context,
                    ss: ss,
                    groupBy: groupBy,
                    aggregation: aggregation);
                if (aggregation.Data.Count > 0)
                {
                    hb.GroupBy(
                        context: context,
                        groupBy: groupBy,
                        targetColumn: targetColumn,
                        aggregation: aggregation);
                }
                aggregation.Data.OrderByDescending(o => o.Value).ForEach(data =>
                                                                         hb.LabelValue(
                                                                             label: groupBy != null
                                ? Label(
                                                                                 context: context,
                                                                                 groupBy: groupBy,
                                                                                 selectedValue: data.Key,
                                                                                 linkedLabelHash: linkedLabelHash)
                                : string.Empty,
                                                                             value: (targetColumn != null
                                ? targetColumn.Display(
                                                                                         context: context,
                                                                                         value: data.Value)
                                : data.Value.ToString()) +
                                                                             (aggregation.Type != Aggregation.Types.Count
                                        ? targetColumn?.Unit
                                        : string.Empty),
                                                                             bold: Bold(
                                                                                 groupBy: groupBy,
                                                                                 key: data.Key,
                                                                                 linkedLabelHash: linkedLabelHash),
                                                                             attributes: new HtmlAttributes()
                                                                             .Attributes(ss, aggregation, groupBy, data.Key)));
            });
            return(hb);
        }
예제 #10
0
        override public void Print(ISparqlPrinter p)
        {
            IVariable asVar = getAs();

            if (asVar != null)
            {
                p.print("(");
            }

            INode  aggType = this.getObject(RDF.PropertyType);
            String aggName = Aggregations.getName(aggType);

            p.printKeyword(aggName);
            p.print("(");

            if (isDistinct())
            {
                p.print("DISTINCT ");
            }

            Triple exprS = this.getProperty(SP.PropertyExpression);

            if (exprS != null && !(exprS.Object is ILiteralNode))
            {
                IResource r    = Resource.Get(exprS.Object, getModel());
                IResource expr = SPINFactory.asExpression(r);
                if (expr is IPrintable)
                {
                    ((IPrintable)expr).Print(p);
                }
                else
                {
                    p.printURIResource(r);
                }
            }
            else
            {
                p.print("*");
            }
            String separator = getString(SP.PropertySeparator);

            if (separator != null)
            {
                p.print("; ");
                p.printKeyword("SEPARATOR");
                p.print("=''"); //"='" + DatasetUtil.escapeString(separator) + "'");
            }
            if (asVar != null)
            {
                p.print(") ");
                p.printKeyword("AS");
                p.print(" ");
                p.print(asVar.ToString());
            }
            p.print(")");
        }
예제 #11
0
        public void Return_the_newest_points_first_and_include_a_GROUP_BY_time_clause()
        {
            var query = InfluxQuery.From(h2o_feet)
                        .Select(f => new { mean = Aggregations.MEAN(f.water_level) })
                        .Where("time >= '2015-08-18T00:00:00Z' AND time <= '2015-08-18T00:42:00Z'")
                        .GroupBy(TimeSpan.FromMinutes(12))
                        .OrderByTimeDesc();

            query.Statement.Text.ShouldBe("SELECT MEAN(water_level) AS mean FROM h2o_feet WHERE time >= '2015-08-18T00:00:00Z' AND time <= '2015-08-18T00:42:00Z' GROUP BY time(12m) ORDER BY time DESC");
        }
예제 #12
0
        public AggregationFilterModel <TParameters> FilterModelFor(Expression <Func <TParameters, string> > expression)
        {
            var filterName = GetFilterNameFrom(expression);

            if (Aggregations.ContainsKey(filterName) && Aggregations[filterName] is AggregationFilterModel <TParameters> p)
            {
                return(p);
            }
            throw new ArgumentOutOfRangeException(nameof(filterName), filterName, "Unable to find filter with the given name");
        }
예제 #13
0
 private static HtmlBuilder Overdue(this HtmlBuilder hb, Aggregations aggregations)
 {
     return(aggregations.OverdueCount > 0
         ? hb
            .Span(css: "label overdue", action: () => hb
                  .Text(text: Displays.Overdue()))
            .Span(css: "data overdue", action: () => hb
                  .Text(text: aggregations.OverdueCount.ToString()))
         : hb);
 }
예제 #14
0
        public void Limit_the_number_points_returned_and_include_a_GROUP_BY_clause()
        {
            var query = InfluxQuery.From(h2o_feet)
                        .Select((f, t) => new { mean = Aggregations.MEAN(f.water_level) })
                        .Where("time >= '2015-08-18T00:00:00Z' AND time <= '2015-08-18T00:42:00Z'")
                        .GroupBy(TimeSpan.FromMinutes(12), t => t)
                        .Limit(2);

            query.Statement.Text.ShouldBe("SELECT MEAN(water_level) AS mean FROM h2o_feet WHERE time >= '2015-08-18T00:00:00Z' AND time <= '2015-08-18T00:42:00Z' GROUP BY time(12m),location LIMIT 2");
        }
예제 #15
0
 private static HtmlBuilder Contents(
     this HtmlBuilder hb, SiteSettings ss, Aggregations aggregations)
 {
     return(aggregations.TotalCount != 0
         ? hb
            .Total(aggregations)
            .Overdue(aggregations)
            .Parts(ss, aggregations)
         : hb.Span(css: "label", action: () => hb
                   .Text(text: Displays.NoData())));
 }
예제 #16
0
        private IList <QueryRecordJson> ConvertRecords(IEnumerable <IDictionary <string, object> > list)
        {
            var aggColumns = Aggregations.Select(x => x.Column).ToList();
            var selColumns = Select.ToList();

            return(list.Select(x => new QueryRecordJson
            {
                Selected = GetList(x, "Select", selColumns),
                Aggregated = GetList(x, "Value", aggColumns),
            })
                   .ToList());
        }
예제 #17
0
        public void Paginate_points_and_include_several_clauses()
        {
            var query = InfluxQuery.From(h2o_feet)
                        .Select(f => new { mean = Aggregations.MEAN(f.water_level) })
                        .Where("time >= '2015-08-18T00:00:00Z' AND time <= '2015-08-18T00:42:00Z'")
                        .GroupBy(TimeSpan.FromMinutes(12), t => t)
                        .OrderByTimeDesc()
                        .Limit(2)
                        .Offset(2)
                        .SLimit(1);

            query.Statement.Text.ShouldBe("SELECT MEAN(water_level) AS mean FROM h2o_feet WHERE time >= '2015-08-18T00:00:00Z' AND time <= '2015-08-18T00:42:00Z' GROUP BY time(12m),location ORDER BY time DESC LIMIT 2 OFFSET 2 SLIMIT 1");
        }
        public override async Task <AggregateOverallResponse> AggregateOverall(AggregateOverallRequest request, ServerCallContext context)
        {
            var cardsIds             = cardsRepository.GetCardsIds();
            var transactionsResponse = await transactionsReadClient.FilterAsync(new FilterTransactionsRequest { Cards = { cardsIds }, TimestampTo = request.TimestampTo, TimestampFrom = request.TimestampFrom }, context.RequestHeaders.SelectCustom());

            var aggregations = Aggregations.CreateOverallCsvReport(new OverallReportData {
                Aggregations = request.Aggregations.ToArray(), Granularity = request.Granularity, Transactions = transactionsResponse.Transactions.ToArray()
            });

            return(new AggregateOverallResponse {
                Portions = { aggregations }
            });
        }
예제 #19
0
        private Ingestion DeserializeAggregations(XmlReader reader)
        {
            while (reader.Read())
            {
                if (reader.IsStartElement())
                {
                    string     name    = reader.LocalName;
                    CFXmlModel model   = null;
                    string     strGuid = reader.GetAttribute("guid");
                    switch (name)
                    {
                    case "collection":
                        model = new CFCollection();
                        break;

                    case "item":
                        model = new CFItem();
                        break;

                    case "form":
                        model = new Form();
                        break;

                    case "file":
                        model = new CFDataFile();
                        break;

                    default:
                        throw new FormatException("Invalid XML element: " + reader.Name);
                    }

                    if (model != null)
                    {
                        model.Guid       = strGuid;
                        model.MappedGuid = strGuid;
                        model.Content    = reader.ReadOuterXml();
                        Aggregations.Add(model);
                    }
                }

                if (reader.NodeType == System.Xml.XmlNodeType.EndElement)
                {
                    if (reader.Name == "aggregations")
                    {
                        return(this);
                    }
                }
            }

            return(this);
        }
        public override Task <AggregateOverallResponse> AggregateOverall(AggregateOverallRequest request, Grpc.Core.ServerCallContext context)
        {
            var filters = new Filters {
                TimestampFrom = request.TimestampFrom.ToDateTime(), TimestampTo = request.TimestampTo.ToDateTime()
            };
            var transactions = transactionsRepository.GetMany(filters, 0).Select(t => mapper.Map <Transaction>(t)).ToArray();
            var aggregations = Aggregations.CreateOverallCsvReport(new OverallReportData {
                Aggregations = request.Aggregations.ToArray(), Granularity = request.Granularity, Transactions = transactions
            });

            return(Task.FromResult(new AggregateOverallResponse {
                Portions = { aggregations }
            }));
        }
        private IEnumerable <UserReportPortion> AggregateUserTransactions(Models.Card card, Transaction[] allTransactions, Granularity granularity)
        {
            var transactions   = allTransactions.Where(t => t.CardId == card.Id).ToArray();
            var withTimestamps = transactions.Select(t => new TransactionWithTimestamp {
                Timestamp = t.Timestamp.ToDateTime(), Transaction = t
            });
            var portions = Aggregations.GroupByPeriods(granularity, withTimestamps);

            foreach (var portion in portions)
            {
                var debits = portion.Sum(p => (float?)p.Transaction.Amount) ?? 0;
                yield return(new UserReportPortion {
                    Period = portion.Key, Debits = debits, Element = card.Number
                });
            }
        }
        private IEnumerable <UserReportPortion> AggregateUserTransactions(Models.Account account, Transaction[] allTransactions, Granularity granularity)
        {
            var transactions   = allTransactions.Where(t => t.Sender == account.Id || t.Recipient == account.Id);
            var withTimestamps = transactions.Select(t => new TransactionWithTimestamp {
                Timestamp = t.Timestamp.ToDateTime(), Transaction = t
            });
            var portions = Aggregations.GroupByPeriods(granularity, withTimestamps);

            foreach (var portion in portions)
            {
                var incomes = portion.Where(p => p.Transaction.Recipient == account.Id).Sum(p => (float?)p.Transaction.Amount) ?? 0;
                var debits  = portion.Where(p => p.Transaction.Sender == account.Id).Sum(p => (float?)p.Transaction.Amount) ?? 0;
                yield return(new UserReportPortion {
                    Period = portion.Key, Debits = debits, Incomes = incomes, Element = account.Number
                });
            }
        }
예제 #23
0
        public static Expression ChildrenAggregationFunc(
            Aggregations agg,
            Expression collection,
            LambdaExpression itemPredicate,
            ExpressionType countComparison,
            object countValue)
        {
            var itemType = collection.Type.GetInterfaces()
                           .Single(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IEnumerable <>))
                           .GetGenericArguments()[0];

            var itemCount = Expression.Call(
                typeof(Enumerable), agg.ToString(), new[] { itemType },
                collection, itemPredicate);

            return(Expression.MakeBinary(countComparison, itemCount, Expression.Constant(countValue)));
        }
예제 #24
0
        /// <inheritdoc />
        public bool Equals([AllowNull] Aggregate other)
        {
            if (other == null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Type == other.Type ||
                     Type != null &&
                     Type.Equals(other.Type)
                     ) &&
                 (
                     Enabled == other.Enabled ||
                     Enabled != null &&
                     Enabled.Equals(other.Enabled)
                 ) &&
                 (
                     Groups == other.Groups ||
                     Groups != null &&
                     Groups.Equals(other.Groups)
                 ) &&
                 (
                     Equals(GroupsArray, other.GroupsArray) ||
                     GroupsArray != null && other.GroupsArray != null &&
                     GroupsArray.SequenceEqual(other.GroupsArray)
                 ) &&
                 (
                     Equals(Aggregations, other.Aggregations) ||
                     Aggregations != null && other.Aggregations != null &&
                     Aggregations.SequenceEqual(other.Aggregations)
                 ) &&
                 (
                     GroupsSrc == other.GroupsSrc ||
                     GroupsSrc != null &&
                     GroupsSrc.Equals(other.GroupsSrc)
                 ));
        }
예제 #25
0
 public static HtmlBuilder Aggregations(
     this HtmlBuilder hb, SiteSettings ss, Aggregations aggregations)
 {
     return(!Reduced(ss.SiteId)
         ? hb.Div(
                id: "Aggregations",
                action: () => hb
                .DisplayControl(
                    id: "ReduceAggregations",
                    icon: "ui-icon-close")
                .Contents(ss, aggregations))
         : hb.Div(
                id: "Aggregations",
                css: "reduced",
                action: () => hb
                .DisplayControl(
                    id: "ExpandAggregations",
                    icon: "ui-icon-folder-open")));
 }
        /// <summary>
        /// Returns the matching Aggregation of type Nested
        /// </summary>
        /// <param name="fieldExpression">The same expression used in the query.</param>
        /// <param name="limit">How many levels to check (default: 100)</param>
        /// <returns>Aggregation</returns>
        public Aggregation NestedAggregation(Expression <Func <T, object> > fieldExpression, bool filtered = false, int limit = 100)
        {
            var exists  = false;
            var c       = 0;
            var aggName = $"nested_{ExpressionHelper.GetPropertyName(fieldExpression)}_{c}";

            while (!exists && c < limit)
            {
                if (Aggregations.ContainsKey(aggName))
                {
                    exists = true;
                    continue;
                }

                c++;
                aggName = $"nested_{ExpressionHelper.GetPropertyName(fieldExpression)}_{c}";
            }
            return(Aggregations[aggName]);
        }
        /// <summary>
        /// Writes the class diagram.
        /// </summary>
        /// <param name="interface">The interface.</param>
        /// <param name="useIncludes">if set to <c>true</c> [use includes].</param>
        /// <returns></returns>
        internal static string WriteClassDiagram(Models.Interface @interface, bool useIncludes = false)
        {
            string markup = Templates.Descriptor;

            markup = markup.Replace(TypeElement, "interface ").Replace(NameElement, @interface.Name).Replace(ProtoTypeElement, "").Replace(StereoTypeElement, "");

            markup = markup.Replace(BodyElement, WriteBody(@interface));

            var aggregates = Aggregations.Distinct().ToList();

            Aggregations.Clear();
            var composites = Compositions.Distinct().ToList();

            Compositions.Clear();

            aggregates.ForEach((n) => markup += Aggregate(@interface.Name, n));
            composites.ForEach((n) => markup += Composite(@interface.Name, n));

            return(markup);
        }
예제 #28
0
        /// <summary>
        /// Childrens the aggregation func pridicate.
        /// </summary>
        /// <returns>The aggregation func pridicate.</returns>
        /// <param name="agg">Agg.</param>
        /// <param name="collection">Collection Property Expression.</param>
        /// <param name="itemName">Item name.</param>
        /// <param name="itemComparison">Item comparison.</param>
        /// <param name="itemValue">Item value.</param>
        /// <param name="countComparison">Count comparison.</param>
        /// <param name="countValue">Count value.</param>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        public static Expression ChildrenAggregationFunc(
            Aggregations agg,
            Expression collection,
            string itemName,
            FilterOperations itemComparison,
            object itemValue,
            FilterOperations countComparison,
            object countValue)
        {
            var itemType = collection.Type.GetInterfaces()
                           .Single(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IEnumerable <>))
                           .GetGenericArguments()[0];

            var itemSource   = Expression.Parameter(itemType, "e");
            var itemProperty = Expression.Property(itemSource, itemName);

            Expression itemExpr = MakePropertyValueComparison(itemProperty, itemComparison, itemValue);

            var itemPredicate = Expression.Lambda(itemExpr, itemSource);

            return(ChildrenAggregationFunc(agg, collection, itemPredicate, countComparison.ToExpression(), countValue));
        }
예제 #29
0
파일: Ingestion.cs 프로젝트: lagoan/Catfish
        private Ingestion DeserializeAggregations(XElement element)
        {
            foreach (XElement child in element.Elements())
            {
                string     name    = child.Name.LocalName;
                CFXmlModel model   = null;
                string     strGuid = child.Attribute("guid").Value;
                switch (name)
                {
                case "collection":
                    model = new CFCollection();
                    break;

                case "item":
                    model = new CFItem();
                    break;

                case "form":
                    model = new Form();
                    break;

                case "file":
                    model = new CFDataFile();
                    break;
                }

                if (model != null)
                {
                    model.Guid       = strGuid;
                    model.MappedGuid = strGuid;
                    model.Content    = child.ToString();
                    Aggregations.Add(model);
                }
            }
            return(this);
        }
예제 #30
0
 /// <summary>
 /// 集団が存在するかどうか
 /// </summary>
 /// <param name="aggregationName">集団名</param>
 /// <returns>存在するかどうか</returns>
 public static bool HasAggregation(string aggregationName)
 => string.IsNullOrEmpty(aggregationName) == true ? false : Aggregations.ContainsKey(aggregationName);