2024-11-20 15:22:23 +05:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2024-11-14 15:17:43 +05:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2024-12-16 15:38:46 +05:00
|
|
|
|
using DD.Persistence.Models;
|
|
|
|
|
using DD.Persistence.Repositories;
|
2024-11-14 15:17:43 +05:00
|
|
|
|
|
2024-12-16 15:38:46 +05:00
|
|
|
|
namespace DD.Persistence.API.Controllers;
|
2024-11-27 13:08:06 +05:00
|
|
|
|
|
2024-11-14 15:17:43 +05:00
|
|
|
|
[ApiController]
|
2024-11-20 15:22:23 +05:00
|
|
|
|
[Authorize]
|
2024-11-14 15:17:43 +05:00
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
public class TimeSeriesController<TDto> : ControllerBase, ITimeSeriesDataApi<TDto>
|
|
|
|
|
where TDto : class, ITimeSeriesAbstractDto, new()
|
|
|
|
|
{
|
2024-12-09 13:19:55 +05:00
|
|
|
|
private readonly ITimeSeriesDataRepository<TDto> timeSeriesDataRepository;
|
2024-11-14 15:17:43 +05:00
|
|
|
|
|
2024-12-09 13:19:55 +05:00
|
|
|
|
public TimeSeriesController(ITimeSeriesDataRepository<TDto> timeSeriesDataRepository)
|
|
|
|
|
{
|
|
|
|
|
this.timeSeriesDataRepository = timeSeriesDataRepository;
|
2024-11-14 15:17:43 +05:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-09 13:19:55 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получить список объектов, удовлетворяющий диапазону дат
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dateBegin"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
2024-11-14 15:17:43 +05:00
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2024-11-21 17:02:36 +05:00
|
|
|
|
public async Task<IActionResult> Get(DateTimeOffset dateBegin, CancellationToken token)
|
2024-11-14 15:17:43 +05:00
|
|
|
|
{
|
2024-12-02 15:14:00 +05:00
|
|
|
|
var result = await timeSeriesDataRepository.GetGtDate(dateBegin, token);
|
2024-11-14 15:17:43 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-09 13:19:55 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получить диапазон дат, для которых есть данные в репозитории
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("datesRange")]
|
2024-11-21 17:02:36 +05:00
|
|
|
|
public async Task<IActionResult> GetDatesRange(CancellationToken token)
|
2024-11-14 15:17:43 +05:00
|
|
|
|
{
|
2024-12-02 15:14:00 +05:00
|
|
|
|
var result = await timeSeriesDataRepository.GetDatesRange(token);
|
2024-11-20 15:22:23 +05:00
|
|
|
|
return Ok(result);
|
2024-11-14 15:17:43 +05:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-09 13:19:55 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получить список объектов с прореживанием, удовлетворяющий диапазону дат
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dateBegin"></param>
|
|
|
|
|
/// <param name="intervalSec"></param>
|
|
|
|
|
/// <param name="approxPointsCount"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("resampled")]
|
2024-11-22 16:48:55 +05:00
|
|
|
|
public async Task<IActionResult> GetResampledData(DateTimeOffset dateBegin, double intervalSec = 600d, int approxPointsCount = 1024, CancellationToken token = default)
|
2024-11-21 17:02:36 +05:00
|
|
|
|
{
|
2024-12-02 15:14:00 +05:00
|
|
|
|
var result = await timeSeriesDataRepository.GetResampledData(dateBegin, intervalSec, approxPointsCount, token);
|
2024-11-22 15:47:00 +05:00
|
|
|
|
return Ok(result);
|
2024-11-21 17:02:36 +05:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-09 13:19:55 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавить записи
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dtos"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
2024-12-04 14:18:57 +05:00
|
|
|
|
public async Task<IActionResult> AddRange(IEnumerable<TDto> dtos, CancellationToken token)
|
2024-11-14 15:17:43 +05:00
|
|
|
|
{
|
2024-12-04 14:18:57 +05:00
|
|
|
|
var result = await timeSeriesDataRepository.AddRange(dtos, token);
|
2024-11-14 15:17:43 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
2024-11-21 17:02:36 +05:00
|
|
|
|
|
|
|
|
|
|
2024-11-14 15:17:43 +05:00
|
|
|
|
}
|