forked from ddrilling/AsbCloudServer
nit SubsystemDetector.Detect() refactor
This commit is contained in:
parent
007a3f1e95
commit
64a4d80d9a
@ -15,7 +15,6 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace AsbCloudInfrastructure.Services.Subsystems
|
namespace AsbCloudInfrastructure.Services.Subsystems
|
||||||
{
|
{
|
||||||
|
|
||||||
internal static class SubsystemOperationTimeCalcWorkFactory
|
internal static class SubsystemOperationTimeCalcWorkFactory
|
||||||
{
|
{
|
||||||
private const string workId = "Subsystem operation time calc";
|
private const string workId = "Subsystem operation time calc";
|
||||||
@ -142,23 +141,19 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
var date = result.GetFieldValue<DateTimeOffset>(0);
|
var date = result.GetFieldValue<DateTimeOffset>(0);
|
||||||
var depth = result.GetFieldValue<float>(2);
|
var depth = result.GetFieldValue<float>(2);
|
||||||
|
|
||||||
var rotorSubsystemOperationTime = detectorRotor.Detect(mode, date, depth);
|
if (detectorRotor.TryDetect(mode, date, depth, out var detectedRotor))
|
||||||
if (rotorSubsystemOperationTime != null)
|
subsystemsOperationTimes.Add(detectedRotor!);
|
||||||
subsystemsOperationTimes.Add(rotorSubsystemOperationTime);
|
|
||||||
|
|
||||||
var slideSubsystemOperationTime = detectorSlide.Detect(mode, date, depth);
|
if (detectorSlide.TryDetect(mode, date, depth, out var detectedSlide))
|
||||||
if (slideSubsystemOperationTime != null)
|
subsystemsOperationTimes.Add(detectedSlide!);
|
||||||
subsystemsOperationTimes.Add(slideSubsystemOperationTime);
|
|
||||||
|
|
||||||
var mseSubsystemOperationTime = detectorMse.Detect(mode, date, depth);
|
if (detectorMse.TryDetect(mode, date, depth, out var detectedMse))
|
||||||
if (mseSubsystemOperationTime != null)
|
subsystemsOperationTimes.Add(detectedMse!);
|
||||||
subsystemsOperationTimes.Add(mseSubsystemOperationTime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return subsystemsOperationTimes;
|
return subsystemsOperationTimes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static async Task<IEnumerable<SubsystemOperationTime>> OperationTimeSpinAsync(int idTelemetry, DateTimeOffset begin, IAsbCloudDbContext db, CancellationToken token)
|
private static async Task<IEnumerable<SubsystemOperationTime>> OperationTimeSpinAsync(int idTelemetry, DateTimeOffset begin, IAsbCloudDbContext db, CancellationToken token)
|
||||||
{
|
{
|
||||||
static int? GetSubsytemId(short? mode, int? state)
|
static int? GetSubsytemId(short? mode, int? state)
|
||||||
@ -193,23 +188,22 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
$"order by date;";
|
$"order by date;";
|
||||||
|
|
||||||
var rows = new List<(int? IdSubsystem, DateTimeOffset Date)>(32);
|
var rows = new List<(int? IdSubsystem, DateTimeOffset Date)>(32);
|
||||||
|
|
||||||
|
using var resultSpin = await ExecuteReaderAsync(db, querySpin, token);
|
||||||
|
int? idSubsystemLast = null;
|
||||||
|
while (resultSpin.Read())
|
||||||
{
|
{
|
||||||
using var resultSpin = await ExecuteReaderAsync(db, querySpin, token);
|
var mode = resultSpin.GetFieldValue<short?>(1);
|
||||||
int? idSubsystemLast = null;
|
var state = resultSpin.GetFieldValue<short?>(2);
|
||||||
while (resultSpin.Read())
|
var idSubsystem = GetSubsytemId(mode, state);
|
||||||
|
if (idSubsystemLast != idSubsystem)
|
||||||
{
|
{
|
||||||
var mode = resultSpin.GetFieldValue<short?>(1);
|
idSubsystemLast = idSubsystem;
|
||||||
var state = resultSpin.GetFieldValue<short?>(2);
|
var date = resultSpin.GetFieldValue<DateTimeOffset>(0);
|
||||||
var idSubsystem = GetSubsytemId(mode, state);
|
rows.Add((idSubsystem, date));
|
||||||
if (idSubsystemLast != idSubsystem)
|
|
||||||
{
|
|
||||||
idSubsystemLast = idSubsystem;
|
|
||||||
var date = resultSpin.GetFieldValue<DateTimeOffset>(0);
|
|
||||||
rows.Add((idSubsystem, date));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
await resultSpin.DisposeAsync();
|
|
||||||
}
|
}
|
||||||
|
await resultSpin.DisposeAsync();
|
||||||
|
|
||||||
if (rows.Count < 2)
|
if (rows.Count < 2)
|
||||||
return Enumerable.Empty<SubsystemOperationTime>();
|
return Enumerable.Empty<SubsystemOperationTime>();
|
||||||
|
@ -401,8 +401,6 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
|
|
||||||
if (request?.Take > 0)
|
if (request?.Take > 0)
|
||||||
query = query.Take((int)request.Take);
|
query = query.Take((int)request.Take);
|
||||||
//else
|
|
||||||
//query = query.Take(3000);
|
|
||||||
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
this.isValid = isValid;
|
this.isValid = isValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SubsystemOperationTime? Detect(short? mode, DateTimeOffset date, float depth)
|
public bool TryDetect(short? mode, DateTimeOffset date, float depth, out SubsystemOperationTime? subsystemOperationTime)
|
||||||
{
|
{
|
||||||
var isEnable = this.isEnable(mode);
|
var isEnable = this.isEnable(mode);
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
}
|
}
|
||||||
else if (pre.isEnable && !isEnable)
|
else if (pre.isEnable && !isEnable)
|
||||||
{
|
{
|
||||||
var subsystemOperationTime = new SubsystemOperationTime
|
var detected = new SubsystemOperationTime
|
||||||
{
|
{
|
||||||
IdTelemetry = idTelemetry,
|
IdTelemetry = idTelemetry,
|
||||||
IdSubsystem = idSubsystem,
|
IdSubsystem = idSubsystem,
|
||||||
@ -43,13 +43,14 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
DepthEnd = depth,
|
DepthEnd = depth,
|
||||||
};
|
};
|
||||||
pre.isEnable = false;
|
pre.isEnable = false;
|
||||||
if (!isValid(subsystemOperationTime))
|
if (isValid(detected))
|
||||||
return null;
|
{
|
||||||
|
subsystemOperationTime = detected;
|
||||||
return subsystemOperationTime;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
subsystemOperationTime = null;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user