Example #1
0
 public static HlidacStatu.Lib.Render.ReportDataSource PocetSmluvPerUzavreni(Nest.DateInterval interval)
 {
     return(PocetSmluvPerUzavreni("-id:pre* ", interval));
 }
Example #2
0
        public static ReportDataSource PocetSmluvPerUzavreni(string query, Nest.DateInterval interval)
        {
            DateTime minDate     = new DateTime(2012, 1, 1);
            DateTime maxDate     = DateTime.Now.Date.AddDays(1);
            string   datumFormat = "MMM yyyy";

            switch (interval)
            {
            case DateInterval.Day:
                datumFormat = "dd.MM.yy";
                break;

            case DateInterval.Week:
                datumFormat = "dd.MM.yy";
                break;

            case DateInterval.Month:
                datumFormat = "MMM yyyy";
                break;

            case DateInterval.Quarter:
                datumFormat = "MMM yyyy";
                break;

            case DateInterval.Year:
                datumFormat = "yyyy";
                break;

            default:
                break;
            }

            AggregationContainerDescriptor <HlidacStatu.Lib.Data.Smlouva> aggs = new AggregationContainerDescriptor <HlidacStatu.Lib.Data.Smlouva>()
                                                                                 .DateHistogram("x-agg", h => h
                                                                                                .Field(f => f.datumUzavreni)
                                                                                                .Interval(interval)
                                                                                                );

            //var res = HlidacStatu.Lib.Data.Smlouva.Search.RawSearch(
            //    "{\"query_string\": { \"query\": \"-id:pre* AND datumUzavreni:{" + HlidacStatu.Util.RenderData.ToElasticDate(minDate) + " TO "+ HlidacStatu.Util.RenderData.ToElasticDate(maxDate) + "}\" } }"
            //        , 1, 0, anyAggregation: aggs);
            var res = HlidacStatu.Lib.Data.Smlouva.Search.SimpleSearch("( " + query + " ) AND datumUzavreni:{" + HlidacStatu.Util.RenderData.ToElasticDate(minDate) + " TO " + HlidacStatu.Util.RenderData.ToElasticDate(maxDate) + "}", 1, 0, HlidacStatu.Lib.Data.Smlouva.Search.OrderResult.FastestForScroll, anyAggregation: aggs, exactNumOfResults: true);

            ReportDataSource rds = new ReportDataSource(new ReportDataSource.Column[]
            {
                new ReportDataSource.Column()
                {
                    Name             = "Datum",
                    TextRender       = (s) => { return(((DateTime)s).ToString(datumFormat)); },
                    OrderValueRender = (s) => { return(((DateTime)s).Ticks.ToString()); }
                },
                new ReportDataSource.Column()
                {
                    Name             = "Počet smluv",
                    OrderValueRender = (s) => { return(HlidacStatu.Util.RenderData.OrderValueFormat((double?)s)); },
                },
            }
                                                        );

            foreach (Nest.DateHistogramBucket val in ((BucketAggregate)res.ElasticResults.Aggregations["x-agg"]).Items)
            {
                if (val.Date >= minDate && val.Date <= maxDate)
                {
                    rds.AddRow(
                        val.Date,
                        val.DocCount
                        );
                }
            }


            return(rds);
        }