Добавление показателя в операцию. Изменение структуры ответа

This commit is contained in:
Lyudmila Romanova 2022-06-10 18:36:14 +05:00
parent e5c1880225
commit 9764809c3a
12 changed files with 6182 additions and 65 deletions

View File

@ -67,5 +67,7 @@ namespace AsbCloudApp.Data
/// Целевые/нормативные показатели /// Целевые/нормативные показатели
/// </summary> /// </summary>
public OperationValueDto OperationValue { get; set; } public OperationValueDto OperationValue { get; set; }
public double Value { get; set; }
} }
} }

View File

@ -4,40 +4,49 @@ using System.Linq;
namespace AsbCloudApp.Data 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>
/// Автоматически определяемая операция /// Автоматически определяемая операция
/// </summary> /// </summary>
public class DetectedOperationListDto public class DetectedOperationListDto
{ {
public IEnumerable<IGrouping<int, DetectedOperationDto>> test { get; set; }
/// <summary> /// <summary>
/// Список всех операций /// Список всех операций
/// </summary> /// </summary>
public IEnumerable<DetectedOperationDto> List { get; set; } public IEnumerable<DetectedOperationDto> List { get; set; }
/// <summary> public ICollection<DetectedOperationStatDto> Stats { get; set; }
/// Количество по
/// </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; }
} }
} }

View File

@ -42,21 +42,5 @@ namespace AsbCloudApp.Data
/// </summary> /// </summary>
public double DepthEnd { get; set; } 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
};
}
}
} }
} }

File diff suppressed because it is too large Load Diff

View 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");
}
}
}

View File

@ -239,6 +239,11 @@ namespace AsbCloudDb.Migrations
.HasColumnName("id_user") .HasColumnName("id_user")
.HasComment("Id пользователя по телеметрии на момент начала операции"); .HasComment("Id пользователя по телеметрии на момент начала операции");
b.Property<double>("Value")
.HasColumnType("double precision")
.HasColumnName("value")
.HasComment("Ключевой показатель операции");
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("IdCategory"); b.HasIndex("IdCategory");

View File

@ -39,6 +39,9 @@ namespace AsbCloudDb.Model
[Column("depth_end"), Comment("Глубина после завершения операции, м")] [Column("depth_end"), Comment("Глубина после завершения операции, м")]
public double DepthEnd { get; set; } public double DepthEnd { get; set; }
[Column("value"), Comment("Ключевой показатель операции")]
public double Value { get; set; }
[JsonIgnore] [JsonIgnore]
[ForeignKey(nameof(IdTelemetry))] [ForeignKey(nameof(IdTelemetry))]
public virtual Telemetry Telemetry { get; set; } public virtual Telemetry Telemetry { get; set; }

View File

