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
@ -10,6 +10,8 @@ namespace AsbCloudApp.Data
|
||||
public double? Longitude { get; set; }
|
||||
public string WellType { get; set; }
|
||||
public int IdWellType { get; set; }
|
||||
|
||||
public int? IdCluster { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 0 - незвестно,
|
||||
|
@ -18,5 +18,6 @@ namespace AsbCloudApp.Services
|
||||
bool IsCompanyInvolvedInWell(int idCompany, int idWell);
|
||||
string GetStateText(int state);
|
||||
DateTime GetLastTelemetryDate(int idWell);
|
||||
Task<IEnumerable<int>> GetClusterWellsIdsAsync(int idWell, CancellationToken token);
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ namespace AsbCloudInfrastructure
|
||||
services.AddTransient<ITelemetryAnalyticsService, TelemetryAnalyticsService>();
|
||||
services.AddTransient<IFileService, FileService>();
|
||||
services.AddTransient<IWellOperationService, WellOperationService>();
|
||||
services.AddTransient<IWellOperationsStatService, WellOperationsStatService>();
|
||||
services.AddTransient<IOperationsStatService, OperationsStatService>();
|
||||
services.AddTransient<IWellOperationImportService, WellOperationImportService>();
|
||||
services.AddTransient<IWellCompositeService, WellCompositeService>();
|
||||
services.AddTransient<IMeasureService, MeasureService>();
|
||||
|
@ -12,10 +12,11 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services.WellOperationService
|
||||
{
|
||||
public class WellOperationsStatService : IWellOperationsStatService
|
||||
public class OperationsStatService : IOperationsStatService
|
||||
{
|
||||
private readonly IAsbCloudDbContext db;
|
||||
private readonly IWellService wellService;
|
||||
private readonly ITelemetryService telemetryService;
|
||||
private readonly CacheTable<WellSectionType> cacheSectionsTypes;
|
||||
private readonly CacheTable<WellType> cacheWellType;
|
||||
private readonly CacheTable<Cluster> cacheCluster;
|
||||
@ -29,14 +30,33 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
|
||||
private const int idOperationTypePlan = 0;
|
||||
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.wellService = wellService;
|
||||
this.telemetryService = telemetryService;
|
||||
cacheSectionsTypes = cache.GetCachedTable<WellSectionType>((DbContext)db);
|
||||
cacheWellType = cache.GetCachedTable<WellType>((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)
|
||||
{
|
||||
@ -93,6 +113,49 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
return new WellDto
|
||||
{
|
||||
Id = well.Id,
|
||||
Caption = well.Caption,
|
||||
IdCluster = well.IdCluster,
|
||||
Cluster = well.Cluster.Caption,
|
||||
Deposit = well.Cluster.Deposit.Caption,
|
||||
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,21 +10,61 @@ using System.Threading.Tasks;
|
||||
namespace AsbCloudWebApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Контроллер секций скважины
|
||||
/// Контроллер статистики по операциям на скважине
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Route("api")]
|
||||
public class WellOperationStatController : ControllerBase
|
||||
public class OperationStatController : ControllerBase
|
||||
{
|
||||
private readonly IWellOperationsStatService operationsStatService;
|
||||
private readonly IOperationsStatService operationsStatService;
|
||||
private readonly IWellService wellService;
|
||||
|
||||
public WellOperationStatController(IWellOperationsStatService sectionsService, IWellService wellService)
|
||||
public OperationStatController(IOperationsStatService sectionsService, IWellService wellService)
|
||||
{
|
||||
this.operationsStatService = sectionsService;
|
||||
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>
|
||||
/// Получает статстику по скважинам куста
|
Loading…
Reference in New Issue
Block a user