public IActionResult Get([FromServices] StatisticsRedisHandler statsRedisHandler, int year = -1, int month = -1)
        {
            DateTime dateTime;

            if (year > -1 && (year < 1000 || year > 9999))
            {
                return(new HttpStatusCodeWithErrorResult(StatusCodes.Status400BadRequest, string.Format(GlobalResources.TheArgument_0_MustBeInFormat_1, "year", "yyyy")));
            }
            if (month > -1 && (month < 1 || month > 12))
            {
                return(new HttpStatusCodeWithErrorResult(StatusCodes.Status400BadRequest, string.Format(GlobalResources.TheArgument_0_MustBeInFormat_1, "month", "MM")));
            }

            var yearMonth = string.Format("{0}{1}", year > -1 ? year.ToString() : string.Empty, month > -1 ? $"-{month.ToString("D2")}" : string.Empty);

            var requestsDic = statsRedisHandler.GetRequests(yearMonth);
            var stats       = new StatisticsWrapper
            {
                Sum        = statsRedisHandler.GetAllRequestCount(),
                Statistics = requestsDic.ToDictionary(rd =>
                                                      rd.Key,
                                                      rd => new Statistics
                {
                    Sum     = rd.Value.Sum(r => r.Value),
                    Actions = rd.Value.Select(r => new SDK.Net.Models.Action {
                        Name = r.Key, Count = r.Value
                    }).ToList()
                })
            };

            return(Ok(stats));
        }
Beispiel #2
0
 public TicTacToeForm()
 {
     InitializeComponent();
     // Создаём экземпляр класса StatisticsWrapper
     wrapper = new StatisticsWrapper();
     // Создаем экземпляр класса TicTacToeFormLogic,
     // передаем в него словарь с кнопками, лейблы для вывода информации, изображения для ячеек и объект wrapper
     logic = new TicTacToeFormLogic(gameFieldGroupBox.Controls.Cast <Button>().ToDictionary(b => (byte)b.TabIndex, b => b),
                                    currentSideLabel, resultLabel, uriTextBox, Properties.Resources.X, Properties.Resources.O, Properties.Resources.Empty, wrapper);
 }
        public async Task <IActionResult> GetBasicEntriesAndByCategoriesAsync(DateTime startDate, DateTime endDate, [FromBody] List <Guid> categoryIds)
        {
            List <MeasureCategory> measureCategories = new List <MeasureCategory>();

            foreach (Guid categoryId in categoryIds)
            {
                MeasureCategory measureCategory = await _measureCategoryRepository.GetByIdAndProfileIdAsync(categoryId, _currentProfileId);

                if (measureCategory == null)
                {
                    return(CreateErrorResponse("Erro de categoria", $"Nenhuma categoria de medição com esse Id {categoryId} foi encontrada no banco de dados."));
                }

                measureCategories.Add(measureCategory);
            }

            StatisticsWrapper wrapper = await _measureStatisticsDomainService.GetBasicEntriesAndByCategoriesAsync(measureCategories, startDate, endDate);

            return(CreateResponse(wrapper));
        }