/// <summary>
        /// Generates the age distr.
        /// </summary>
        /// <param name="start">The start.</param>
        /// <param name="end">The end.</param>
        /// <param name="companies">The companies.</param>
        /// <returns>List&lt;AgeDistribution&gt;.</returns>
        public List <AgeDistribution> GenerateAgeDistr(DateTime start, DateTime end, IEnumerable <string> companies)
        {
            start = new DateTime(start.Year, start.Month, start.Day);
            end   = new DateTime(end.Year, end.Month, end.Day);
            var result = new List <AgeDistribution>();

            using (var context = this.GetContext())
            {
                foreach (var company in companies)
                {
                    var ages = new AgeDistribution();
                    ages.Name = company;
                    var filter  = this.keywordManager.GetFilters(company);
                    var pattern = this.indexHelper.BuildPatternFromFilter(filter);

                    var tableName = TableNameHelper.GetNewsStreamTableName(this.currentClientUser.GetProfile().Postfix);
                    try
                    {
                        var cluster =
                            context.Database.SqlQuery <string>(
                                $@"select ClusterId0 from {tableName} 
                           where Contains(keywords, {{0}})",
                                pattern).ToList();
                    }catch (Exception e) { continue; }
                    var clusters =
                        context.Database.SqlQuery <string>(
                            $@"select ClusterId0 from {tableName} 
                           where Contains(keywords, {{0}})",
                            pattern).ToList();
                    var idList = clusters.ToList();

                    var vs = from vi in context.LocationAndUserDemo
                             where vi.Date >= start && vi.Date <= end && idList.Contains(vi.ClusterId0)
                             group vi by vi.AgeGroup
                             into s
                             select new { key = s.Key, value = s.Sum(x => x.QueryViewCount) };

                    var visitCount = vs.ToDictionary(i => i.key);
                    foreach (var item in visitCount)
                    {
                        var detail = new AgeDetail {
                            Name = item.Key, Value = (int)item.Value.value
                        };
                        ages.Details.Add(detail);
                    }

                    result.Add(ages);
                }
            }

            return(result);
        }
Beispiel #2
0
        public static AgeDetail AgeParser(StructParseContext ctx, int linedex, char level)
        {
            AgeDetail det  = new AgeDetail();
            var       ctx2 = PContextFactory.Alloc(ctx, det, linedex);

            ctx2.Level  = level;
            ctx2.Record = ctx.Record;
            if (!string.IsNullOrWhiteSpace(ctx.Remain))
            {
                det.Detail = ctx.Remain;
            }
            StructParse(ctx2, tagDict);
            ctx.Endline = ctx2.Endline;
            PContextFactory.Free(ctx2);
            return(det);
        }