示例#1
0
        private OverviewDetails LoadCashOverview()
        {
            OverviewDetails details = new OverviewDetails();
            IAggregateFluent <HandHistory> cashGameHands =
                handCollection.Aggregate().Match(h => h.GameDescription.PokerFormat == PokerFormat.CashGame &&
                                                 h.GameDescription.Limit.Currency != Currency.PlayMoney);

            IAggregateFluent <UnwoundHand> actions = cashGameHands
                                                     .Unwind <HandHistory, UnwoundHand>(h => h.HandActions)
                                                     .Match(h => PlayerNames.Contains(h.HandActions.PlayerName));

            if (!cashGameHands.Any())
            {
                return(details);     // Return empty result set if there are no hands available
            }
            details.Hands = cashGameHands.Count().First().Count;

            foreach (var profit in actions.Group(h => h.HandId, h => new { sum = h.Sum(h2 => h2.HandActions.Amount * h2.GameDescription.Limit.BigBlind) }).ToEnumerable())
            {
                if (profit.sum > 0)
                {
                    details.Winnings += profit.sum;
                }
                else
                {
                    details.Losses += profit.sum;
                }
            }

            return(details);
        }
示例#2
0
        public async Task <int> CountAsync(CancellationToken cancellationToken)
        {
            AggregateCountResult result = await _source
                                          .Count()
                                          .FirstOrDefaultAsync(cancellationToken)
                                          .ConfigureAwait(false);

            return((int)(result?.Count ?? 0L));
        }
示例#3
0
        public List <object> SkipTake <T>(IAggregateFluent <T> result, int skip, int take, out long total)
        {
            if (take > 0)
            {
                //var sortStage = result.Stages.FirstOrDefault(x => x.OperatorName == "$sort");
                //var stages = result.Stages.Where(x => x.OperatorName != "$sort");
                //var resultForTotal = new PipelineStagePipelineDefinition<TDocument, T>(stages);

                total  = result.Count().FirstOrDefault()?.Count ?? 0;
                result = result.Skip(skip).Limit(take);
            }
            else
            {
                total = 0;
            }
            var list = result.ToList();

            return(list.Cast <object>().ToList());
        }
示例#4
0
        private OverviewDetails LoadTournamentOverview(bool sitAndGo)
        {
            OverviewDetails details = new OverviewDetails();
            PokerFormat     format  = sitAndGo ? PokerFormat.SitAndGo : PokerFormat.MultiTableTournament;
            IAggregateFluent <HandHistory> hands = handCollection.Aggregate().Match(h => h.GameDescription.PokerFormat == format);

            if (!hands.Any())
            {
                return(details);
            }

            details.Hands = hands.Count().First().Count;
            IAggregateFluent <TournamentSummary> tournaments =
                tournamentCollection.Aggregate()
                .Match(t => t.SitAndGo == sitAndGo && t.Buyin.Currency != Currency.PlayMoney);

            details.Winnings = tournaments.Group(t => t.SitAndGo, t => new { sum = t.Sum(t2 => t2.Winnings) }).First().sum;
            details.Losses   = -tournaments.Group(t => t.SitAndGo,
                                                  t => new { sum = t.Sum(t2 => t2.Buyin.Total + t2.Rebuy.Total * t2.RebuyCount + t2.AddOn.Total) }).First().sum;
            details.Tournaments = tournaments.Count().First().Count;
            return(details);
        }
