public Task <List <PressureVm> > Handle(GetPressureQuery request, CancellationToken cancellationToken) { var currentDate = _dateTimeProvider.GetUtcNow(); request.WithDefaultValues(currentDate.AddDays(-2), currentDate); int granulation = (int)(request.Granulation ?? default); var fromDate = request.From !.Value; return(_applicationDbContext.WeatherStationAirParameters .AsNoTracking() .Where(x => x.MeasurementStartTime >= request.From && x.MeasurementEndTime <= request.To) .Select(x => new { TimestampGroup = granulation == (int)DateRangeGranulation.Year ? EF.Functions.DateDiffYear(fromDate, x.MeasurementEndTime) : granulation == (int)DateRangeGranulation.Month ? EF.Functions.DateDiffMonth(fromDate, x.MeasurementEndTime) : EF.Functions.DateDiffSecond(fromDate, x.MeasurementEndTime) / granulation, x.Pressure }) .GroupBy(x => x.TimestampGroup) .OrderBy(x => x.Key) .Select(g => new PressureVm { Timestamp = DateTime.SpecifyKind( granulation == (int)DateRangeGranulation.Year ? fromDate.AddYears(g.Key) : granulation == (int)DateRangeGranulation.Month ? fromDate.AddMonths(g.Key) : fromDate.AddSeconds(g.Key * granulation), DateTimeKind.Utc), Pressure = Math.Round(g.Average(x => x.Pressure), 2), MaxPressure = Math.Round(g.Max(x => x.Pressure), 2), MinPressure = Math.Round(g.Min(x => x.Pressure), 2) }) .ToListAsync(cancellationToken)); }
public Task <IEnumerable <PressureVm> > GetPressure(GetPressureQuery query) { return(_apiClient.Get <GetPressureQuery, IEnumerable <PressureVm> >("WeatherData/pressure", query)); }
public async Task <IActionResult> GetPressure([FromQuery] GetPressureQuery query) { return(Ok(await _mediator.Send(query))); }