Внести правки после ревью
This commit is contained in:
parent
ba949f2dff
commit
393bb93760
@ -27,12 +27,12 @@ public class WitsDataController : ControllerBase, IWitsDataApi
|
|||||||
/// <param name="discriminatorId"></param>
|
/// <param name="discriminatorId"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet("datesRange")]
|
[HttpGet("{discriminatorId}/datesRange")]
|
||||||
public async Task<ActionResult<DatesRangeDto>> GetDatesRangeAsync([FromQuery] int discriminatorId, CancellationToken token)
|
public async Task<ActionResult<DatesRangeDto>> GetDatesRangeAsync([FromRoute] int discriminatorId, CancellationToken token)
|
||||||
{
|
{
|
||||||
var result = await witsDataService.GetDatesRangeAsync(discriminatorId, token);
|
var result = await witsDataService.GetDatesRangeAsync(discriminatorId, token);
|
||||||
|
|
||||||
return Ok(result);
|
return result == null ? NoContent() : Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -43,8 +43,8 @@ public class WitsDataController : ControllerBase, IWitsDataApi
|
|||||||
/// <param name="take"></param>
|
/// <param name="take"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet("part")]
|
[HttpGet("{discriminatorId}/part")]
|
||||||
public async Task<ActionResult<IEnumerable<WitsDataDto>>> GetPart([FromQuery] int discriminatorId, [FromQuery] DateTimeOffset dateBegin, [FromQuery] int take, CancellationToken token)
|
public async Task<ActionResult<IEnumerable<WitsDataDto>>> GetPart([FromRoute] int discriminatorId, [FromQuery] DateTimeOffset dateBegin, [FromQuery] int take, CancellationToken token)
|
||||||
{
|
{
|
||||||
var result = await witsDataService.GetPart(discriminatorId, dateBegin, take, token);
|
var result = await witsDataService.GetPart(discriminatorId, dateBegin, take, token);
|
||||||
|
|
||||||
@ -60,8 +60,8 @@ public class WitsDataController : ControllerBase, IWitsDataApi
|
|||||||
/// <param name="approxPointsCount">Количество точек</param>
|
/// <param name="approxPointsCount">Количество точек</param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet("graph")]
|
[HttpGet("{discriminatorId}/graph")]
|
||||||
public async Task<ActionResult<IEnumerable<WitsDataDto>>> GetValuesForGraph([FromQuery] int discriminatorId,
|
public async Task<ActionResult<IEnumerable<WitsDataDto>>> GetValuesForGraph([FromRoute] int discriminatorId,
|
||||||
[FromQuery] DateTimeOffset dateFrom, [FromQuery] DateTimeOffset dateTo, [FromQuery] int approxPointsCount, CancellationToken token)
|
[FromQuery] DateTimeOffset dateFrom, [FromQuery] DateTimeOffset dateTo, [FromQuery] int approxPointsCount, CancellationToken token)
|
||||||
{
|
{
|
||||||
var result = await witsDataService.GetValuesForGraph(discriminatorId, dateFrom, dateTo, approxPointsCount, token);
|
var result = await witsDataService.GetValuesForGraph(discriminatorId, dateFrom, dateTo, approxPointsCount, token);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using Persistence.Models;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Persistence.Models;
|
||||||
using Refit;
|
using Refit;
|
||||||
|
|
||||||
namespace Persistence.Client.Clients;
|
namespace Persistence.Client.Clients;
|
||||||
@ -6,15 +7,15 @@ public interface IWitsDataClient
|
|||||||
{
|
{
|
||||||
private const string BaseRoute = "/api/witsData";
|
private const string BaseRoute = "/api/witsData";
|
||||||
|
|
||||||
[Get($"{BaseRoute}/graph")]
|
[Get($"{BaseRoute}/{{discriminatorId}}/graph")]
|
||||||
Task<IApiResponse<IEnumerable<WitsDataDto>>> GetValuesForGraph([Query] int discriminatorId, [Query] DateTimeOffset dateFrom, [Query] DateTimeOffset dateTo, [Query] int approxPointsCount, CancellationToken token);
|
Task<IApiResponse<IEnumerable<WitsDataDto>>> GetValuesForGraph(int discriminatorId, [Query] DateTimeOffset dateFrom, [Query] DateTimeOffset dateTo, [Query] int approxPointsCount, CancellationToken token);
|
||||||
|
|
||||||
[Post($"{BaseRoute}/")]
|
[Post($"{BaseRoute}/")]
|
||||||
Task<IApiResponse<int>> AddRange([Body] IEnumerable<WitsDataDto> dtos, CancellationToken token);
|
Task<IApiResponse<int>> AddRange(IEnumerable<WitsDataDto> dtos, CancellationToken token);
|
||||||
|
|
||||||
[Get($"{BaseRoute}/part")]
|
[Get($"{BaseRoute}/{{discriminatorId}}/part")]
|
||||||
Task<IApiResponse<IEnumerable<WitsDataDto>>> GetPart([Query] int discriminatorId, [Query] DateTimeOffset dateBegin, [Query] int take = 24 * 60 * 60, CancellationToken token = default);
|
Task<IApiResponse<IEnumerable<WitsDataDto>>> GetPart(int discriminatorId, [Query] DateTimeOffset dateBegin, [Query] int take = 24 * 60 * 60, CancellationToken token = default);
|
||||||
|
|
||||||
[Get($"{BaseRoute}/datesRange")]
|
[Get($"{BaseRoute}/{{discriminatorId}}/datesRange")]
|
||||||
Task<IApiResponse<DatesRangeDto>> GetDatesRangeAsync([Query] int discriminatorId, CancellationToken token);
|
Task<IApiResponse<DatesRangeDto>> GetDatesRangeAsync(int discriminatorId, CancellationToken token);
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ namespace Persistence.IntegrationTests.Controllers
|
|||||||
dbContext.CleanupDbSet<Setpoint>();
|
dbContext.CleanupDbSet<Setpoint>();
|
||||||
|
|
||||||
//act
|
//act
|
||||||
var response = await setpointClient.GetDatesRangeAsync(new CancellationToken());
|
var response = await setpointClient.GetDatesRangeAsync(CancellationToken.None);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
@ -159,10 +159,10 @@ namespace Persistence.IntegrationTests.Controllers
|
|||||||
|
|
||||||
var dateBegin = DateTimeOffset.MinValue;
|
var dateBegin = DateTimeOffset.MinValue;
|
||||||
var take = 1;
|
var take = 1;
|
||||||
var part = await setpointClient.GetPart(dateBegin, take, new CancellationToken());
|
var part = await setpointClient.GetPart(dateBegin, take, CancellationToken.None);
|
||||||
|
|
||||||
//act
|
//act
|
||||||
var response = await setpointClient.GetDatesRangeAsync(new CancellationToken());
|
var response = await setpointClient.GetDatesRangeAsync(CancellationToken.None);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
@ -188,7 +188,7 @@ namespace Persistence.IntegrationTests.Controllers
|
|||||||
var take = 2;
|
var take = 2;
|
||||||
|
|
||||||
//act
|
//act
|
||||||
var response = await setpointClient.GetPart(dateBegin, take, new CancellationToken());
|
var response = await setpointClient.GetPart(dateBegin, take, CancellationToken.None);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
@ -205,7 +205,7 @@ namespace Persistence.IntegrationTests.Controllers
|
|||||||
await Add();
|
await Add();
|
||||||
|
|
||||||
//act
|
//act
|
||||||
var response = await setpointClient.GetPart(dateBegin, take, new CancellationToken());
|
var response = await setpointClient.GetPart(dateBegin, take, CancellationToken.None);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
|
@ -40,7 +40,7 @@ namespace Persistence.IntegrationTests.Controllers
|
|||||||
};
|
};
|
||||||
|
|
||||||
//act
|
//act
|
||||||
var response = await techMessagesClient.GetPage(requestDto, new CancellationToken());
|
var response = await techMessagesClient.GetPage(requestDto, CancellationToken.None);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
@ -64,7 +64,7 @@ namespace Persistence.IntegrationTests.Controllers
|
|||||||
};
|
};
|
||||||
|
|
||||||
//act
|
//act
|
||||||
var response = await techMessagesClient.GetPage(requestDto, new CancellationToken());
|
var response = await techMessagesClient.GetPage(requestDto, CancellationToken.None);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
@ -97,7 +97,7 @@ namespace Persistence.IntegrationTests.Controllers
|
|||||||
};
|
};
|
||||||
|
|
||||||
//act
|
//act
|
||||||
var response = await techMessagesClient.AddRange(dtos, new CancellationToken());
|
var response = await techMessagesClient.AddRange(dtos, CancellationToken.None);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
||||||
@ -112,7 +112,7 @@ namespace Persistence.IntegrationTests.Controllers
|
|||||||
dbContext.CleanupDbSet<Database.Entity.DrillingSystem>();
|
dbContext.CleanupDbSet<Database.Entity.DrillingSystem>();
|
||||||
|
|
||||||
//act
|
//act
|
||||||
var response = await techMessagesClient.GetSystems(new CancellationToken());
|
var response = await techMessagesClient.GetSystems(CancellationToken.None);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
@ -131,7 +131,7 @@ namespace Persistence.IntegrationTests.Controllers
|
|||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
//act
|
//act
|
||||||
var response = await techMessagesClient.GetSystems(new CancellationToken());
|
var response = await techMessagesClient.GetSystems(CancellationToken.None);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
@ -152,7 +152,7 @@ namespace Persistence.IntegrationTests.Controllers
|
|||||||
var autoDrillingSystem = nameof(TechMessageDto.System);
|
var autoDrillingSystem = nameof(TechMessageDto.System);
|
||||||
|
|
||||||
//act
|
//act
|
||||||
var response = await techMessagesClient.GetStatistics(autoDrillingSystem, imortantId, new CancellationToken());
|
var response = await techMessagesClient.GetStatistics(autoDrillingSystem, imortantId, CancellationToken.None);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
@ -170,7 +170,7 @@ namespace Persistence.IntegrationTests.Controllers
|
|||||||
var filteredDtos = dtos.Where(e => e.CategoryId == imortantId && e.System == autoDrillingSystem);
|
var filteredDtos = dtos.Where(e => e.CategoryId == imortantId && e.System == autoDrillingSystem);
|
||||||
|
|
||||||
//act
|
//act
|
||||||
var response = await techMessagesClient.GetStatistics(autoDrillingSystem, imortantId, new CancellationToken());
|
var response = await techMessagesClient.GetStatistics(autoDrillingSystem, imortantId, CancellationToken.None);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
@ -185,7 +185,7 @@ namespace Persistence.IntegrationTests.Controllers
|
|||||||
public async Task GetDatesRange_returns_success()
|
public async Task GetDatesRange_returns_success()
|
||||||
{
|
{
|
||||||
//act
|
//act
|
||||||
var response = await techMessagesClient.GetDatesRangeAsync(new CancellationToken());
|
var response = await techMessagesClient.GetDatesRangeAsync(CancellationToken.None);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
@ -201,7 +201,7 @@ namespace Persistence.IntegrationTests.Controllers
|
|||||||
await InsertRange();
|
await InsertRange();
|
||||||
|
|
||||||
//act
|
//act
|
||||||
var response = await techMessagesClient.GetDatesRangeAsync(new CancellationToken());
|
var response = await techMessagesClient.GetDatesRangeAsync(CancellationToken.None);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
@ -218,7 +218,7 @@ namespace Persistence.IntegrationTests.Controllers
|
|||||||
var take = 2;
|
var take = 2;
|
||||||
|
|
||||||
//act
|
//act
|
||||||
var response = await techMessagesClient.GetPart(dateBegin, take, new CancellationToken());
|
var response = await techMessagesClient.GetPart(dateBegin, take, CancellationToken.None);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
@ -235,7 +235,7 @@ namespace Persistence.IntegrationTests.Controllers
|
|||||||
await InsertRange();
|
await InsertRange();
|
||||||
|
|
||||||
//act
|
//act
|
||||||
var response = await techMessagesClient.GetPart(dateBegin, take, new CancellationToken());
|
var response = await techMessagesClient.GetPart(dateBegin, take, CancellationToken.None);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
@ -276,7 +276,7 @@ namespace Persistence.IntegrationTests.Controllers
|
|||||||
|
|
||||||
|
|
||||||
//act
|
//act
|
||||||
var response = await techMessagesClient.AddRange(dtos, new CancellationToken());
|
var response = await techMessagesClient.AddRange(dtos, CancellationToken.None);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.Equal(HttpStatusCode.Created, response.StatusCode);
|
Assert.Equal(HttpStatusCode.Created, response.StatusCode);
|
||||||
|
@ -29,7 +29,7 @@ public class WitsDataControllerTest : BaseIntegrationTest
|
|||||||
var discriminatorId = 1;
|
var discriminatorId = 1;
|
||||||
|
|
||||||
//act
|
//act
|
||||||
var response = await witsDataClient.GetDatesRangeAsync(discriminatorId, new CancellationToken());
|
var response = await witsDataClient.GetDatesRangeAsync(discriminatorId, CancellationToken.None);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
@ -47,7 +47,7 @@ public class WitsDataControllerTest : BaseIntegrationTest
|
|||||||
var take = 1;
|
var take = 1;
|
||||||
|
|
||||||
//act
|
//act
|
||||||
var response = await witsDataClient.GetPart(discriminatorId, dateBegin, take, new CancellationToken());
|
var response = await witsDataClient.GetPart(discriminatorId, dateBegin, take, CancellationToken.None);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
@ -77,7 +77,7 @@ public class WitsDataControllerTest : BaseIntegrationTest
|
|||||||
var approxPointCount = 12;
|
var approxPointCount = 12;
|
||||||
|
|
||||||
//act
|
//act
|
||||||
var response = await witsDataClient.GetValuesForGraph(discriminatorId, dateFrom, dateTo, approxPointCount, new CancellationToken());
|
var response = await witsDataClient.GetValuesForGraph(discriminatorId, dateFrom, dateTo, approxPointCount, CancellationToken.None);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
@ -95,7 +95,7 @@ public class WitsDataControllerTest : BaseIntegrationTest
|
|||||||
var discriminatorId = dtos.FirstOrDefault()!.DiscriminatorId;
|
var discriminatorId = dtos.FirstOrDefault()!.DiscriminatorId;
|
||||||
|
|
||||||
//act
|
//act
|
||||||
var response = await witsDataClient.GetDatesRangeAsync(discriminatorId, new CancellationToken());
|
var response = await witsDataClient.GetDatesRangeAsync(discriminatorId, CancellationToken.None);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
@ -111,9 +111,9 @@ public class WitsDataControllerTest : BaseIntegrationTest
|
|||||||
|
|
||||||
var expectedDateTo = dtos
|
var expectedDateTo = dtos
|
||||||
.Select(e => e.Timestamped)
|
.Select(e => e.Timestamped)
|
||||||
.Min()
|
.Max()
|
||||||
.ToString("dd.MM.yyyy-HH:mm:ss");
|
.ToString("dd.MM.yyyy-HH:mm:ss");
|
||||||
var actualDateTo = response.Content.From.DateTime
|
var actualDateTo = response.Content.To.DateTime
|
||||||
.ToString("dd.MM.yyyy-HH:mm:ss");
|
.ToString("dd.MM.yyyy-HH:mm:ss");
|
||||||
Assert.Equal(expectedDateTo, actualDateTo);
|
Assert.Equal(expectedDateTo, actualDateTo);
|
||||||
}
|
}
|
||||||
@ -130,13 +130,22 @@ public class WitsDataControllerTest : BaseIntegrationTest
|
|||||||
var take = 1;
|
var take = 1;
|
||||||
|
|
||||||
//act
|
//act
|
||||||
var response = await witsDataClient.GetPart(discriminatorId, dateBegin, take, new CancellationToken());
|
var response = await witsDataClient.GetPart(discriminatorId, dateBegin, take, CancellationToken.None);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
Assert.NotNull(response.Content);
|
Assert.NotNull(response.Content);
|
||||||
Assert.NotEmpty(response.Content);
|
Assert.NotEmpty(response.Content);
|
||||||
Assert.Equal(take, response.Content.Count());
|
Assert.Equal(take, response.Content.Count());
|
||||||
|
|
||||||
|
var expectedDto = dtos.FirstOrDefault();
|
||||||
|
var actualDto = response.Content.FirstOrDefault();
|
||||||
|
Assert.Equal(expectedDto?.DiscriminatorId, actualDto?.DiscriminatorId);
|
||||||
|
|
||||||
|
var expectedValueDto = expectedDto?.Values.FirstOrDefault();
|
||||||
|
var actualValueDto = actualDto?.Values.FirstOrDefault();
|
||||||
|
Assert.Equal(expectedValueDto?.ItemId, actualValueDto?.ItemId);
|
||||||
|
Assert.Equal(expectedValueDto?.RecordId, actualValueDto?.RecordId);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -152,7 +161,7 @@ public class WitsDataControllerTest : BaseIntegrationTest
|
|||||||
var approxPointCount = 12;
|
var approxPointCount = 12;
|
||||||
|
|
||||||
//act
|
//act
|
||||||
var response = await witsDataClient.GetValuesForGraph(discriminatorId, dateFrom, dateTo, approxPointCount, new CancellationToken());
|
var response = await witsDataClient.GetValuesForGraph(discriminatorId, dateFrom, dateTo, approxPointCount, CancellationToken.None);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
@ -161,7 +170,7 @@ public class WitsDataControllerTest : BaseIntegrationTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task InsertRange_returns_BadRequest()
|
public async Task AddRange_returns_BadRequest()
|
||||||
{
|
{
|
||||||
//arrange
|
//arrange
|
||||||
var dtos = new List<WitsDataDto>()
|
var dtos = new List<WitsDataDto>()
|
||||||
@ -183,7 +192,7 @@ public class WitsDataControllerTest : BaseIntegrationTest
|
|||||||
};
|
};
|
||||||
|
|
||||||
//act
|
//act
|
||||||
var response = await witsDataClient.AddRange(dtos, new CancellationToken());
|
var response = await witsDataClient.AddRange(dtos, CancellationToken.None);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
||||||
@ -193,8 +202,9 @@ public class WitsDataControllerTest : BaseIntegrationTest
|
|||||||
{
|
{
|
||||||
var dtos = new List<WitsDataDto>();
|
var dtos = new List<WitsDataDto>();
|
||||||
var timestamped = DateTimeOffset.UtcNow;
|
var timestamped = DateTimeOffset.UtcNow;
|
||||||
for (var i = 0; i < countToCreate && i < 100; i++)
|
for (var i = 0; i < countToCreate; i++)
|
||||||
{
|
{
|
||||||
|
var random = new Random();
|
||||||
dtos.Add(new WitsDataDto()
|
dtos.Add(new WitsDataDto()
|
||||||
{
|
{
|
||||||
DiscriminatorId = 1,
|
DiscriminatorId = 1,
|
||||||
@ -205,14 +215,14 @@ public class WitsDataControllerTest : BaseIntegrationTest
|
|||||||
{
|
{
|
||||||
RecordId = i + 1,
|
RecordId = i + 1,
|
||||||
ItemId = i + 1,
|
ItemId = i + 1,
|
||||||
Value = new Random().Next(1, 100)
|
Value = random.Next(1, 100)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//act
|
//act
|
||||||
var response = await witsDataClient.AddRange(dtos, new CancellationToken());
|
var response = await witsDataClient.AddRange(dtos, CancellationToken.None);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
var count = dtos.SelectMany(e => e.Values).Count();
|
var count = dtos.SelectMany(e => e.Values).Count();
|
||||||
|
@ -58,7 +58,8 @@ public class ParameterRepository : IParameterRepository
|
|||||||
var universalDateTo = dateTo.ToUniversalTime();
|
var universalDateTo = dateTo.ToUniversalTime();
|
||||||
|
|
||||||
query = query
|
query = query
|
||||||
.Where(e => e.DiscriminatorId == discriminatorId && e.Timestamp >= universalDateFrom && e.Timestamp <= universalDateTo)
|
.Where(e => e.DiscriminatorId == discriminatorId)
|
||||||
|
.Where(e => e.Timestamp >= universalDateFrom && e.Timestamp <= universalDateTo)
|
||||||
.OrderBy(e => e.Timestamp);
|
.OrderBy(e => e.Timestamp);
|
||||||
if (ratio != null)
|
if (ratio != null)
|
||||||
{
|
{
|
||||||
@ -67,7 +68,7 @@ public class ParameterRepository : IParameterRepository
|
|||||||
|
|
||||||
var entities = await query
|
var entities = await query
|
||||||
.Take((int)(2.5 * approxPointsCount))
|
.Take((int)(2.5 * approxPointsCount))
|
||||||
.ToListAsync(token);
|
.ToArrayAsync(token);
|
||||||
|
|
||||||
var dtos = entities.Select(e => e.Adapt<ParameterDto>());
|
var dtos = entities.Select(e => e.Adapt<ParameterDto>());
|
||||||
|
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
namespace Persistence.Models.Configurations;
|
namespace Persistence.Models.Configurations;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Протокол Wits
|
||||||
|
/// </summary>
|
||||||
public class WitsInfo
|
public class WitsInfo
|
||||||
{
|
{
|
||||||
public int RecordId { get; set; }
|
public int RecordId { get; set; }
|
||||||
|
@ -18,7 +18,7 @@ public class WitsDataService : IWitsDataService
|
|||||||
private const int multiplier = 1000;
|
private const int multiplier = 1000;
|
||||||
private const string witsConfigPath = "Persistence.Services.Config.WitsConfig.json";
|
private const string witsConfigPath = "Persistence.Services.Config.WitsConfig.json";
|
||||||
|
|
||||||
public WitsDataService(IParameterRepository witsDataRepository, IConfiguration configuration)
|
public WitsDataService(IParameterRepository witsDataRepository)
|
||||||
{
|
{
|
||||||
this.witsDataRepository = witsDataRepository;
|
this.witsDataRepository = witsDataRepository;
|
||||||
|
|
||||||
@ -96,30 +96,60 @@ public class WitsDataService : IWitsDataService
|
|||||||
private IEnumerable<WitsDataDto> AdaptToWitsData(IEnumerable<ParameterDto> dtos)
|
private IEnumerable<WitsDataDto> AdaptToWitsData(IEnumerable<ParameterDto> dtos)
|
||||||
{
|
{
|
||||||
var result = new List<WitsDataDto>();
|
var result = new List<WitsDataDto>();
|
||||||
foreach (var dto in dtos)
|
var witsGroup = dtos
|
||||||
|
.GroupBy(e => new { e.DiscriminatorId, e.Timestamp });
|
||||||
|
foreach (var witsInGroup in witsGroup)
|
||||||
{
|
{
|
||||||
var witsDataDto = result.FirstOrDefault(e => e.DiscriminatorId == dto.DiscriminatorId && e.Timestamped == dto.Timestamp);
|
var witsDataDto = new WitsDataDto()
|
||||||
if (witsDataDto == null)
|
|
||||||
{
|
{
|
||||||
witsDataDto = new WitsDataDto()
|
DiscriminatorId = witsInGroup.Key.DiscriminatorId,
|
||||||
{
|
Timestamped = witsInGroup.Key.Timestamp
|
||||||
DiscriminatorId = dto.DiscriminatorId,
|
|
||||||
Timestamped = dto.Timestamp
|
|
||||||
};
|
|
||||||
result.Add(witsDataDto);
|
|
||||||
}
|
|
||||||
var recordId = DecodeRecordId(dto.ParameterId);
|
|
||||||
var itemId = DecodeItemId(dto.ParameterId);
|
|
||||||
var witsValueDto = new WitsValueDto()
|
|
||||||
{
|
|
||||||
RecordId = recordId,
|
|
||||||
ItemId = itemId,
|
|
||||||
Value = ConvertValue(recordId, itemId, dto.Value)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
witsDataDto.Values.Append(witsValueDto);
|
witsDataDto.Values = witsInGroup.Select(e =>
|
||||||
|
{
|
||||||
|
var recordId = DecodeRecordId(e.ParameterId);
|
||||||
|
var itemId = DecodeItemId(e.ParameterId);
|
||||||
|
|
||||||
|
return new WitsValueDto()
|
||||||
|
{
|
||||||
|
RecordId = recordId,
|
||||||
|
ItemId = itemId,
|
||||||
|
Value = ConvertValue(recordId, itemId, e.Value)
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
result.Add(witsDataDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//foreach (var dto in dtos)
|
||||||
|
//{
|
||||||
|
// var witsDataDto = result
|
||||||
|
// .Where(e => e.DiscriminatorId == dto.DiscriminatorId)
|
||||||
|
// .Where(e => e.Timestamped == dto.Timestamp)
|
||||||
|
// .FirstOrDefault();
|
||||||
|
// if (witsDataDto == null)
|
||||||
|
// {
|
||||||
|
// witsDataDto = new WitsDataDto()
|
||||||
|
// {
|
||||||
|
// DiscriminatorId = dto.DiscriminatorId,
|
||||||
|
// Timestamped = dto.Timestamp
|
||||||
|
// };
|
||||||
|
// result.Add(witsDataDto);
|
||||||
|
// }
|
||||||
|
// var recordId = DecodeRecordId(dto.ParameterId);
|
||||||
|
// var itemId = DecodeItemId(dto.ParameterId);
|
||||||
|
// var witsValueDto = new WitsValueDto()
|
||||||
|
// {
|
||||||
|
// RecordId = recordId,
|
||||||
|
// ItemId = itemId,
|
||||||
|
// Value = ConvertValue(recordId, itemId, dto.Value)
|
||||||
|
// };
|
||||||
|
|
||||||
|
// witsDataDto.Values = witsDataDto.Values.Append(witsValueDto);
|
||||||
|
//}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user