示例#5
0
        /// <summary>
        /// Return establishment list.
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        public ListResult <EstablishmentListDTO> List(EstablishmentFilter filter)
        {
            IAggregateFluent <Establishment> establishmentAggregateFluent = this.MongoRepository
                                                                            .GetCollection <Establishment>().Aggregate();

            if (filter.GeospatialQuery)
            {
                if (!filter.Meters.HasValue)
                {
                    filter.Meters = 10000;
                }

                BsonDocument geoNearOptions = new BsonDocument {
                    {
                        "near", new BsonDocument {
                            { "type", "Point" },
                            { "coordinates", new BsonArray {
                                  filter.Longitude.Value, filter.Latitude.Value
                              } },
                        }
                    },
                    { "maxDistance", filter.Meters },
                    { "includeLocs", "Location.Coordinates" },
                    { "distanceField", "Location.Distance" },
                    { "spherical", true }
                };

                establishmentAggregateFluent = establishmentAggregateFluent.AppendStage(
                    (PipelineStageDefinition <Establishment, Establishment>) new BsonDocument {
                    { "$geoNear", geoNearOptions }
                }
                    );

                this.TelemetryClient.TrackEvent(
                    EventNames.EstablishmentListLocation,
                    new { filter.Latitude, filter.Longitude }
                    );
            }

            if (filter.EstablishmentType.HasValue)
            {
                establishmentAggregateFluent = establishmentAggregateFluent
                                               .Match(document => document.EstablishmentTypes.Contains(filter.EstablishmentType.Value));

                this.TelemetryClient.TrackEvent(
                    EventNames.EstablishmentListType,
                    new { filter.EstablishmentType }
                    );
            }

            if (!string.IsNullOrEmpty(filter.Query))
            {
                establishmentAggregateFluent = establishmentAggregateFluent.Match(
                    document => document.Name.Contains(filter.Query) ||
                    document.Description.Contains(filter.Query)
                    );

                this.TelemetryClient.TrackEvent(
                    EventNames.EstablishmentListQuery,
                    new { filter.Query }
                    );
            }

            if (filter.DaysOfWeekEnum != null)
            {
                Expression <Func <Establishment, bool> > availabilityExpression = document => false;

                foreach (DayOfWeekEnum dayOfWeek in filter.DaysOfWeekEnum)
                {
                    availabilityExpression = availabilityExpression.Or(
                        document => document.Availabilities.Any(
                            availability => availability.DayOfWeek == dayOfWeek || availability.CloseDayOfWeek == dayOfWeek
                            )
                        );
                }

                establishmentAggregateFluent = establishmentAggregateFluent.Match(availabilityExpression);

                this.TelemetryClient.TrackEvent(
                    EventNames.EstablishmentListDaysOfWeek,
                    new { filter.DaysOfWeek }
                    );
            }

            IAggregateFluent <BsonDocument> aggregateFluent = establishmentAggregateFluent.As <BsonDocument>();

            aggregateFluent = filter.OrderType == OrderTypeEnum.Distance
                ? aggregateFluent.SortBy(document => document["Location"]["Distance"])
                : aggregateFluent.SortByDescending(document => document["Relevance"]);

            if (!this.UserContext.EstablishmentId.HasValue)
            {
                this.RelevanceService.Register <Establishment, EstablishmentFilter>(filter);
            }

            IEnumerable <BsonDocument> documents = aggregateFluent
                                                   .Skip((filter.Page - 1) * filter.PageSize)
                                                   .Limit(filter.PageSize)
                                                   .ToList();

            IEnumerable <EstablishmentListDTO> establishments = documents.Select(document =>
                                                                                 new EstablishmentListDTO
            {
                Id = document["_id"].AsObjectId,
                EstablishmentTypes = document["EstablishmentTypes"].AsBsonArray.Select(x => (EstablishmentTypeEnum)x.AsInt32),
                ImageThumbnail     = document["ImageThumbnail"]["Uri"].AsString,
                Name     = document["Name"].AsString,
                Distance = document["Location"].AsBsonDocument.Contains("Distance")
                        ? document["Location"]["Distance"].AsDouble
                        : (double?)null
            }
                                                                                 ).ToList();

            return(new ListResult <EstablishmentListDTO>(
                       establishments,
                       aggregateFluent.Count().FirstOrDefault()?.Count ?? 0,
                       filter
                       ));
        }
示例#6
0
 public AggregateFluentPagingContainer(IAggregateFluent <TEntity> source)
 {
     _countSource = source.Count();
     _source      = source;
 }
