Ejemplo n.º 1
0
        public IEnumerable <GetAnalyticCovidCasesResult> Handle(GetAnalyticCovidCasesFilter filter)
        {
            var data = _csvContext.GetCsvData <CovidData>("Resources/input.csv");

            var result = data
                         .Select(x => new GetAnalyticCovidCasesResult
            {
                Cases  = x.Cases,
                Date   = x.Date,
                Deaths = x.Deaths,
                Uf     = x.Uf
            });

            if (!string.IsNullOrEmpty(filter?.month))
            {
                result = result
                         .Where(x => x.Date.ToString("yyyy-MM") == filter.month);
            }
            if (!string.IsNullOrEmpty(filter?.uf))
            {
                result = result
                         .Where(x => x.Uf == filter.uf);
            }

            return(result);
        }
Ejemplo n.º 2
0
        public IEnumerable <GetSyntheticCovidCasesResult> Handle(GetSyntheticCovidCasesFilter filter)
        {
            var data = _csvContext.GetCsvData <CovidData>("Resources/input.csv");

            var result = data
                         .Select(x => new
            {
                month = Convert.ToDateTime(x.Date).ToString("yyyy-MM"),
                x.Cases,
                x.Deaths
            })
                         .GroupBy(x => new
            {
                x.month
            })
                         .Select(x => new GetSyntheticCovidCasesResult
            {
                month  = x.Key.month,
                cases  = x.Sum(y => y.Cases),
                deaths = x.Sum(y => y.Deaths)
            });

            if (!string.IsNullOrEmpty(filter?.month))
            {
                result = result.Where(x => x.month == filter.month);
            }

            return(result);
        }