forked from ddrilling/AsbCloudServer
дополнен фоновый сервис наработок
доработан контроллер наработок подсистем переименованы модели ДТО
This commit is contained in:
parent
9f23a45be7
commit
2c4d6a9a53
@ -9,7 +9,7 @@ namespace AsbCloudApp.Data.Subsystems
|
||||
/// <summary>
|
||||
/// Статистика подсистемы
|
||||
/// </summary>
|
||||
public class SubsystemStatisticsDto
|
||||
public class SubsystemStatDto
|
||||
{
|
||||
|
||||
/// <summary>
|
@ -12,7 +12,7 @@ namespace AsbCloudApp.Services.Subsystems
|
||||
public interface ISubsystemOperationTimeService
|
||||
{
|
||||
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<IEnumerable<SubsystemOperationTimeDto>> GetOperationTimeAsync(SubsystemOperationTimeRequest request, CancellationToken token);
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using AsbCloudApp.Data.Subsystems;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudApp.Services.Subsystems;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudDb.Model.Subsystems;
|
||||
using AsbCloudInfrastructure.Repository;
|
||||
@ -87,7 +88,7 @@ namespace AsbCloudInfrastructure
|
||||
services.AddScoped<IEmailService, EmailService>();
|
||||
|
||||
services.AddHostedService<OperationDetectionBackgroundService>();
|
||||
//services.AddHostedService<SubsystemOperationTimeBackgroundService>();
|
||||
services.AddHostedService<SubsystemOperationTimeBackgroundService>();
|
||||
services.AddSingleton(new WitsInfoService());
|
||||
services.AddSingleton(new CacheDb());
|
||||
services.AddSingleton(new InstantDataRepository());
|
||||
@ -118,10 +119,11 @@ namespace AsbCloudInfrastructure
|
||||
services.AddTransient<IWellOperationService, WellOperationService>();
|
||||
services.AddTransient<IScheduleReportService, ScheduleReportService>();
|
||||
services.AddTransient<IDailyReportService, DailyReportService>();
|
||||
services.AddTransient<IDetectedOperationService, DetectedOperationService>();
|
||||
services.AddTransient<IDetectedOperationService, DetectedOperationService>();
|
||||
services.AddTransient<IDrillerService, DrillerService>();
|
||||
services.AddTransient<IScheduleService, ScheduleService>();
|
||||
services.AddTransient<IOperationValueService, OperationValueService>();
|
||||
//services.AddTransient<ISubsystemOperationTimeService, SubsystemOperationTimeService>();
|
||||
|
||||
// admin crud services:
|
||||
services.AddTransient<ICrudService<TelemetryDto>, CrudServiceBase<TelemetryDto, Telemetry>>(s =>
|
||||
|
@ -87,11 +87,17 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
||||
foreach (var item in JounedlastDetectedDates)
|
||||
{
|
||||
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();
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -109,19 +115,18 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
||||
Mode = d.Mode,
|
||||
Depth = d.WellDepth
|
||||
})
|
||||
.OrderBy(d => d.DateTime);
|
||||
.OrderBy(d => d.DateTime);
|
||||
|
||||
var take = 4 * 86_400; // 4 дня
|
||||
var startDate = begin;
|
||||
var resultSubsystemOperationTime = new List<SubsystemOperationTime>();
|
||||
var startDate = begin;
|
||||
var firstItem = query.FirstOrDefault();
|
||||
if (firstItem is null)
|
||||
return null;
|
||||
short? mode = firstItem.Mode;
|
||||
DateTimeOffset dateBegin = firstItem.DateTime;
|
||||
float? depthStart = firstItem.Depth;
|
||||
while (true)
|
||||
{
|
||||
var resultSubsystemOperationTime = new List<SubsystemOperationTime>();
|
||||
|
||||
var data = await query
|
||||
.Where(d => d.DateTime > startDate)
|
||||
.Take(take)
|
||||
@ -134,6 +139,7 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
||||
{
|
||||
IdTelemetry = idTelemetry,
|
||||
DateStart = dateBegin,
|
||||
IdSubsystem = (int)data[i - 1].Mode,
|
||||
DateEnd = data[i - 1].DateTime,
|
||||
DepthStart = depthStart,
|
||||
DepthEnd = data[i - 1].Depth
|
||||
@ -146,67 +152,64 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
||||
}
|
||||
}
|
||||
startDate = data.Last().DateTime;
|
||||
}
|
||||
|
||||
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 дня
|
||||
// var startDate = begin;
|
||||
// var operationTime = new List<SubsystemOperationTime>();
|
||||
// const int minOperationLength = 5;
|
||||
// const int maxDetectorsInterpolationFrameLength = 30;
|
||||
// const int gap = maxDetectorsInterpolationFrameLength + minOperationLength;
|
||||
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 = 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 data = await query
|
||||
// .Where(d => d.DateTime > startDate)
|
||||
// .Take(take)
|
||||
// .ToArrayAsync(token);
|
||||
var take = 4 * 86_400; // 4 дня
|
||||
var startDate = begin;
|
||||
var firstItem = query.FirstOrDefault();
|
||||
if (firstItem is null)
|
||||
return null;
|
||||
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);
|
||||
|
||||
for (int i = 1; i <= data.Length; i++)
|
||||
{
|
||||
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
|
||||
|
||||
// if (data.Length < gap)
|
||||
// break;
|
||||
};
|
||||
resultSubsystemOperationTime.Add(operationTimeItem);
|
||||
mode = data[i].Mode;
|
||||
dateBegin = data[i].DateTime;
|
||||
depthStart = data[i].Depth;
|
||||
}
|
||||
}
|
||||
startDate = data.Last().DateTime;
|
||||
|
||||
// short? modeCount = data[0].Mode;
|
||||
// DateTimeOffset dateBegin = data[0].DateTime;
|
||||
// float? depthStart = data[0].Depth;
|
||||
// for (int i = 1; i <= data.Length; i++)
|
||||
// {
|
||||
// if (data[i].Mode != modeCount)
|
||||
// {
|
||||
// var operationTimeItem = new SubsystemOperationTime()
|
||||
// {
|
||||
// IdTelemetry = idTelemetry,
|
||||
// DateStart = dateBegin,
|
||||
// DateEnd = data[i - 1].DateTime,
|
||||
// DepthStart = depthStart,
|
||||
// DepthEnd = data[i - 1].Depth
|
||||
|
||||
// };
|
||||
// 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;
|
||||
//}
|
||||
return resultSubsystemOperationTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 statList = CalcStat(data, request);
|
||||
@ -116,9 +116,9 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
||||
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
|
||||
.GroupBy(x => x.IdSubsystem)
|
||||
.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)
|
||||
.Sum(o => (o.DateEnd - o.DateStart).TotalHours);
|
||||
int idSubsystem = item.First().IdSubsystem;
|
||||
var subsystemStat = new SubsystemStatisticsDto()
|
||||
var subsystemStat = new SubsystemStatDto()
|
||||
{
|
||||
IdSubsystem = idSubsystem,
|
||||
Subsystem = subsystemService.GetOrDefault(idSubsystem)?.Name ?? "unknown",
|
||||
|
@ -10,38 +10,28 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudWebApi.Controllers.Subsystems
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
/// <summary>
|
||||
/// Наработка подсистем
|
||||
/// </summary>
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
|
||||
public class SubsystemOperationTimeController : ControllerBase
|
||||
{
|
||||
private readonly ISubsystemOperationTimeService subsystemOperationTimeService;
|
||||
private readonly IWellService wellService;
|
||||
|
||||
public SubsystemOperationTimeController(ISubsystemOperationTimeService subsystemOperationTimeService, IWellService wellService)
|
||||
public SubsystemOperationTimeController(ISubsystemOperationTimeService subsystemOperationTimeService)
|
||||
{
|
||||
this.subsystemOperationTimeService = subsystemOperationTimeService;
|
||||
this.wellService = wellService;
|
||||
this.subsystemOperationTimeService = subsystemOperationTimeService;
|
||||
}
|
||||
/// <summary>
|
||||
/// получить статистику
|
||||
/// </summary>
|
||||
[HttpGet("stat")]
|
||||
[ProducesResponseType(typeof(IEnumerable<SubsystemStatisticsDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> GetStatisticsAsync(CancellationToken token = default)
|
||||
[ProducesResponseType(typeof(IEnumerable<SubsystemStatDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
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);
|
||||
}
|
||||
|
||||
@ -52,8 +42,14 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
||||
[ProducesResponseType(typeof(IEnumerable<SubsystemDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
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);
|
||||
return Ok(result);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -64,8 +60,7 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
||||
public async Task<IActionResult> GetOperationTimeAsync(
|
||||
[FromQuery] SubsystemOperationTimeRequest request,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
|
||||
{
|
||||
var result = await subsystemOperationTimeService.GetOperationTimeAsync(request, token);
|
||||
return Ok(result);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user