forked from ddrilling/AsbCloudServer
дополнен фоновый сервис наработок
доработан контроллер наработок подсистем переименованы модели ДТО
This commit is contained in:
parent
9f23a45be7
commit
2c4d6a9a53
@ -9,7 +9,7 @@ namespace AsbCloudApp.Data.Subsystems
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Статистика подсистемы
|
/// Статистика подсистемы
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SubsystemStatisticsDto
|
public class SubsystemStatDto
|
||||||
{
|
{
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
@ -12,7 +12,7 @@ namespace AsbCloudApp.Services.Subsystems
|
|||||||
public interface ISubsystemOperationTimeService
|
public interface ISubsystemOperationTimeService
|
||||||
{
|
{
|
||||||
Task<IEnumerable<SubsystemDto>> GetSubsystemAsync(int idWell, CancellationToken token);
|
Task<IEnumerable<SubsystemDto>> GetSubsystemAsync(int idWell, CancellationToken token);
|
||||||
Task<IEnumerable<SubsystemStatisticsDto>> GetStatAsync(SubsystemOperationTimeRequest request, CancellationToken token);
|
Task<IEnumerable<SubsystemStatDto>> GetStatAsync(SubsystemOperationTimeRequest request, CancellationToken token);
|
||||||
Task<int> DeleteAsync(SubsystemOperationTimeRequest request, CancellationToken token);
|
Task<int> DeleteAsync(SubsystemOperationTimeRequest request, CancellationToken token);
|
||||||
Task<IEnumerable<SubsystemOperationTimeDto>> GetOperationTimeAsync(SubsystemOperationTimeRequest request, CancellationToken token);
|
Task<IEnumerable<SubsystemOperationTimeDto>> GetOperationTimeAsync(SubsystemOperationTimeRequest request, CancellationToken token);
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using AsbCloudApp.Data.SAUB;
|
using AsbCloudApp.Data.SAUB;
|
||||||
using AsbCloudApp.Data.Subsystems;
|
using AsbCloudApp.Data.Subsystems;
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
|
using AsbCloudApp.Services.Subsystems;
|
||||||
using AsbCloudDb.Model;
|
using AsbCloudDb.Model;
|
||||||
using AsbCloudDb.Model.Subsystems;
|
using AsbCloudDb.Model.Subsystems;
|
||||||
using AsbCloudInfrastructure.Repository;
|
using AsbCloudInfrastructure.Repository;
|
||||||
@ -87,7 +88,7 @@ namespace AsbCloudInfrastructure
|
|||||||
services.AddScoped<IEmailService, EmailService>();
|
services.AddScoped<IEmailService, EmailService>();
|
||||||
|
|
||||||
services.AddHostedService<OperationDetectionBackgroundService>();
|
services.AddHostedService<OperationDetectionBackgroundService>();
|
||||||
//services.AddHostedService<SubsystemOperationTimeBackgroundService>();
|
services.AddHostedService<SubsystemOperationTimeBackgroundService>();
|
||||||
services.AddSingleton(new WitsInfoService());
|
services.AddSingleton(new WitsInfoService());
|
||||||
services.AddSingleton(new CacheDb());
|
services.AddSingleton(new CacheDb());
|
||||||
services.AddSingleton(new InstantDataRepository());
|
services.AddSingleton(new InstantDataRepository());
|
||||||
@ -122,6 +123,7 @@ namespace AsbCloudInfrastructure
|
|||||||
services.AddTransient<IDrillerService, DrillerService>();
|
services.AddTransient<IDrillerService, DrillerService>();
|
||||||
services.AddTransient<IScheduleService, ScheduleService>();
|
services.AddTransient<IScheduleService, ScheduleService>();
|
||||||
services.AddTransient<IOperationValueService, OperationValueService>();
|
services.AddTransient<IOperationValueService, OperationValueService>();
|
||||||
|
//services.AddTransient<ISubsystemOperationTimeService, SubsystemOperationTimeService>();
|
||||||
|
|
||||||
// admin crud services:
|
// admin crud services:
|
||||||
services.AddTransient<ICrudService<TelemetryDto>, CrudServiceBase<TelemetryDto, Telemetry>>(s =>
|
services.AddTransient<ICrudService<TelemetryDto>, CrudServiceBase<TelemetryDto, Telemetry>>(s =>
|
||||||
|
@ -87,11 +87,17 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
foreach (var item in JounedlastDetectedDates)
|
foreach (var item in JounedlastDetectedDates)
|
||||||
{
|
{
|
||||||
var stopwatch = Stopwatch.StartNew();
|
var stopwatch = Stopwatch.StartNew();
|
||||||
var newOperations = await OperationTimeSaubAsync(item.IdTelemetry, item.LastDate ?? DateTimeOffset.MinValue, db, token);
|
var newOperationsSaub = await OperationTimeSaubAsync(item.IdTelemetry, item.LastDate ?? DateTimeOffset.MinValue, db, token);
|
||||||
|
var newOperationsSpin = await OperationTimeSpinAsync(item.IdTelemetry, item.LastDate ?? DateTimeOffset.MinValue, db, token);
|
||||||
stopwatch.Stop();
|
stopwatch.Stop();
|
||||||
if (newOperations.Any())
|
if (newOperationsSaub.Any())
|
||||||
{
|
{
|
||||||
db.SubsystemOperationTimes.AddRange(newOperations);
|
db.SubsystemOperationTimes.AddRange(newOperationsSaub);
|
||||||
|
affected += await db.SaveChangesAsync(token);
|
||||||
|
}
|
||||||
|
if (newOperationsSpin.Any())
|
||||||
|
{
|
||||||
|
db.SubsystemOperationTimes.AddRange(newOperationsSpin);
|
||||||
affected += await db.SaveChangesAsync(token);
|
affected += await db.SaveChangesAsync(token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -113,15 +119,14 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
|
|
||||||
var take = 4 * 86_400; // 4 дня
|
var take = 4 * 86_400; // 4 дня
|
||||||
var startDate = begin;
|
var startDate = begin;
|
||||||
var resultSubsystemOperationTime = new List<SubsystemOperationTime>();
|
|
||||||
var firstItem = query.FirstOrDefault();
|
var firstItem = query.FirstOrDefault();
|
||||||
if (firstItem is null)
|
if (firstItem is null)
|
||||||
return null;
|
return null;
|
||||||
short? mode = firstItem.Mode;
|
short? mode = firstItem.Mode;
|
||||||
DateTimeOffset dateBegin = firstItem.DateTime;
|
DateTimeOffset dateBegin = firstItem.DateTime;
|
||||||
float? depthStart = firstItem.Depth;
|
float? depthStart = firstItem.Depth;
|
||||||
while (true)
|
var resultSubsystemOperationTime = new List<SubsystemOperationTime>();
|
||||||
{
|
|
||||||
var data = await query
|
var data = await query
|
||||||
.Where(d => d.DateTime > startDate)
|
.Where(d => d.DateTime > startDate)
|
||||||
.Take(take)
|
.Take(take)
|
||||||
@ -134,6 +139,7 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
{
|
{
|
||||||
IdTelemetry = idTelemetry,
|
IdTelemetry = idTelemetry,
|
||||||
DateStart = dateBegin,
|
DateStart = dateBegin,
|
||||||
|
IdSubsystem = (int)data[i - 1].Mode,
|
||||||
DateEnd = data[i - 1].DateTime,
|
DateEnd = data[i - 1].DateTime,
|
||||||
DepthStart = depthStart,
|
DepthStart = depthStart,
|
||||||
DepthEnd = data[i - 1].Depth
|
DepthEnd = data[i - 1].Depth
|
||||||
@ -146,67 +152,64 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
startDate = data.Last().DateTime;
|
startDate = data.Last().DateTime;
|
||||||
}
|
|
||||||
return resultSubsystemOperationTime;
|
return resultSubsystemOperationTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
//private static async Task<IEnumerable<SubsystemOperationTime>> OperationTimeSpinAsync(int idTelemetry, DateTimeOffset begin, IAsbCloudDbContext db, CancellationToken token)
|
|
||||||
//{
|
|
||||||
// var query = db.TelemetryDataSpin
|
|
||||||
// .AsNoTracking()
|
|
||||||
// .Where(d => d.IdTelemetry == idTelemetry)
|
|
||||||
// .Select(d => new OperationTimeData
|
|
||||||
// {
|
|
||||||
// DateTime = d.DateTime,
|
|
||||||
// Mode = d.Mode
|
|
||||||
// // Depth = d.d
|
|
||||||
// })
|
|
||||||
// .OrderBy(d => d.DateTime);
|
|
||||||
|
|
||||||
// var take = 4 * 86_400; // 4 дня
|
private static async Task<IEnumerable<SubsystemOperationTime>> OperationTimeSpinAsync(int idTelemetry, DateTimeOffset begin, IAsbCloudDbContext db, CancellationToken token)
|
||||||
// var startDate = begin;
|
{
|
||||||
// var operationTime = new List<SubsystemOperationTime>();
|
var query = db.TelemetryDataSpin
|
||||||
// const int minOperationLength = 5;
|
.AsNoTracking()
|
||||||
// const int maxDetectorsInterpolationFrameLength = 30;
|
.Where(d => d.IdTelemetry == idTelemetry)
|
||||||
// const int gap = maxDetectorsInterpolationFrameLength + minOperationLength;
|
.Select(d => new OperationTimeData
|
||||||
|
{
|
||||||
|
DateTime = d.DateTime,
|
||||||
|
Mode = d.Mode,
|
||||||
|
Depth = db.TelemetryDataSaub.Where(t => t.DateTime == d.DateTime & t.IdTelemetry ==idTelemetry)
|
||||||
|
.GroupBy(t => t.IdTelemetry)
|
||||||
|
.Select(group => group.Min(t => t.WellDepth))
|
||||||
|
.FirstOrDefault()
|
||||||
|
})
|
||||||
|
.OrderBy(d => d.DateTime);
|
||||||
|
|
||||||
// while (true)
|
var take = 4 * 86_400; // 4 дня
|
||||||
// {
|
var startDate = begin;
|
||||||
// var data = await query
|
var firstItem = query.FirstOrDefault();
|
||||||
// .Where(d => d.DateTime > startDate)
|
if (firstItem is null)
|
||||||
// .Take(take)
|
return null;
|
||||||
// .ToArrayAsync(token);
|
short? mode = firstItem.Mode;
|
||||||
|
DateTimeOffset dateBegin = firstItem.DateTime;
|
||||||
|
float? depthStart = firstItem.Depth;
|
||||||
|
var resultSubsystemOperationTime = new List<SubsystemOperationTime>();
|
||||||
|
var data = await query
|
||||||
|
.Where(d => d.DateTime > startDate)
|
||||||
|
.Take(take)
|
||||||
|
.ToArrayAsync(token);
|
||||||
|
|
||||||
// if (data.Length < gap)
|
for (int i = 1; i <= data.Length; i++)
|
||||||
// break;
|
{
|
||||||
|
if (data[i].Mode != mode)
|
||||||
|
{
|
||||||
|
var operationTimeItem = new SubsystemOperationTime()
|
||||||
|
{
|
||||||
|
IdTelemetry = idTelemetry,
|
||||||
|
DateStart = dateBegin,
|
||||||
|
IdSubsystem = (int)data[i - 1].Mode,
|
||||||
|
DateEnd = data[i - 1].DateTime,
|
||||||
|
DepthStart = depthStart,
|
||||||
|
DepthEnd = data[i - 1].Depth
|
||||||
|
|
||||||
// short? modeCount = data[0].Mode;
|
};
|
||||||
// DateTimeOffset dateBegin = data[0].DateTime;
|
resultSubsystemOperationTime.Add(operationTimeItem);
|
||||||
// float? depthStart = data[0].Depth;
|
mode = data[i].Mode;
|
||||||
// for (int i = 1; i <= data.Length; i++)
|
dateBegin = data[i].DateTime;
|
||||||
// {
|
depthStart = data[i].Depth;
|
||||||
// if (data[i].Mode != modeCount)
|
}
|
||||||
// {
|
}
|
||||||
// var operationTimeItem = new SubsystemOperationTime()
|
startDate = data.Last().DateTime;
|
||||||
// {
|
|
||||||
// IdTelemetry = idTelemetry,
|
|
||||||
// DateStart = dateBegin,
|
|
||||||
// DateEnd = data[i - 1].DateTime,
|
|
||||||
// DepthStart = depthStart,
|
|
||||||
// DepthEnd = data[i - 1].Depth
|
|
||||||
|
|
||||||
// };
|
return resultSubsystemOperationTime;
|
||||||
// operationTime.Add(operationTimeItem);
|
}
|
||||||
// modeCount = data[i].Mode;
|
|
||||||
// dateBegin = data[i].DateTime;
|
|
||||||
// depthStart = data[i].Depth;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// var depths = db.TelemetryDataSaub.Where(t => true/*by date*/)
|
|
||||||
// .GroupBy(t => t.IdTelemetry)
|
|
||||||
// .Select(group => group.Min(t => t.WellDepth));
|
|
||||||
// return operationTime;
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public async Task<IEnumerable<SubsystemStatisticsDto>?> GetStatAsync(SubsystemOperationTimeRequest request, CancellationToken token)
|
public async Task<IEnumerable<SubsystemStatDto>?> GetStatAsync(SubsystemOperationTimeRequest request, CancellationToken token)
|
||||||
{
|
{
|
||||||
var data = await GetOperationTimeAsync(request, token);
|
var data = await GetOperationTimeAsync(request, token);
|
||||||
var statList = CalcStat(data, request);
|
var statList = CalcStat(data, request);
|
||||||
@ -116,9 +116,9 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
return itemsToTrim;
|
return itemsToTrim;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<SubsystemStatisticsDto> CalcStat(IEnumerable<SubsystemOperationTimeDto> groupedData, SubsystemOperationTimeRequest request)
|
private IEnumerable<SubsystemStatDto> CalcStat(IEnumerable<SubsystemOperationTimeDto> groupedData, SubsystemOperationTimeRequest request)
|
||||||
{
|
{
|
||||||
var result = new List<SubsystemStatisticsDto>();
|
var result = new List<SubsystemStatDto>();
|
||||||
var periodGroupTotal = groupedData
|
var periodGroupTotal = groupedData
|
||||||
.GroupBy(x => x.IdSubsystem)
|
.GroupBy(x => x.IdSubsystem)
|
||||||
.Sum(g => g.Sum(o=> (o.DateEnd - o.DateStart).TotalHours));
|
.Sum(g => g.Sum(o=> (o.DateEnd - o.DateStart).TotalHours));
|
||||||
@ -129,7 +129,7 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
var periodRequest = item.Where(o => o.DateStart==request.GtDate & o.DateEnd == request.LtDate)
|
var periodRequest = item.Where(o => o.DateStart==request.GtDate & o.DateEnd == request.LtDate)
|
||||||
.Sum(o => (o.DateEnd - o.DateStart).TotalHours);
|
.Sum(o => (o.DateEnd - o.DateStart).TotalHours);
|
||||||
int idSubsystem = item.First().IdSubsystem;
|
int idSubsystem = item.First().IdSubsystem;
|
||||||
var subsystemStat = new SubsystemStatisticsDto()
|
var subsystemStat = new SubsystemStatDto()
|
||||||
{
|
{
|
||||||
IdSubsystem = idSubsystem,
|
IdSubsystem = idSubsystem,
|
||||||
Subsystem = subsystemService.GetOrDefault(idSubsystem)?.Name ?? "unknown",
|
Subsystem = subsystemService.GetOrDefault(idSubsystem)?.Name ?? "unknown",
|
||||||
|
@ -11,37 +11,27 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace AsbCloudWebApi.Controllers.Subsystems
|
namespace AsbCloudWebApi.Controllers.Subsystems
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Наработка подсистем
|
/// Наработка подсистем
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Route("api/[controller]")]
|
[Route("api/[controller]")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Authorize]
|
[Authorize]
|
||||||
|
|
||||||
public class SubsystemOperationTimeController : ControllerBase
|
public class SubsystemOperationTimeController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly ISubsystemOperationTimeService subsystemOperationTimeService;
|
private readonly ISubsystemOperationTimeService subsystemOperationTimeService;
|
||||||
private readonly IWellService wellService;
|
public SubsystemOperationTimeController(ISubsystemOperationTimeService subsystemOperationTimeService)
|
||||||
|
|
||||||
public SubsystemOperationTimeController(ISubsystemOperationTimeService subsystemOperationTimeService, IWellService wellService)
|
|
||||||
{
|
{
|
||||||
this.subsystemOperationTimeService = subsystemOperationTimeService;
|
this.subsystemOperationTimeService = subsystemOperationTimeService;
|
||||||
this.wellService = wellService;
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// получить статистику
|
/// получить статистику
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HttpGet("stat")]
|
[HttpGet("stat")]
|
||||||
[ProducesResponseType(typeof(IEnumerable<SubsystemStatisticsDto>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(IEnumerable<SubsystemStatDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> GetStatisticsAsync(CancellationToken token = default)
|
public async Task<IActionResult> GetStatAsync([FromQuery] SubsystemOperationTimeRequest request, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
var subsystemResult = new List<SubsystemStatisticsDto>()
|
var subsystemResult = await subsystemOperationTimeService.GetStatAsync(request, token);
|
||||||
{
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
return Ok(subsystemResult);
|
return Ok(subsystemResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,8 +42,14 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
|||||||
[ProducesResponseType(typeof(IEnumerable<SubsystemDto>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(IEnumerable<SubsystemDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> GetSubsystemAsync([FromQuery] int idWell, CancellationToken token = default)
|
public async Task<IActionResult> GetSubsystemAsync([FromQuery] int idWell, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
|
if (idWell != null)
|
||||||
|
{
|
||||||
|
var resultIdWell = await subsystemOperationTimeService.GetSubsystemAsync(idWell, token);
|
||||||
|
return Ok(resultIdWell);
|
||||||
|
}
|
||||||
var result = await subsystemOperationTimeService.GetSubsystemAsync(idWell, token);
|
var result = await subsystemOperationTimeService.GetSubsystemAsync(idWell, token);
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -65,7 +61,6 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
|||||||
[FromQuery] SubsystemOperationTimeRequest request,
|
[FromQuery] SubsystemOperationTimeRequest request,
|
||||||
CancellationToken token = default)
|
CancellationToken token = default)
|
||||||
{
|
{
|
||||||
|
|
||||||
var result = await subsystemOperationTimeService.GetOperationTimeAsync(request, token);
|
var result = await subsystemOperationTimeService.GetOperationTimeAsync(request, token);
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user