Ejemplo n.º 1
0
        public IEnumerable <Tuple <DateTime, Int32> > WinsGraph(IFilterBuilder userFilter, IFilterBuilder prizeFilter, bool byDay)
        {
            IMongoQuery query = null;

            if (userFilter != null)
            {
                query = new MongoFilterVisitor(userFilter.Build()).Build();
            }
            var queryPrize = Query.And(Query.Exists("Prizes._v"),
                                       Query.Not(Query.Size("Prizes._v", 0)),
                                       Query.NE("Hidden", true));

            if (query != null)
            {
                query = Query.And(queryPrize, query);
            }

            var aggQuery = new AggregationBuilder("User")
                           .Match(query)
                           .Project(new Dictionary <String, object> {
                { "Prizes._v", 1 }
            })
                           .Unwind("$Prizes._v")
                           .Match(new MongoFilterVisitor(prizeFilter.Build()).Build())
                           .Project(winGraphProjection)
                           .Group(byDay ? byDayGroup : byMinuteGroup);

            var im = AggregationResultToList(RunAggreation(aggQuery.Pipeline));

            return(byDay ? GraphByDays(im) : GraphByMinutes(im));
        }
Ejemplo n.º 2
0
        //private MongoCursor<UserEvent> GetEventsCursor(ObjectId campaignId,
        //    IEnumerable<EventTypeEnum> eventTypes, DateTime? start, DateTime? end)
        //{
        //    var query = Query.And(Query.EQ("CampaignId", campaignId),
        //                          Query.In("EventTypeId", eventTypes.Select(x => BsonValue.Create((int)x))));
        //    if (start.HasValue)
        //        query = Query.And(query, Query.GTE("EventDate", start.Value.ToUniversalTime().Ticks));

        //    if (end.HasValue)
        //        query = Query.And(query, Query.LTE("EventDate", end.Value.ToUniversalTime().Ticks));

        //    query = Query.And(query, Query.NE("Hidden", true));
        //    return Context..SlaveServerCollection.FindAs<UserEvent>(query);
        //}

        public IEnumerable <Object> WinsReport(IFilterBuilder userFilter, IFilterBuilder prizeFilter, ISort sort, int skip, int limit)
        {
            IMongoQuery query = null;

            if (userFilter != null)
            {
                query = new MongoFilterVisitor(userFilter.Build()).Build();
            }
            var queryPrize = Query.And(Query.Exists("Prizes._v"),
                                       Query.Not(Query.Size("Prizes._v", 0)),
                                       Query.NE("Hidden", true));

            if (query != null)
            {
                query = Query.And(queryPrize, query);
            }
            else
            {
                query = queryPrize;
            }
            var aggQuery = new AggregationBuilder("User")
                           .Match(query)
                           .Project(winReportFields)
                           .Unwind("$Prizes._v")
                           .Match(new MongoFilterVisitor(prizeFilter.Build()).Build())
                           .Sort(sort)
                           .Skip(skip)
                           .Limit(limit).Pipeline;

            //Console.WriteLine(aggQuery.ToString());
            return(AggregationResultToList(RunAggreation(aggQuery)));
        }
Ejemplo n.º 3
0
        public IEnumerable <Object> RegistrationReport(IFilterBuilder userFilter, ISort sort, int skip, int limit)
        {
            IMongoQuery query = null;

            if (userFilter != null)
            {
                query = new MongoFilterVisitor(userFilter.Build()).Build();
            }

            //var aggQuery = new AggregationBuilder("UserXUserEvent")
            //    .Match(query)
            //    .Project(registrationReportFields)
            //    .Unwind("$UserEvents")
            //    .Sort(sort)
            //    .Skip(skip)
            //    .Limit(limit).Pipeline;

            var aggQuery = new AggregationBuilder("User")
                           .Match(query)
                           .Project(registrationReportFields)
                           .Sort(sort)
                           .Skip(skip)
                           .Limit(limit).Pipeline;

            // Debug.WriteLine(aggQuery);
            //return RunCommand(aggQuery);
            return(AggregationResultToList(RunAggreation(aggQuery)));
        }
Ejemplo n.º 4
0
        public IEnumerable <Object> WinnersReport(IFilterBuilder userFilter, IFilterBuilder prizeFilter, ISort sort, int skip, int limit)

        /**
         * > db.User.aggregate(
         * {$match: { CampaignId: ObjectId("5011b6099610f710f4fd438e"), PrizeCount: {$gt:3}}}, # user fields
         * {$project: { LastName: 1, Prizes:1} } # return fields and Prizes
         * {$unwind: '$Prizes._v'}, # unwind the prizes
         * {$match: {"Prizes._v.PrizeDate": {$gte: NumberLong("634794549227340147"), $lte: NumberLong("634794559975708161")}}}
         * # match on prizes
         * {$group: { _id: { _id: '$_id', LastName: '$LastName' ....}, # re-group all the fields you want to see except...
         * "Prizes" : { $addToSet: '$Prizes._v'}}}, # prizes, which you add to set (and now they are unsorted!)
         * {$project: { _id: "$_id._id", LastName:"$_id.LastName", Prizes: 1}}) # project out of _id to get to top level
         */


        {
            IMongoQuery userQuery = null;

            if (userFilter != null)
            {
                userQuery = new MongoFilterVisitor(userFilter.Build()).Build();
            }
            var queryPrize = Query.And(Query.Exists("Prizes._v"),
                                       Query.Not(Query.Size("Prizes._v", 0)),
                                       Query.NE("Hidden", true));

            userQuery = userQuery != null?Query.And(queryPrize, userQuery) : queryPrize;

            IMongoQuery prizeQuery = new MongoFilterVisitor(prizeFilter.Build()).Build();

            var groupFields  = winnersReportFields.Keys.Where(x => !x.StartsWith("Prizes")).ToList();
            var id           = FieldDocument("$", groupFields);
            var finalProject = FieldDocument("$_id.", groupFields).Add("Prizes", 1);

            var group = new BsonDocument {
                { "_id", id }, { "Prizes", new BsonDocument("$addToSet", "$Prizes._v") }
            };


            var aggQuery = new AggregationBuilder("User")
                           .Match(userQuery)
                           .Project(winnersReportFields)
                           .Unwind("$Prizes._v")
                           .Match(prizeQuery)
                           .Group(group)
                           .Project(finalProject)
                           .Sort(sort)
                           .Skip(skip)
                           .Limit(limit).Pipeline;

            //Console.WriteLine(aggQuery.ToString());
            return(AggregationResultToList(RunAggreation(aggQuery)));
        }
