Beispiel #1
0
        private async Task <PagedQueryResult <ActivityDTO> > GetActivityFeedAsync(string userId, TableContinuationToken continuationToken, string startActivityId)
        {
            var result = await storageAccessService.QueryTableAsync <JsonTableEntity <ActivityEntity> >(Constants.TableNames.ActivityUserFeed, userId, startActivityId, 30, continuationToken);

            var activities = result.ResultPage.Select(r => r.Entity.ToDto()).ToList();

            return(new PagedQueryResult <ActivityDTO>(activities, result.ContinuationToken));
        }
        private async Task <IEnumerable <UserStatistics> > GetScoreStatisticsAsync()
        {
            string whereClause = TableQuery.GenerateFilterConditionForInt(nameof(UserStatsTableEntity.Score), QueryComparisons.GreaterThan, 0);

            var queryResult = await storageAccessService.QueryTableAsync <UserStatsTableEntity>(TableNames.UserStats, whereClause);

            var result = queryResult.Where(s => s.Score.GetValueOrDefault() > 0)
                         .OrderByDescending(r => r.Score)
                         .Select(r => new UserStatistics(r.RowKey, r.CurrentAlcoholization, r.CurrentNightDrinks, r.Score, r.TotalDrinksLastMonth))
                         .ToList();

            return(result);
        }
        public async Task <IEnumerable <ActivityEntity> > GetMasterActivitiesAsync(ActivityFilterArgs args)
        {
            string whereClause = null;
            string tableName   = Constants.TableNames.Activity;

            string currentPartition  = ActivityKeyFactory.CreatePartitionKey(DateTime.UtcNow);
            string previousPartition = ActivityKeyFactory.CreatePartitionKey(DateTime.UtcNow.AddDays(-(DateTime.UtcNow.Day + 1)));

            whereClause =
                TableQuery.CombineFilters(
                    TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, currentPartition),
                    TableOperators.Or,
                    TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, previousPartition));

            if ((args.FilterOptions & ActivityFilterOptions.WithLocation) == ActivityFilterOptions.WithLocation)
            {
                whereClause = TableQuery.CombineFilters(whereClause, TableOperators.And,
                                                        TableQuery.GenerateFilterConditionForBool(nameof(ActivityTableEntity.HasLocation), QueryComparisons.Equal, true));
            }

            if ((args.FilterOptions & ActivityFilterOptions.WithVenue) == ActivityFilterOptions.WithVenue)
            {
                whereClause = TableQuery.CombineFilters(whereClause, TableOperators.And,
                                                        TableQuery.GenerateFilterCondition(nameof(ActivityTableEntity.VenueId), QueryComparisons.NotEqual, null));
            }

            if (args.ActivityType != ActivityType.None)
            {
                whereClause = TableQuery.CombineFilters(whereClause, TableOperators.And,
                                                        TableQuery.GenerateFilterCondition(nameof(ActivityTableEntity.ActivityType), QueryComparisons.Equal, args.ActivityType.ToString()));
            }

            var result = await storageAccessService.QueryTableAsync <JsonTableEntity <ActivityEntity> >(tableName, whereClause, args.PageSize);

            var resultActivities = result.ResultPage.Select(a => a.Entity).ToList();

            return(resultActivities);
        }
        public async Task <Domain.DrinkEvent> FindCurrentDrinkEventAsync()
        {
            string now = GetRowKey(DateTime.UtcNow);

            var queryResult = await storageAccessService.QueryTableAsync <JsonTableEntity <DrinkEventEntity> >(TableNames.DrinkEvents, StaticPartitionKeys.DrinkEvent, now, 1);

            var result = queryResult.ResultPage.FirstOrDefault()?.Entity;

            if (result == null)
            {
                return(null);
            }

            return(new Domain.DrinkEvent(result.StartUtc, result.EndUtc, result.ScoringUserIds));
        }
        public async Task <List <UserRankingDTO> > Handle(GetDrinksRankingQuery request, CancellationToken cancellationToken)
        {
            string whereClause = TableQuery.GenerateFilterConditionForInt(nameof(UserStatsTableEntity.TotalDrinksLastMonth), QueryComparisons.GreaterThan, 0);
            var    queryResult = await storageAccessService.QueryTableAsync <UserStatsTableEntity>(TableNames.UserStats, whereClause);

            var userStats = queryResult.OrderByDescending(r => r.TotalDrinksLastMonth)
                            .Select(r => new UserStatistics(r.RowKey, r.CurrentAlcoholization, r.CurrentNightDrinks, r.Score, r.TotalDrinksLastMonth))
                            .ToList();

            var userIds = userStats.Select(u => u.UserId).Distinct();
            var users   = await userRepository.SearchUsersAsync(userIds);

            var result = userStats.Select(s => new UserRankingDTO(users.Select(u => new UserInfoDTO(u.Id, u.Name)).First(u => u.UserId == s.UserId), s.ToDto())).ToList();

            return(result);
        }
        public async Task <IEnumerable <UserStatisticHistoryDTO> > Handle(GetStatisticHistoryForUserQuery request, CancellationToken cancellationToken)
        {
            string whereClause =
                TableQuery.CombineFilters(
                    TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, request.UserId),
                    TableOperators.And,
                    TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.GreaterThanOrEqual, DateTime.UtcNow.Subtract(TimeSpan.FromDays(1))
                                                       .ToString("yyyyMMddHHmm")));
            var queryResult = await storageAccessService.QueryTableAsync <UserStatisticHistoryTableEntity>(TableNames.UserStatsHistory, whereClause);

            var result = queryResult
                         .Select(r => new UserStatisticHistoryDTO(r.CalculationTimestamp, r.CurrentAlcLevel))
                         .ToList();

            return(result);
        }
Beispiel #7
0
        public async Task <List <UserEntity> > SearchUsersAsync(IEnumerable <string> userIds = null, string filterText = null)
        {
            string whereClause = BuildWhereClause(userIds);

            var result = await storageAccessService.QueryTableAsync <JsonTableEntity <UserEntity> >(TableNames.Users, whereClause);

            var users = result.OrderByDescending(u => u.Timestamp).Select(r =>
            {
                var user        = r.Entity;
                user.LastOnline = r.Timestamp.UtcDateTime;
                return(user);
            }).ToList();

            // TODO: Should soon be improved!
            if (!string.IsNullOrEmpty(filterText))
            {
                string lowerFilter = filterText.ToLower();
                users = users.Where(u => u.Name.ToLower().Contains(lowerFilter)).ToList();
            }

            return(users);
        }