forked from ddrilling/AsbCloudServer
CS2-107: Added calculation of max and average Rop for cluster wells
This commit is contained in:
parent
07f76afa35
commit
d361c9a9b4
@ -11,6 +11,8 @@ namespace AsbCloudApp.Data
|
|||||||
public string WellType { get; set; }
|
public string WellType { get; set; }
|
||||||
public int IdWellType { get; set; }
|
public int IdWellType { get; set; }
|
||||||
|
|
||||||
|
public int? IdCluster { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 0 - незвестно,
|
/// 0 - незвестно,
|
||||||
/// 1 - в работе,
|
/// 1 - в работе,
|
||||||
|
@ -18,5 +18,6 @@ namespace AsbCloudApp.Services
|
|||||||
bool IsCompanyInvolvedInWell(int idCompany, int idWell);
|
bool IsCompanyInvolvedInWell(int idCompany, int idWell);
|
||||||
string GetStateText(int state);
|
string GetStateText(int state);
|
||||||
DateTime GetLastTelemetryDate(int idWell);
|
DateTime GetLastTelemetryDate(int idWell);
|
||||||
|
Task<IEnumerable<int>> GetClusterWellsIdsAsync(int idWell, CancellationToken token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ namespace AsbCloudInfrastructure
|
|||||||
services.AddTransient<ITelemetryAnalyticsService, TelemetryAnalyticsService>();
|
services.AddTransient<ITelemetryAnalyticsService, TelemetryAnalyticsService>();
|
||||||
services.AddTransient<IFileService, FileService>();
|
services.AddTransient<IFileService, FileService>();
|
||||||
services.AddTransient<IWellOperationService, WellOperationService>();
|
services.AddTransient<IWellOperationService, WellOperationService>();
|
||||||
services.AddTransient<IWellOperationsStatService, WellOperationsStatService>();
|
services.AddTransient<IOperationsStatService, OperationsStatService>();
|
||||||
services.AddTransient<IWellOperationImportService, WellOperationImportService>();
|
services.AddTransient<IWellOperationImportService, WellOperationImportService>();
|
||||||
services.AddTransient<IWellCompositeService, WellCompositeService>();
|
services.AddTransient<IWellCompositeService, WellCompositeService>();
|
||||||
services.AddTransient<IMeasureService, MeasureService>();
|
services.AddTransient<IMeasureService, MeasureService>();
|
||||||
|
@ -12,10 +12,11 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace AsbCloudInfrastructure.Services.WellOperationService
|
namespace AsbCloudInfrastructure.Services.WellOperationService
|
||||||
{
|
{
|
||||||
public class WellOperationsStatService : IWellOperationsStatService
|
public class OperationsStatService : IOperationsStatService
|
||||||
{
|
{
|
||||||
private readonly IAsbCloudDbContext db;
|
private readonly IAsbCloudDbContext db;
|
||||||
private readonly IWellService wellService;
|
private readonly IWellService wellService;
|
||||||
|
private readonly ITelemetryService telemetryService;
|
||||||
private readonly CacheTable<WellSectionType> cacheSectionsTypes;
|
private readonly CacheTable<WellSectionType> cacheSectionsTypes;
|
||||||
private readonly CacheTable<WellType> cacheWellType;
|
private readonly CacheTable<WellType> cacheWellType;
|
||||||
private readonly CacheTable<Cluster> cacheCluster;
|
private readonly CacheTable<Cluster> cacheCluster;
|
||||||
@ -29,15 +30,34 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
|
|||||||
private const int idOperationTypePlan = 0;
|
private const int idOperationTypePlan = 0;
|
||||||
private const int idOperationTypeFact = 1;
|
private const int idOperationTypeFact = 1;
|
||||||
|
|
||||||
public WellOperationsStatService(IAsbCloudDbContext db, CacheDb cache, IWellService wellService)
|
public OperationsStatService(IAsbCloudDbContext db, CacheDb cache, IWellService wellService,
|
||||||
|
ITelemetryService telemetryService)
|
||||||
{
|
{
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.wellService = wellService;
|
this.wellService = wellService;
|
||||||
|
this.telemetryService = telemetryService;
|
||||||
cacheSectionsTypes = cache.GetCachedTable<WellSectionType>((DbContext)db);
|
cacheSectionsTypes = cache.GetCachedTable<WellSectionType>((DbContext)db);
|
||||||
cacheWellType = cache.GetCachedTable<WellType>((DbContext)db);
|
cacheWellType = cache.GetCachedTable<WellType>((DbContext)db);
|
||||||
cacheCluster = cache.GetCachedTable<Cluster>((DbContext)db);
|
cacheCluster = cache.GetCachedTable<Cluster>((DbContext)db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<ClusterRopStatDto> GetRopStatByIdWellAsync(int idWell,
|
||||||
|
CancellationToken token)
|
||||||
|
{
|
||||||
|
return await GetRopStatAsync(idWell, token).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<ClusterRopStatDto> GetRopStatByUidAsync(string uid,
|
||||||
|
CancellationToken token)
|
||||||
|
{
|
||||||
|
var idWell = telemetryService.GetidWellByTelemetryUid(uid);
|
||||||
|
|
||||||
|
if (idWell is null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return await GetRopStatAsync((int)idWell, token).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<StatClusterDto> GetStatClusterAsync(int idCluster, int idCompany, CancellationToken token = default)
|
public async Task<StatClusterDto> GetStatClusterAsync(int idCluster, int idCompany, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
var allWellsByCompany = await wellService.GetWellsByCompanyAsync(idCompany, token).ConfigureAwait(false);
|
var allWellsByCompany = await wellService.GetWellsByCompanyAsync(idCompany, token).ConfigureAwait(false);
|
||||||
@ -93,6 +113,49 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
|
|||||||
return statWellDto;
|
return statWellDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task<ClusterRopStatDto> GetRopStatAsync(int idWell, CancellationToken token)
|
||||||
|
{
|
||||||
|
var clusterWellsIds = await wellService.GetClusterWellsIdsAsync(idWell, token)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (clusterWellsIds is null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var idLastSectionType = await (from o in db.WellOperations
|
||||||
|
where o.IdWell == idWell &&
|
||||||
|
o.IdType == 1
|
||||||
|
orderby o.DepthStart
|
||||||
|
select o.IdWellSectionType)
|
||||||
|
.LastOrDefaultAsync(token)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
|
var operations = await (from o in db.WellOperations
|
||||||
|
where clusterWellsIds.Contains(o.IdWell) &&
|
||||||
|
o.IdType == 1 &&
|
||||||
|
o.IdWellSectionType == idLastSectionType
|
||||||
|
select o)
|
||||||
|
.ToListAsync(token)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
|
var statsList = clusterWellsIds.Select(clusterWellId =>
|
||||||
|
{
|
||||||
|
var currentWellOps = operations.Where(o => o.IdWell == clusterWellId);
|
||||||
|
var stat = CalcStat(currentWellOps);
|
||||||
|
return stat;
|
||||||
|
}).Where(c => c is not null);
|
||||||
|
|
||||||
|
if (!statsList.Any())
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var clusterRops = new ClusterRopStatDto()
|
||||||
|
{
|
||||||
|
RopMax = statsList.Max(s => s.Rop),
|
||||||
|
RopAverage = statsList.Average(s => s.Rop)
|
||||||
|
};
|
||||||
|
|
||||||
|
return clusterRops;
|
||||||
|
}
|
||||||
|
|
||||||
private async Task<StatWellDto> CalcStatWellAsync(Well well, CancellationToken token = default)
|
private async Task<StatWellDto> CalcStatWellAsync(Well well, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
var wellType = await cacheWellType.FirstOrDefaultAsync(t => t.Id == well.IdWellType, token);
|
var wellType = await cacheWellType.FirstOrDefaultAsync(t => t.Id == well.IdWellType, token);
|
@ -138,12 +138,28 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<int>> GetClusterWellsIdsAsync(int idWell, CancellationToken token)
|
||||||
|
{
|
||||||
|
var well = await cacheWells.FirstOrDefaultAsync(w => w.Id == idWell)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (well is null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var clusterWells = await cacheWells.WhereAsync(w => w.IdCluster == well.IdCluster)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
|
return clusterWells.Select(w => w.Id);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private WellDto Convert(Well well)
|
private WellDto Convert(Well well)
|
||||||
{
|
{
|
||||||
return new WellDto
|
return new WellDto
|
||||||
{
|
{
|
||||||
Id = well.Id,
|
Id = well.Id,
|
||||||
Caption = well.Caption,
|
Caption = well.Caption,
|
||||||
|
IdCluster = well.IdCluster,
|
||||||
Cluster = well.Cluster.Caption,
|
Cluster = well.Cluster.Caption,
|
||||||
Deposit = well.Cluster.Deposit.Caption,
|
Deposit = well.Cluster.Deposit.Caption,
|
||||||
LastTelemetryDate = GetLastTelemetryDate(well.Id),
|
LastTelemetryDate = GetLastTelemetryDate(well.Id),
|
||||||
|
@ -1,67 +0,0 @@
|
|||||||
using AsbCloudApp.Data;
|
|
||||||
using AsbCloudApp.Services;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AsbCloudWebApi.Controllers
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Контроллер статистики вручную внесенных операций на кусту
|
|
||||||
/// </summary>
|
|
||||||
[Route("api/cluster")]
|
|
||||||
[ApiController]
|
|
||||||
[Authorize]
|
|
||||||
public class ClusterOperationStatController : ControllerBase
|
|
||||||
{
|
|
||||||
private readonly IWellOperationService operationService;
|
|
||||||
private readonly IWellService wellService;
|
|
||||||
private readonly IWellOperationImportService wellOperationImportService;
|
|
||||||
|
|
||||||
public ClusterOperationStatController(IWellOperationService operationService,
|
|
||||||
IWellService wellService, IWellOperationImportService wellOperationImportService)
|
|
||||||
{
|
|
||||||
this.operationService = operationService;
|
|
||||||
this.wellService = wellService;
|
|
||||||
this.wellOperationImportService = wellOperationImportService;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Формирует данные по среднему и максимальному МСП на кусту
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="idWell">id скважины с данного куста (через нее будут полуены данные)</param>
|
|
||||||
/// <param name="token"></param>
|
|
||||||
/// <returns>Возвращает данные по среднему и максимальному МСП на кусту</returns>
|
|
||||||
[HttpGet("{idWell}/ropStat")]
|
|
||||||
[ProducesResponseType(typeof(ClusterRopStatDto), (int)System.Net.HttpStatusCode.OK)]
|
|
||||||
public async Task<IActionResult> GetClusterRopStatAsync([FromRoute] int idWell,
|
|
||||||
CancellationToken token = default)
|
|
||||||
{
|
|
||||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
||||||
return Forbid();
|
|
||||||
|
|
||||||
// var result = await operationService.GetOperationsAsync(
|
|
||||||
// idWell, token).ConfigureAwait(false);
|
|
||||||
|
|
||||||
var result = new ClusterRopStatDto()
|
|
||||||
{
|
|
||||||
RopMax = 3.2,
|
|
||||||
RopAverage = 1.1
|
|
||||||
};
|
|
||||||
|
|
||||||
return Ok(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task<bool> CanUserAccessToWellAsync(int idWell, CancellationToken token = default)
|
|
||||||
{
|
|
||||||
int? idCompany = User.GetCompanyId();
|
|
||||||
return idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
||||||
idWell, token).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -10,22 +10,62 @@ using System.Threading.Tasks;
|
|||||||
namespace AsbCloudWebApi.Controllers
|
namespace AsbCloudWebApi.Controllers
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Контроллер секций скважины
|
/// Контроллер статистики по операциям на скважине
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Authorize]
|
[Authorize]
|
||||||
[Route("api")]
|
[Route("api")]
|
||||||
public class WellOperationStatController : ControllerBase
|
public class OperationStatController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly IWellOperationsStatService operationsStatService;
|
private readonly IOperationsStatService operationsStatService;
|
||||||
private readonly IWellService wellService;
|
private readonly IWellService wellService;
|
||||||
|
|
||||||
public WellOperationStatController(IWellOperationsStatService sectionsService, IWellService wellService)
|
public OperationStatController(IOperationsStatService sectionsService, IWellService wellService)
|
||||||
{
|
{
|
||||||
this.operationsStatService = sectionsService;
|
this.operationsStatService = sectionsService;
|
||||||
this.wellService = wellService;
|
this.wellService = wellService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Формирует данные по среднему и максимальному МСП на кусту по id скважины
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idWell">id скважины с данного куста (через нее будут полуены данные)</param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns>Возвращает данные по среднему и максимальному МСП на кусту</returns>
|
||||||
|
[HttpGet("cluster/{idWell}/idWellRopStat")]
|
||||||
|
[ProducesResponseType(typeof(ClusterRopStatDto), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
public async Task<IActionResult> GetClusterRopStatByIdWellAsync([FromRoute] int idWell,
|
||||||
|
CancellationToken token = default)
|
||||||
|
{
|
||||||
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||||
|
return Forbid();
|
||||||
|
|
||||||
|
var result = await operationsStatService.GetRopStatByIdWellAsync(
|
||||||
|
idWell, token).ConfigureAwait(false);
|
||||||
|
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Формирует данные по среднему и максимальному МСП на кусту по uid панели
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="uid">id передающей данные панели</param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns>Возвращает данные по среднему и максимальному МСП на кусту</returns>
|
||||||
|
[HttpGet("cluster/{uid}/uidRopStat")]
|
||||||
|
[ProducesResponseType(typeof(ClusterRopStatDto), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
public async Task<IActionResult> GetClusterRopStatByUidAsync([FromRoute] string uid,
|
||||||
|
CancellationToken token = default)
|
||||||
|
{
|
||||||
|
// if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||||
|
// return Forbid();
|
||||||
|
|
||||||
|
var result = await operationsStatService.GetRopStatByUidAsync(
|
||||||
|
uid, token).ConfigureAwait(false);
|
||||||
|
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получает статстику по скважинам куста
|
/// Получает статстику по скважинам куста
|
||||||
/// </summary>
|
/// </summary>
|
Loading…
Reference in New Issue
Block a user