forked from ddrilling/AsbCloudServer
Изменение алгоритма выбора подсистемы АКБ
This commit is contained in:
parent
174be9b35f
commit
c6a49056bd
@ -16,7 +16,7 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
||||
{
|
||||
#nullable enable
|
||||
internal class SubsystemOperationTimeBackgroundService : BackgroundService
|
||||
{
|
||||
{
|
||||
private readonly string connectionString;
|
||||
private readonly TimeSpan period = TimeSpan.FromHours(1);
|
||||
private const int idSubsytemTorqueMaster = 65537;
|
||||
@ -112,12 +112,12 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
||||
{
|
||||
if (mode == 1 | mode == 3)
|
||||
return 1;
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
static bool IsSubsystemMse(short state)
|
||||
{
|
||||
{
|
||||
if ((state & 1) > 0)
|
||||
return true;
|
||||
return false;
|
||||
@ -137,79 +137,57 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
||||
$" order by date ) as tt " +
|
||||
$"where (tt.mode_prev is null or tt.mode != tt.mode_prev) and tt.date >= @begin " +
|
||||
$"order by tt.date;";
|
||||
|
||||
|
||||
var idTelemetryParam = new NpgsqlParameter("@idTelemetry", idTelemetry);
|
||||
var beginParam = new NpgsqlParameter("@begin", begin);
|
||||
|
||||
|
||||
await db.Database.OpenConnectionAsync(token);
|
||||
using var command = db.Database.GetDbConnection().CreateCommand();
|
||||
command.CommandText = query;
|
||||
command.Parameters.Add(idTelemetryParam);
|
||||
using var command = db.Database.GetDbConnection().CreateCommand();
|
||||
command.CommandText = query;
|
||||
command.Parameters.Add(idTelemetryParam);
|
||||
command.Parameters.Add(beginParam);
|
||||
|
||||
|
||||
using var result = await command.ExecuteReaderAsync(token);
|
||||
|
||||
var subsystemOperationTime = new List<SubsystemOperationTime>(32);
|
||||
|
||||
var prevSubsystem1 = false;
|
||||
DateTimeOffset? prevDate = null;
|
||||
|
||||
if (result.Read())
|
||||
{
|
||||
var mode = result.GetFieldValue<short>(1);
|
||||
var mseState = result.GetFieldValue<short>(3);
|
||||
//var mseState = result.GetFieldValue<short>(3);
|
||||
var idSubsystem = GetSubsytemId(mode);
|
||||
var foundSubsystem = idSubsystem.HasValue;
|
||||
var dateStart = result.GetFieldValue<DateTimeOffset>(0);
|
||||
var depthStart = result.GetFieldValue<float>(2);
|
||||
var depthStart = result.GetFieldValue<float>(2);
|
||||
|
||||
while (result.Read())
|
||||
{
|
||||
var dateEnd = result.GetFieldValue<DateTimeOffset>(0);
|
||||
var depthEnd = result.GetFieldValue<float>(2);
|
||||
if (idSubsystem.HasValue)
|
||||
var currentMode = result.GetFieldValue<short>(1);
|
||||
var currentSubsystemAkb = GetSubsytemId(currentMode);
|
||||
var endSubsystemAkb = !currentSubsystemAkb.HasValue;
|
||||
if (foundSubsystem && endSubsystemAkb)
|
||||
{
|
||||
if (idSubsystem == 1)
|
||||
{
|
||||
prevSubsystem1 = true;
|
||||
prevDate = dateStart;
|
||||
}
|
||||
else
|
||||
{
|
||||
prevSubsystem1 = false;
|
||||
prevDate = null;
|
||||
}
|
||||
|
||||
|
||||
var operationTimeItem = new SubsystemOperationTime()
|
||||
{
|
||||
IdTelemetry = idTelemetry,
|
||||
IdSubsystem = idSubsystem.Value,
|
||||
DateStart = (DateTimeOffset)(prevSubsystem1 ? prevDate : dateStart),
|
||||
DateEnd = dateEnd,
|
||||
DepthStart = depthStart,
|
||||
DepthEnd = depthEnd
|
||||
};
|
||||
subsystemOperationTime.Add(operationTimeItem);
|
||||
if (IsSubsystemMse(mseState))
|
||||
{
|
||||
var operationTimeItemMse = new SubsystemOperationTime()
|
||||
{
|
||||
IdTelemetry = idTelemetry,
|
||||
IdSubsystem = 2,
|
||||
DateStart = (DateTimeOffset)(prevSubsystem1 ? prevDate : dateStart),
|
||||
DateEnd = dateEnd,
|
||||
DepthStart = depthStart,
|
||||
DepthEnd = depthEnd
|
||||
};
|
||||
subsystemOperationTime.Add(operationTimeItemMse);
|
||||
}
|
||||
|
||||
IdTelemetry = idTelemetry,
|
||||
IdSubsystem = idSubsystem.Value,
|
||||
DateStart = dateStart,
|
||||
DateEnd = dateEnd,
|
||||
DepthStart = depthStart,
|
||||
DepthEnd = depthEnd
|
||||
};
|
||||
subsystemOperationTime.Add(operationTimeItem);
|
||||
foundSubsystem = false;
|
||||
}
|
||||
|
||||
mode = result.GetFieldValue<short>(1);
|
||||
mseState = result.GetFieldValue<short>(3);
|
||||
idSubsystem = GetSubsytemId(mode);
|
||||
dateStart = dateEnd;
|
||||
depthStart = depthEnd;
|
||||
if (currentSubsystemAkb.HasValue && !foundSubsystem)
|
||||
{
|
||||
idSubsystem = currentSubsystemAkb;
|
||||
dateStart = dateEnd;
|
||||
foundSubsystem = true;
|
||||
depthStart = depthEnd;
|
||||
}
|
||||
}
|
||||
}
|
||||
return subsystemOperationTime;
|
||||
|
Loading…
Reference in New Issue
Block a user