Пример #1
0
 /// <summary>
 /// Load trending in volume
 /// This method does not leak
 /// </summary>
 public List <TrendingEntity> GetTreding(TrendingQuery query)
 {
     try
     {
         if (!Running)
         {
             return(new List <TrendingEntity>());
         }
         return(DoGetTreding(query));
     }
     catch (Exception e)
     {
         Log(MessageType.Error, "GetTreding", e.ToMessageWithType(), e);
     }
     return(new List <TrendingEntity>());
 }
Пример #2
0
        private void readTrending(string userFilter, string productFilter)
        {
            var sd_ = dtpSB.Value.ToUniversalTime();
            var ed_ = dtpED.Value.ToUniversalTime();

            var sd = new DateTime(sd_.Year, sd_.Month, sd_.Day, 0, 0, 0);
            var ed = new DateTime(ed_.Year, ed_.Month, ed_.Day, 23, 59, 59);

            var qryUser    = new TrendingQuery("user", sd_, ed_, 70 * 70, 0, nCol.Value.AsInt(), userFilter);
            var qryProduct = new TrendingQuery("product", sd_, ed_, 70 * 70, 0, nCol.Value.AsInt(), productFilter);

            var resultUser    = m_Client.GetTrending(qryUser);
            var resultProduct = m_Client.GetTrending(qryProduct);

            MessageBox.Show(resultUser.ToJSON(JSONWritingOptions.PrettyPrint) + "\n" + resultProduct.ToJSON(JSONWritingOptions.PrettyPrint));
        }
Пример #3
0
        protected override List <TrendingEntity> DoGetTreding(TrendingQuery query)
        {
            var result = new List <TrendingEntity>();

            IEnumerable <string> collections;

            if (query.EntityType.IsNotNullOrWhiteSpace())
            {
                if (!TrendingHost.HasEntity(query.EntityType))
                {
                    return(result);
                }
                collections = new[] { query.EntityType };
            }
            else
            {
                collections = TrendingHost.AllEntities;
            }

            foreach (var collection in collections)
            {
                var sort        = new BSONDocument().Set(new BSONInt32Element(DBConsts.FIELD_VALUE, -1));
                var qry         = new Query();
                var betweenDate = new BSONDocument();
                betweenDate.Set(new BSONDateTimeElement("$gte", query.StartDate));
                betweenDate.Set(new BSONDateTimeElement("$lte", query.EndDate));
                qry.Set(new BSONDocumentElement("dt", betweenDate));
                if (query.DimensionFilter.IsNotNullOrEmpty())
                {
                    TrendingHost.MapGaugeDimensions(collection, query.DimensionFilter)
                    .ForEach(pair => qry.Set(new BSONStringElement(pair.Key, pair.Value)));
                }

                var find = new Query();
                find.Set(new BSONDocumentElement("$query", qry));
                find.Set(new BSONDocumentElement("$orderby", sort));

                var fetchBy = 1000;
                if (query.FetchCount < fetchBy)
                {
                    fetchBy = query.FetchCount;
                }
                using (var cursor = m_Database[collection].Find(find, query.FetchStart, fetchBy))
                {
                    foreach (var doc in cursor)
                    {
                        if (result.Count >= query.FetchCount)
                        {
                            break;
                        }

                        var doc_dt = doc[DBConsts.FIELD_DATETIME].ObjectValue;

                        var dt   = doc[DBConsts.FIELD_DATETIME].ObjectValue.AsDateTime();
                        var dl   = MapDetalizationToMinutes(DetalizationLevel);
                        var gshr = RowConverter.GDID_BSONtoCLR((BSONBinaryElement)doc[DBConsts.FIELD_G_SHARD]);
                        var gent = RowConverter.GDID_BSONtoCLR((BSONBinaryElement)doc[DBConsts.FIELD_G_ENTITY]);
                        var val  = doc[DBConsts.FIELD_VALUE].ObjectValue.AsULong();

                        result.Add(new TrendingEntity(dt,
                                                      dl,
                                                      query.EntityType,
                                                      gshr,
                                                      gent,
                                                      val
                                                      )
                                   );
                    }
                }
            }
            return(result);
        }
Пример #4
0
        public IEnumerable <TrendingEntity> GetTrending(TrendingQuery query)
        {
            var volume = findVolume(query.StartDate, query.EndDate, query.SampleCount);

            return(volume != null?volume.GetTreding(query) : Enumerable.Empty <TrendingEntity>());
        }
Пример #5
0
 protected abstract List <TrendingEntity> DoGetTreding(TrendingQuery query);
Пример #6
0
 public IEnumerable <TrendingEntity> GetTrending(TrendingQuery query)
 {
     return(TrendingSystemService.Instance.GetTrending(query));
 }