Ejemplo n.º 5
0
        public IEnumerable <Object> SpinReport(IFilterBuilder userFilter, IFilterBuilder eventFilter, ISort sort, int skip, int limit)
        {
            IMongoQuery query      = new MongoFilterVisitor(userFilter.Build()).Build();
            IMongoQuery eventQuery = new MongoFilterVisitor(eventFilter.Build()).Build();

            var aggQuery = new AggregationBuilder("UserXUserEvent")
                           .Match(query)
                           .Project(registrationReportFields)
                           .Unwind("UserEvents")
                           .Match(eventQuery)
                           .Sort(sort)
                           .Skip(skip)
                           .Limit(limit)
                           .Pipeline;

            return(AggregationResultToList(RunAggreation(aggQuery)));
        }
Ejemplo n.º 6
0
        public IEnumerable <Tuple <DateTime, Int32> > RegistrationGraph(IFilterBuilder userFilter, bool byDay)
        {
            IMongoQuery query = null;

            if (userFilter != null)
            {
                query = new MongoFilterVisitor(userFilter.Build()).Build();
            }


            var aggQuery = new AggregationBuilder("User")
                           .Match(query)
                           .Project(registrationGraphProjection)
                           .Group(byDay ? byDayGroup : byMinuteGroup);

            var im = AggregationResultToList(RunAggreation(aggQuery.Pipeline));

            return(byDay ? GraphByDays(im) : GraphByMinutes(im));
        }
Ejemplo n.º 7
0
        public IEnumerable <Object> PrizesReport(IFilterBuilder userFilter, ISort sort, int skip, int limit)
        {
            IMongoQuery query = null;

            if (userFilter != null)
            {
                query = new MongoFilterVisitor(userFilter.Build()).Build();
            }

            var aggQuery = new AggregationBuilder("Prize")
                           .Match(query)
                           .Project(prizeReportFields)
                           .Sort(sort)
                           .Skip(skip)
                           .Limit(limit).Pipeline;

            //Console.WriteLine(aggQuery.ToString());
            return(RunAggreationToList <Prize>(aggQuery));
        }
Ejemplo n.º 8
0
        protected AggregationBuilder WinsGraphBase(IFilterBuilder userFilter, IFilterBuilder prizeFilter)
        {
            var baseQuery = Query.And(
                Query.Exists("Prizes._v"),
                Query.Not(Query.Size("Prizes._v", 0)),
                Query.NE("Hidden", true));

            var userQuery = new MongoFilterVisitor(baseQuery, userFilter.Build()).Build();

            var prizeQuery = new MongoFilterVisitor(prizeFilter.Build()).Build();

            var aggBuilder = new AggregationBuilder("User")
                             .Match(userQuery)
                             .Project(new Dictionary <string, object> {
                { "CampaignId", 1 }, { "Prizes", 1 }
            })
                             .Unwind("$Prizes._v")
                             .Match(prizeQuery);

            return(aggBuilder);
        }
Ejemplo n.º 9
0
        //public IUserProfilePromo AggregationResultForReport(Object listitem)
        //{
        //    var up = new UserProfilePromo();
        //    try
        //    {
        //        var doc = listitem as BsonDocument;
        //        if (doc != null)
        //        {
        //            //if (doc["_id"].BsonType == BsonType.Document)
        //            //    doc = doc["_id"].AsBsonDocument;
        //            up.FirstName = doc["FirstName"].AsString;
        //            up.LastName = doc["LastName"].AsString;
        //            if (doc.Contains("RegisteredOn"))
        //            {
        //                up.RegisteredOn = new DateTime(doc["RegisteredOn"].AsInt64).ToLocalTime();
        //            }
        //            up.Email = doc["Email"].AsString;

        //            BsonDocument sub = doc["PromoCode"].AsBsonDocument;
        //            var promoCode = BsonSerializer.Deserialize<UserPromoCode>(sub.ToJson());
        //            up.Code = promoCode.Code;
        //            up.CodeType = promoCode.CodeType;
        //            up.UsedDate = promoCode.UsedDate;
        //            up.PromoCodes.Add(promoCode);
        //        }
        //    }
        //    catch (Exception)
        //    {
        //    }
        //    return up;
        //}

        protected IMongoQuery BuildQuery(IFilterBuilder userFilter)
        {
            IMongoQuery query = null;

            if (userFilter != null)
            {
                query = new MongoFilterVisitor(userFilter.Build()).Build();
            }
            var queryPromoCode = Query.And(Query.Exists("PromoCodes._v"),
                                           Query.Not(Query.Size("PromoCodes._v", 0)),
                                           Query.NE("Hidden", true));

            if (query != null)
            {
                query = Query.And(queryPromoCode, query);
            }
            else
            {
                query = queryPromoCode;
            }

            return(query);
        }