forked from ddrilling/AsbCloudServer
-добавлена модель статистики по активным скважинам
- метод расчета статистики -шаблон метода в контроллере
This commit is contained in:
parent
0bab711eb8
commit
3aa01ebe47
20
AsbCloudApp/Data/Subsystems/SubsystemActiveWellStatDto.cs
Normal file
20
AsbCloudApp/Data/Subsystems/SubsystemActiveWellStatDto.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AsbCloudApp.Data.Subsystems
|
||||
{
|
||||
/// <summary>
|
||||
/// Статистика наработки подсистем по активным скважинам
|
||||
/// </summary>
|
||||
public class SubsystemActiveWellStatDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Идентификатор скважины
|
||||
/// </summary>
|
||||
public int IdWell { get; set; }
|
||||
/// <summary>
|
||||
/// Наработки подсистем
|
||||
/// </summary>
|
||||
public IEnumerable<SubsystemStatDto> listSubsystemStat { get; set; }
|
||||
|
||||
}
|
||||
}
|
@ -101,7 +101,7 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
||||
return null;
|
||||
var depthInterval = GetDepthInterval(detectedOperations);
|
||||
|
||||
var statList = CalcStat(data,depthInterval,request, token);
|
||||
var statList = CalcStat(data,depthInterval);
|
||||
return statList;
|
||||
}
|
||||
|
||||
@ -125,7 +125,7 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
||||
return items;
|
||||
}
|
||||
|
||||
private IEnumerable<SubsystemStatDto> CalcStat(IEnumerable<SubsystemOperationTimeDto> dtos, (double depthIntervalRotor, double depthIntervalSlide) depthInterval, SubsystemOperationTimeRequest request, CancellationToken token)
|
||||
private IEnumerable<SubsystemStatDto> CalcStat(IEnumerable<SubsystemOperationTimeDto> dtos, (double depthIntervalRotor, double depthIntervalSlide) depthInterval)
|
||||
{
|
||||
var groupedDataSubsystems = dtos
|
||||
.GroupBy(o => o.IdSubsystem);
|
||||
@ -153,8 +153,7 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
||||
return result;
|
||||
}
|
||||
private (double depthIntervalRotor, double depthIntervalSlide) GetDepthInterval (IEnumerable<DetectedOperationDto> detectedOperations)
|
||||
{
|
||||
|
||||
{
|
||||
var depthIntervalRotor = detectedOperations.Where(o => o.IdCategory == 1)
|
||||
.Sum(o => o.DepthEnd - o.DepthStart);
|
||||
var depthIntervalSlide = detectedOperations.Where(o => o.IdCategory == 3)
|
||||
@ -185,6 +184,76 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private async Task<IEnumerable<WellDto>> GetSubsystemOperationTimeAll(int idCompany, CancellationToken token)
|
||||
{
|
||||
var listWell = await wellService.GetWellsByCompanyAsync(idCompany, token);
|
||||
var active = listWell.Where(w => w.IdState == 1);
|
||||
return active;
|
||||
}
|
||||
|
||||
|
||||
public async Task<IEnumerable<SubsystemActiveWellStatDto>?> GetStatByActiveWell(int idCompany, DateTime? gtDate, DateTime? ltDate, CancellationToken token)
|
||||
{
|
||||
var activeWell = await GetSubsystemOperationTimeAll(idCompany, token);
|
||||
var telemetryIds = activeWell.Select(w => w.IdTelemetry);
|
||||
var query = db.SubsystemOperationTimes
|
||||
.Include(o => o.Subsystem)
|
||||
.Where(o => telemetryIds.Contains(o.IdTelemetry))
|
||||
.AsNoTracking();
|
||||
|
||||
if (query is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
DateTime today = DateTime.Today;
|
||||
if (gtDate.HasValue)
|
||||
{
|
||||
query = query.Where(o => o.DateEnd >= gtDate);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtDate = today;
|
||||
query = query.Where(o => o.DateEnd == gtDate);
|
||||
}
|
||||
|
||||
if (ltDate.HasValue)
|
||||
{
|
||||
query = query.Where(o => o.DateStart <= ltDate);
|
||||
}
|
||||
else
|
||||
{
|
||||
ltDate = today.AddDays(-1);
|
||||
query = query.Where(o => o.DateStart == ltDate );
|
||||
}
|
||||
var detectedOperationsRequest = new DetectedOperationRequest()
|
||||
{
|
||||
IdsCategories = new List<int>() {
|
||||
1,3
|
||||
},
|
||||
LtDate = ltDate,
|
||||
GtDate = gtDate,
|
||||
};
|
||||
var detectedOperations = await detectedOperationService.GetOperationsAsync(detectedOperationsRequest, token);
|
||||
var groupData = query.GroupBy(g => g.IdTelemetry);
|
||||
var result = new List<SubsystemActiveWellStatDto>();
|
||||
foreach (var group in groupData)
|
||||
{
|
||||
var wellStat = new SubsystemActiveWellStatDto();
|
||||
wellStat.IdWell = activeWell.Where(w => w.IdTelemetry == group.Key).Select(w => w.Id).FirstOrDefault();
|
||||
var groupSubsystem = (IEnumerable<IGrouping<int, SubsystemOperationTimeDto>>)group.GroupBy(g => g.IdSubsystem);
|
||||
var detectedOperationsById = detectedOperations.Where(d => d.IdWell == wellStat.IdWell).ToList();
|
||||
var depthInterval = GetDepthInterval(detectedOperationsById);
|
||||
wellStat.listSubsystemStat = CalcStat((IEnumerable<SubsystemOperationTimeDto>)groupSubsystem, depthInterval);
|
||||
result.Add(wellStat);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<DatesRangeDto?> GetDateRangeOperationTimeAsync(SubsystemOperationTimeRequest request, CancellationToken token)
|
||||
{
|
||||
|
@ -46,6 +46,18 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
||||
return Ok(subsystemResult);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// получить статистику по активным скважинам
|
||||
/// </summary>
|
||||
[HttpGet("statByActiveWell")]
|
||||
[ProducesResponseType(typeof(IEnumerable<SubsystemStatDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> GetStatByWellAsync([FromQuery] DateTime? GtDate, DateTime? LtDate, CancellationToken token = default)
|
||||
{
|
||||
|
||||
var subsystemResult = await subsystemOperationTimeService.GetStatAsync(request, token);
|
||||
return Ok(subsystemResult);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// получить список подсистем общий.
|
||||
/// </summary>
|
||||
|
Loading…
Reference in New Issue
Block a user