public async Task <GetLastWeekAvgStatsDto> GetLastWeekAvgStatsByUserIdAsync(String userId) { GetLastWeekAvgStatsDto stats = await _DailyStats.AsQueryable() .Where(o => o.UserId == userId && o.Date > DateTime.UtcNow.Date.AddDays(-7)) .GroupBy(o => o.UserId) .Select(o => new GetLastWeekAvgStatsDto { Creativity = o.Sum(o => o.Creativity), Fluency = o.Sum(o => o.Fluency), Intelligence = o.Sum(o => o.Intelligence), Strength = o.Sum(o => o.Strength) }).FirstOrDefaultAsync() ?? new GetLastWeekAvgStatsDto();; return(stats.weekAvg().scaleToPercent()); }
public async Task manageRank(String userId) { try { this.userId = userId; stats = await _dailyStatsService.GetLastWeekAvgStatsByUserIdAsync(userId); await calculateRank(); await _userRankService.UpdateAsync(userRank); } catch (Exception e) { _logger.LogError("Error cached in RankManager manageRank {error}", e); throw e; } }