nit SubsystemDetector.Detect() refactor

This commit is contained in:
ngfrolov 2023-09-15 16:21:17 +05:00
parent 007a3f1e95
commit 64a4d80d9a
Signed by untrusted user who does not match committer: ng.frolov
GPG Key ID: E99907A0357B29A7
3 changed files with 27 additions and 34 deletions

View File

@ -15,7 +15,6 @@ using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Services.Subsystems
{
internal static class SubsystemOperationTimeCalcWorkFactory
{
private const string workId = "Subsystem operation time calc";
@ -142,23 +141,19 @@ namespace AsbCloudInfrastructure.Services.Subsystems
var date = result.GetFieldValue<DateTimeOffset>(0);
var depth = result.GetFieldValue<float>(2);
var rotorSubsystemOperationTime = detectorRotor.Detect(mode, date, depth);
if (rotorSubsystemOperationTime != null)
subsystemsOperationTimes.Add(rotorSubsystemOperationTime);
if (detectorRotor.TryDetect(mode, date, depth, out var detectedRotor))
subsystemsOperationTimes.Add(detectedRotor!);
var slideSubsystemOperationTime = detectorSlide.Detect(mode, date, depth);
if (slideSubsystemOperationTime != null)
subsystemsOperationTimes.Add(slideSubsystemOperationTime);
if (detectorSlide.TryDetect(mode, date, depth, out var detectedSlide))
subsystemsOperationTimes.Add(detectedSlide!);
var mseSubsystemOperationTime = detectorMse.Detect(mode, date, depth);
if (mseSubsystemOperationTime != null)
subsystemsOperationTimes.Add(mseSubsystemOperationTime);
if (detectorMse.TryDetect(mode, date, depth, out var detectedMse))
subsystemsOperationTimes.Add(detectedMse!);
}
return subsystemsOperationTimes;
}
private static async Task<IEnumerable<SubsystemOperationTime>> OperationTimeSpinAsync(int idTelemetry, DateTimeOffset begin, IAsbCloudDbContext db, CancellationToken token)
{
static int? GetSubsytemId(short? mode, int? state)
@ -193,23 +188,22 @@ namespace AsbCloudInfrastructure.Services.Subsystems
$"order by date;";
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);
int? idSubsystemLast = null;
while (resultSpin.Read())
var mode = resultSpin.GetFieldValue<short?>(1);
var state = resultSpin.GetFieldValue<short?>(2);
var idSubsystem = GetSubsytemId(mode, state);
if (idSubsystemLast != idSubsystem)
{
var mode = resultSpin.GetFieldValue<short?>(1);
var state = resultSpin.GetFieldValue<short?>(2);
var idSubsystem = GetSubsytemId(mode, state);
if (idSubsystemLast != idSubsystem)
{
idSubsystemLast = idSubsystem;
var date = resultSpin.GetFieldValue<DateTimeOffset>(0);
rows.Add((idSubsystem, date));
}
idSubsystemLast = idSubsystem;
var date = resultSpin.GetFieldValue<DateTimeOffset>(0);
rows.Add((idSubsystem, date));
}
await resultSpin.DisposeAsync();
}
await resultSpin.DisposeAsync();
if (rows.Count < 2)
return Enumerable.Empty<SubsystemOperationTime>();

View File

@ -401,8 +401,6 @@ namespace AsbCloudInfrastructure.Services.Subsystems
if (request?.Take > 0)
query = query.Take((int)request.Take);
//else
//query = query.Take(3000);
return query;
}

View File

@ -23,7 +23,7 @@ namespace AsbCloudInfrastructure.Services.Subsystems
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);
@ -33,7 +33,7 @@ namespace AsbCloudInfrastructure.Services.Subsystems
}
else if (pre.isEnable && !isEnable)
{
var subsystemOperationTime = new SubsystemOperationTime
var detected = new SubsystemOperationTime
{
IdTelemetry = idTelemetry,
IdSubsystem = idSubsystem,
@ -43,13 +43,14 @@ namespace AsbCloudInfrastructure.Services.Subsystems
DepthEnd = depth,
};
pre.isEnable = false;
if (!isValid(subsystemOperationTime))
return null;
return subsystemOperationTime;
if (isValid(detected))
{
subsystemOperationTime = detected;
return true;
}
}
return null;
subsystemOperationTime = null;
return false;
}
}
}