//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))); }
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)); }
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))); }
protected AggregationBuilder UserPromoCodeReportCommon(Dictionary <string, object> projection, IFilterBuilder userFilter, IFilterBuilder promoFilter) { IMongoQuery query = BuildQuery(userFilter); return(new AggregationBuilder("User") .Match(query) .Project(projection) .Unwind("$PromoCodes._v") .Project(userPromoListFieldsNoV) .Match(new MongoFilterVisitor(promoFilter.Build()).Build())); }
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))); }
protected AggregationBuilder RegistrationReportCommon(Dictionary <string, object> projection, IFilterBuilder userFilter, IFilterBuilder promoFilter) { IMongoQuery query = BuildQuery(userFilter); var sortByUsedDate = SortBy.Ascending("_id", "PromoCodes._v.UsedDate"); var groupByUserPromo = FieldDocument("$", "_id", "RegisteredOn", "Email", "FirstName", "LastName", "RegisteredOnLocalDate", "LocationAddress1", "LocationCity", "LocationState", "LocationZipCode", "ContactPhoneHome", "DemographicDateofBirth"); return(new AggregationBuilder("User") .Match(query) .Project(projection) .Unwind("$PromoCodes._v") .Sort(sortByUsedDate) .Group("_id", groupByUserPromo) .First("PromoCode", "$PromoCodes._v") .Project(userPromoListFieldsAfterUnwind) .Match(new MongoFilterVisitor(promoFilter.Build()).Build())); }
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))); }
public OperationResult <PaginatedResult <EventDto> > Filter(EventFilter filter) { var predicate = _filterBuilder.Build(filter); var query = _repository.Get(predicate); var total = query.Count(); if (filter.IsPaged) { query = query .OrderBy(c => c.Id) .Skip(filter.Skip) .Take(filter.Take); } var events = query.ProjectTo <EventDto>().ToList(); var result = new PaginatedResult <EventDto>(events, total); return(OperationResult.Success(result)); }
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)); }
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)); }
public IList<ScaleLevel> ReadData(IFilterBuilder filterBuilder) { var result = new List<ScaleLevel>(); foreach (var path in Directory.EnumerateFiles(FolderName)) { var fileInfo = new FileInfo(path); if (Extension.Equals(fileInfo.Extension, StringComparison.OrdinalIgnoreCase)) { using (var stream = fileInfo.OpenRead()) { var deserilizer = new BinaryFormatter(); var metadata = (ScaleMetadata)deserilizer.Deserialize(stream); var scaleLevel = new ScaleLevel(filterBuilder.Build(metadata.T), metadata.Image); result.Add(scaleLevel); } } } return result; }
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); }
//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); }