forked from ddrilling/AsbCloudServer
Добавление показателя в операцию. Изменение структуры ответа
This commit is contained in:
parent
e5c1880225
commit
9764809c3a
@ -67,5 +67,7 @@ namespace AsbCloudApp.Data
|
||||
/// Целевые/нормативные показатели
|
||||
/// </summary>
|
||||
public OperationValueDto OperationValue { get; set; }
|
||||
|
||||
public double Value { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -4,40 +4,49 @@ using System.Linq;
|
||||
|
||||
namespace AsbCloudApp.Data
|
||||
{
|
||||
public class DetectedOperationStatDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Бурильцик
|
||||
/// </summary>
|
||||
public DrillerDto Driller { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Количество операции
|
||||
/// </summary>
|
||||
public int Count { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Среднее по целевым показателям
|
||||
/// </summary>
|
||||
public double Average { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Коэффициент эффективности
|
||||
/// </summary>
|
||||
public double Efficiency { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Среднее по ключевому показателю
|
||||
/// </summary>
|
||||
public double AverageByParam { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Коэффициент потерь
|
||||
/// </summary>
|
||||
public double Loss { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Автоматически определяемая операция
|
||||
/// </summary>
|
||||
public class DetectedOperationListDto
|
||||
{
|
||||
public IEnumerable<IGrouping<int, DetectedOperationDto>> test { get; set; }
|
||||
/// <summary>
|
||||
/// Список всех операций
|
||||
/// </summary>
|
||||
public IEnumerable<DetectedOperationDto> List { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Количество по
|
||||
/// </summary>
|
||||
public IDictionary<int,int> Count { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Среднее целевое
|
||||
/// </summary>
|
||||
public IDictionary<int,double> Average { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Коэффициент эффективности
|
||||
/// </summary>
|
||||
public IDictionary<int,double> Efficiency { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Среднее по ключевому показателю
|
||||
/// </summary>
|
||||
public IDictionary<int,double> AverageByParam { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Коэффициент потерь
|
||||
/// </summary>
|
||||
public IDictionary<int,double> Loss { get; set; }
|
||||
public ICollection<DetectedOperationStatDto> Stats { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -42,21 +42,5 @@ namespace AsbCloudApp.Data
|
||||
/// </summary>
|
||||
public double DepthEnd { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Определение применяемого предикат по типц операции
|
||||
/// </summary>
|
||||
/// <returns>Предикат для использования</returns>
|
||||
public Predicate<double> PredicateTarget
|
||||
{
|
||||
get {
|
||||
return IdOperationCategory switch
|
||||
{
|
||||
1 => (x) => false,
|
||||
11 => (x) => x > TargetValue,
|
||||
_ => (x) => true
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
6054
AsbCloudDb/Migrations/20220610113921_AddValToOp.Designer.cs
generated
Normal file
6054
AsbCloudDb/Migrations/20220610113921_AddValToOp.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
27
AsbCloudDb/Migrations/20220610113921_AddValToOp.cs
Normal file
27
AsbCloudDb/Migrations/20220610113921_AddValToOp.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace AsbCloudDb.Migrations
|
||||
{
|
||||
public partial class AddValToOp : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<double>(
|
||||
name: "value",
|
||||
table: "t_detected_operation",
|
||||
type: "double precision",
|
||||
nullable: false,
|
||||
defaultValue: 0.0,
|
||||
comment: "Ключевой показатель операции");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "value",
|
||||
table: "t_detected_operation");
|
||||
}
|
||||
}
|
||||
}
|
@ -239,6 +239,11 @@ namespace AsbCloudDb.Migrations
|
||||
.HasColumnName("id_user")
|
||||
.HasComment("Id пользователя по телеметрии на момент начала операции");
|
||||
|
||||
b.Property<double>("Value")
|
||||
.HasColumnType("double precision")
|
||||
.HasColumnName("value")
|
||||
.HasComment("Ключевой показатель операции");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("IdCategory");
|
||||
|
@ -39,6 +39,9 @@ namespace AsbCloudDb.Model
|
||||
[Column("depth_end"), Comment("Глубина после завершения операции, м")]
|
||||
public double DepthEnd { get; set; }
|
||||
|
||||
[Column("value"), Comment("Ключевой показатель операции")]
|
||||
public double Value { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
[ForeignKey(nameof(IdTelemetry))]
|
||||
public virtual Telemetry Telemetry { get; set; }
|
||||
|
@ -20,8 +20,6 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
|
||||
private readonly IOperationValueService operationValueService;
|
||||
private readonly IScheduleService scheduleService;
|
||||
|
||||
private IEnumerable<OperationValueDto> operationValues;
|
||||
|
||||
public DetectedOperationService(IAsbCloudDbContext db, IWellService wellService,
|
||||
IOperationValueService operationValueService, IScheduleService scheduleService)
|
||||
{
|
||||
@ -43,30 +41,31 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
|
||||
|
||||
var data = await query.ToListAsync(token);
|
||||
|
||||
operationValues = await operationValueService.GetAllAsync(token);
|
||||
var operationValues = await operationValueService.GetAllAsync(token);
|
||||
operationValues = operationValues.Where(o => o.IdWell == idWell);
|
||||
|
||||
var dtos = data.Select(o => Convert(o, well, operationValues));
|
||||
foreach (var item in dtos)
|
||||
{
|
||||
item.Driller = await scheduleService.GetDrillerAsync(idWell, item.DateStart);
|
||||
}
|
||||
res.List = dtos;
|
||||
res.Count = dtos.GroupBy(o => o.Driller==null?0:o.Driller.Id,
|
||||
p=>p,
|
||||
(key,gr)=>(key,gr.Count())).ToDictionary(e=>e.key,e=>e.Item2);
|
||||
|
||||
res.Average = dtos.GroupBy(o => o.Driller == null ? 0 : o.Driller.Id,
|
||||
var group = dtos.GroupBy(o => o.Driller == null ? 0 : o.Driller.Id,
|
||||
p => p,
|
||||
(key, gr) => (key,
|
||||
gr.Sum(o => o.OperationValue?.TargetValue??0)/ gr.Count()
|
||||
)).ToDictionary(e => e.key, e => e.Item2);
|
||||
|
||||
//res.Efficiency = dtos.GroupBy(o => o.Driller == null ? 0 : o.Driller.Id,
|
||||
// p => p,
|
||||
// (key, gr) => (key,
|
||||
// 100*gr.Where(i=>i.OperationValue.PredicateTarget(5)).Sum(o => o.OperationValue?.TargetValue ?? 0) / gr.Count()
|
||||
// )).ToDictionary(e => e.key, e => e.Item2);
|
||||
(key, gr) => (key, gr.ToList())).ToDictionary(e => e.key, e => e.Item2);
|
||||
res.List = dtos;
|
||||
res.Stats = new List<DetectedOperationStatDto>();
|
||||
foreach (var item in group)
|
||||
{
|
||||
var obj = new DetectedOperationStatDto();
|
||||
obj.Driller = item.Value.FirstOrDefault()?.Driller;
|
||||
obj.Count = item.Value.Count();
|
||||
obj.Average = item.Value.Sum(e=>e.OperationValue?.TargetValue ?? 0)/obj.Count;
|
||||
obj.Efficiency = 100d * item.Value.Count(e => PredicateTarget(e)(e.Value)) / obj.Count;
|
||||
obj.AverageByParam = item.Value.Sum(e => e.Value) / obj.Count;
|
||||
obj.Loss = item.Value
|
||||
.Where(e => !PredicateTarget(e)(e.Value))
|
||||
.Sum(p => Math.Abs(p.Value - p.OperationValue?.TargetValue ?? 0));
|
||||
res.Stats.Add(obj);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -81,6 +80,20 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
|
||||
return await db.SaveChangesAsync(token);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Определение применяемого предикат по типц операции
|
||||
/// </summary>
|
||||
/// <returns>Предикат для использования</returns>
|
||||
private static Predicate<double> PredicateTarget(DetectedOperationDto op)
|
||||
{
|
||||
return op.OperationValue.IdOperationCategory switch
|
||||
{
|
||||
1 => (x) => false,
|
||||
11 => (x) => x > op.OperationValue.TargetValue,
|
||||
_ => (x) => true
|
||||
};
|
||||
}
|
||||
|
||||
private IQueryable<DetectedOperation> BuildQuery(WellDto well, DetectedOperationRequest request)
|
||||
{
|
||||
if (well?.IdTelemetry is null || well.Timezone is null)
|
||||
|
@ -49,6 +49,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
|
||||
DepthStart = telemetry[position].WellDepth ?? -1d,
|
||||
DepthEnd = telemetry[skip].WellDepth ?? -1d,
|
||||
};
|
||||
CalcValue(ref result);
|
||||
position = skip + FragmentLength;
|
||||
return result;
|
||||
}
|
||||
@ -59,6 +60,8 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
|
||||
return null;
|
||||
}
|
||||
|
||||
protected abstract void CalcValue(ref DetectedOperation result);
|
||||
|
||||
protected abstract bool DetectStart(DetectableTelemetry[] telemetry, int position);
|
||||
|
||||
protected abstract bool DetectEnd(DetectableTelemetry[] telemetry, int position);
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Linq;
|
||||
using AsbCloudDb.Model;
|
||||
using System.Linq;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
|
||||
{
|
||||
@ -42,7 +43,11 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
|
||||
|
||||
protected override bool DetectEnd(DetectableTelemetry[] telemetry, int position)
|
||||
=> !DetectStart(telemetry, position);
|
||||
|
||||
|
||||
protected override void CalcValue(ref DetectedOperation result)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
#nullable disable
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Linq;
|
||||
using AsbCloudDb.Model;
|
||||
using System.Linq;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
|
||||
{
|
||||
@ -41,7 +42,11 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
|
||||
|
||||
protected override bool DetectEnd(DetectableTelemetry[] telemetry, int position)
|
||||
=> !DetectStart(telemetry, position);
|
||||
|
||||
|
||||
protected override void CalcValue(ref DetectedOperation result)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
#nullable disable
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
|
||||
using AsbCloudDb.Model;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
|
||||
{
|
||||
#nullable enable
|
||||
class DetectorSlipsTime : DetectorAbstract
|
||||
@ -31,6 +33,11 @@
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected override void CalcValue(ref DetectedOperation result)
|
||||
{
|
||||
result.Value = result.DurationMinutes;
|
||||
}
|
||||
}
|
||||
#nullable disable
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user