示例#7
0
        /// <summary>
        /// Return event list.
        /// </summary>
        /// <returns></returns>
        public ListResult <EventListDTO> List(EventFilter filter)
        {
            IAggregateFluent <Event> eventAggregateFluent = this.MongoRepository.GetCollection <Event>().Aggregate();

            if (filter.GeospatialQuery)
            {
                if (!filter.Meters.HasValue)
                {
                    filter.Meters = 10000;
                }

                BsonDocument geoNearOptions = new BsonDocument {
                    {
                        "near", new BsonDocument {
                            { "type", "Point" },
                            { "coordinates", new BsonArray {
                                  filter.Longitude.Value, filter.Latitude.Value
                              } },
                        }
                    },
                    { "maxDistance", filter.Meters },
                    { "includeLocs", "Location.Coordinates" },
                    { "distanceField", "Location.Distance" },
                    { "spherical", true }
                };

                eventAggregateFluent = eventAggregateFluent.AppendStage(
                    (PipelineStageDefinition <Event, Event>) new BsonDocument {
                    { "$geoNear", geoNearOptions }
                }
                    );

                this.TelemetryClient.TrackEvent(
                    EventNames.EventListLocation,
                    new { filter.Latitude, filter.Longitude }
                    );
            }

            if (!string.IsNullOrEmpty(filter.EstablishmentId))
            {
                eventAggregateFluent = eventAggregateFluent.Match(
                    document => document.EstablishmentId == new ObjectId(filter.EstablishmentId));

                this.TelemetryClient.TrackEvent(
                    EventNames.EventListEstablishment,
                    new { filter.EstablishmentId }
                    );
            }

            if (filter.Genre.HasValue)
            {
                eventAggregateFluent = eventAggregateFluent.Match(
                    document => document.Genres.Contains(filter.Genre.Value));

                this.TelemetryClient.TrackEvent(
                    EventNames.EventListGenre,
                    new { filter.Genre }
                    );
            }

            if (!string.IsNullOrEmpty(filter.Query))
            {
                eventAggregateFluent = eventAggregateFluent.Match(
                    document => document.Name.Contains(filter.Query) ||
                    document.Description.Contains(filter.Query)
                    );

                this.TelemetryClient.TrackEvent(
                    EventNames.EventListQuery,
                    new { filter.Query }
                    );
            }

            if (filter.DateFilter)
            {
                eventAggregateFluent = eventAggregateFluent.Match(document => (
                                                                      (document.EndDate >= filter.StartDate && document.StartDate <= filter.StartDate) ||
                                                                      (document.StartDate <= filter.EndDate && document.EndDate >= filter.EndDate) ||
                                                                      (document.StartDate >= filter.StartDate && document.EndDate <= filter.EndDate)
                                                                      ));

                this.TelemetryClient.TrackEvent(
                    EventNames.EventListDate,
                    new { filter.StartDate, filter.EndDate }
                    );
            }

            if (!this.UserContext.EstablishmentId.HasValue)
            {
                this.RelevanceService.Register <Event, EventFilter>(filter);
            }

            IAggregateFluent <BsonDocument> aggregateFluent = eventAggregateFluent.Lookup(
                nameof(Establishment),
                "EstablishmentId",
                "_id",
                "Establishment"
                ).Unwind("Establishment");

            aggregateFluent = filter.OrderType == OrderTypeEnum.Distance
                ? aggregateFluent.SortBy(document => document["Location"]["Distance"])
                : aggregateFluent.SortByDescending(document => document["Relevance"]);

            IEnumerable <BsonDocument> documents = aggregateFluent
                                                   .Skip((filter.Page - 1) * filter.PageSize)
                                                   .Limit(filter.PageSize)
                                                   .ToList();

            IEnumerable <EventListDTO> events = documents.Select(document =>
                                                                 new EventListDTO
            {
                Id             = document["_id"].AsObjectId,
                Name           = document["Name"].AsString,
                StartDate      = document["StartDate"].ToUniversalTime(),
                EndDate        = document["EndDate"].ToUniversalTime(),
                Genres         = document["Genres"].AsBsonArray.Select(x => (GenreEnum)x.AsInt32),
                ImageThumbnail = document["ImageThumbnail"]["Uri"].AsString,
                Distance       = document["Location"].AsBsonDocument.Contains("Distance")
                        ? document["Location"]["Distance"].AsDouble
                        : (double?)null,
                Establishment = new EventListEstablishmentDTO
                {
                    Id             = document["EstablishmentId"].AsObjectId,
                    Name           = document["Establishment"]["Name"].AsString,
                    ImageThumbnail = document["Establishment"]["ImageThumbnail"]["Uri"].AsString,
                }
            }
                                                                 ).ToList();

            return(new ListResult <EventListDTO>(
                       events,
                       aggregateFluent.Count().FirstOrDefault()?.Count ?? 0,
                       filter
                       ));
        }