@ -20,8 +20,6 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
private readonly IOperationValueService operationValueService; private readonly IOperationValueService operationValueService;
private readonly IScheduleService scheduleService; private readonly IScheduleService scheduleService;
private IEnumerable<OperationValueDto> operationValues;
public DetectedOperationService(IAsbCloudDbContext db, IWellService wellService, public DetectedOperationService(IAsbCloudDbContext db, IWellService wellService,
IOperationValueService operationValueService, IScheduleService scheduleService) IOperationValueService operationValueService, IScheduleService scheduleService)
{ {
@ -43,30 +41,31 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
var data = await query.ToListAsync(token); var data = await query.ToListAsync(token);
operationValues = await operationValueService.GetAllAsync(token); var operationValues = await operationValueService.GetAllAsync(token);
operationValues = operationValues.Where(o => o.IdWell == idWell); operationValues = operationValues.Where(o => o.IdWell == idWell);
var dtos = data.Select(o => Convert(o, well, operationValues)); var dtos = data.Select(o => Convert(o, well, operationValues));
foreach (var item in dtos) foreach (var item in dtos)
{ {
item.Driller = await scheduleService.GetDrillerAsync(idWell, item.DateStart); item.Driller = await scheduleService.GetDrillerAsync(idWell, item.DateStart);
} }
var group = dtos.GroupBy(o => o.Driller == null ? 0 : o.Driller.Id,
p => p,
(key, gr) => (key, gr.ToList())).ToDictionary(e => e.key, e => e.Item2);
res.List = dtos; res.List = dtos;
res.Count = dtos.GroupBy(o => o.Driller==null?0:o.Driller.Id, res.Stats = new List<DetectedOperationStatDto>();
p=>p, foreach (var item in group)
(key,gr)=>(key,gr.Count())).ToDictionary(e=>e.key,e=>e.Item2); {
var obj = new DetectedOperationStatDto();
res.Average = dtos.GroupBy(o => o.Driller == null ? 0 : o.Driller.Id, obj.Driller = item.Value.FirstOrDefault()?.Driller;
p => p, obj.Count = item.Value.Count();
(key, gr) => (key, obj.Average = item.Value.Sum(e=>e.OperationValue?.TargetValue ?? 0)/obj.Count;
gr.Sum(o => o.OperationValue?.TargetValue??0)/ gr.Count() obj.Efficiency = 100d * item.Value.Count(e => PredicateTarget(e)(e.Value)) / obj.Count;
)).ToDictionary(e => e.key, e => e.Item2); obj.AverageByParam = item.Value.Sum(e => e.Value) / obj.Count;
obj.Loss = item.Value
//res.Efficiency = dtos.GroupBy(o => o.Driller == null ? 0 : o.Driller.Id, .Where(e => !PredicateTarget(e)(e.Value))
// p => p, .Sum(p => Math.Abs(p.Value - p.OperationValue?.TargetValue ?? 0));
// (key, gr) => (key, res.Stats.Add(obj);
// 100*gr.Where(i=>i.OperationValue.PredicateTarget(5)).Sum(o => o.OperationValue?.TargetValue ?? 0) / gr.Count() }
// )).ToDictionary(e => e.key, e => e.Item2);
return res; return res;
} }
@ -81,6 +80,20 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
return await db.SaveChangesAsync(token); 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) private IQueryable<DetectedOperation> BuildQuery(WellDto well, DetectedOperationRequest request)
{ {
if (well?.IdTelemetry is null || well.Timezone is null) if (well?.IdTelemetry is null || well.Timezone is null)

View File

@ -49,6 +49,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
DepthStart = telemetry[position].WellDepth ?? -1d, DepthStart = telemetry[position].WellDepth ?? -1d,
DepthEnd = telemetry[skip].WellDepth ?? -1d, DepthEnd = telemetry[skip].WellDepth ?? -1d,
}; };
CalcValue(ref result);
position = skip + FragmentLength; position = skip + FragmentLength;
return result; return result;
} }
@ -59,6 +60,8 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
return null; return null;
} }
protected abstract void CalcValue(ref DetectedOperation result);
protected abstract bool DetectStart(DetectableTelemetry[] telemetry, int position); protected abstract bool DetectStart(DetectableTelemetry[] telemetry, int position);
protected abstract bool DetectEnd(DetectableTelemetry[] telemetry, int position); protected abstract bool DetectEnd(DetectableTelemetry[] telemetry, int position);

View File

@ -1,4 +1,5 @@
using System.Linq; using AsbCloudDb.Model;
using System.Linq;
namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
{ {
@ -43,6 +44,10 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
protected override bool DetectEnd(DetectableTelemetry[] telemetry, int position) protected override bool DetectEnd(DetectableTelemetry[] telemetry, int position)
=> !DetectStart(telemetry, position); => !DetectStart(telemetry, position);
protected override void CalcValue(ref DetectedOperation result)
{
throw new System.NotImplementedException();
}
} }
#nullable disable #nullable disable
} }

View File

@ -1,4 +1,5 @@
using System.Linq; using AsbCloudDb.Model;
using System.Linq;
namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
{ {
@ -42,6 +43,10 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
protected override bool DetectEnd(DetectableTelemetry[] telemetry, int position) protected override bool DetectEnd(DetectableTelemetry[] telemetry, int position)
=> !DetectStart(telemetry, position); => !DetectStart(telemetry, position);
protected override void CalcValue(ref DetectedOperation result)
{
throw new System.NotImplementedException();
}
} }
#nullable disable #nullable disable
} }

View File

@ -1,4 +1,6 @@
namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors using AsbCloudDb.Model;
namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
{ {
#nullable enable #nullable enable
class DetectorSlipsTime : DetectorAbstract class DetectorSlipsTime : DetectorAbstract
@ -31,6 +33,11 @@
return result; return result;
} }
protected override void CalcValue(ref DetectedOperation result)
{
result.Value = result.DurationMinutes;
}
} }
#nullable disable #nullable disable
} }