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