forked from ddrilling/AsbCloudServer
АПД разбивается на ротор и слайд
This commit is contained in:
parent
23fd77eb9d
commit
e28ec2cd0a
@ -15,7 +15,7 @@ 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";
|
||||||
@ -24,6 +24,8 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
private const int idSubsytemTorqueMaster = 65537;
|
private const int idSubsytemTorqueMaster = 65537;
|
||||||
private const int idSubsytemSpinMaster = 65536;
|
private const int idSubsytemSpinMaster = 65536;
|
||||||
private const int idSubsytemAkb = 1;
|
private const int idSubsytemAkb = 1;
|
||||||
|
private const int idSubsytemAkbRototor = 11;
|
||||||
|
private const int idSubsytemAkbSlide = 12;
|
||||||
private const int idSubsytemMse = 2;
|
private const int idSubsytemMse = 2;
|
||||||
|
|
||||||
public static WorkPeriodic MakeWork()
|
public static WorkPeriodic MakeWork()
|
||||||
@ -85,8 +87,8 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
{
|
{
|
||||||
var connection = db.Database.GetDbConnection();
|
var connection = db.Database.GetDbConnection();
|
||||||
if (
|
if (
|
||||||
connection?.State is null ||
|
connection?.State is null ||
|
||||||
connection.State == ConnectionState.Broken ||
|
connection.State == ConnectionState.Broken ||
|
||||||
connection.State == ConnectionState.Closed)
|
connection.State == ConnectionState.Closed)
|
||||||
{
|
{
|
||||||
await db.Database.OpenConnectionAsync(token);
|
await db.Database.OpenConnectionAsync(token);
|
||||||
@ -101,11 +103,20 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
|
|
||||||
private static async Task<IEnumerable<SubsystemOperationTime>> OperationTimeSaubAsync(int idTelemetry, DateTimeOffset begin, IAsbCloudDbContext db, CancellationToken token)
|
private static async Task<IEnumerable<SubsystemOperationTime>> OperationTimeSaubAsync(int idTelemetry, DateTimeOffset begin, IAsbCloudDbContext db, CancellationToken token)
|
||||||
{
|
{
|
||||||
static bool isSubsytemAkb(short? mode)
|
static bool isSubsytemAkbRotor(short? mode)
|
||||||
{
|
{
|
||||||
if (mode is null)
|
if (mode is null)
|
||||||
return false;
|
return false;
|
||||||
if (mode == 1 | mode == 3)
|
if (mode == 1)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool isSubsytemAkbSlide(short? mode)
|
||||||
|
{
|
||||||
|
if (mode is null)
|
||||||
|
return false;
|
||||||
|
if (mode == 3)
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -138,8 +149,9 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
using var result = await ExecuteReaderAsync(db, query, token);
|
using var result = await ExecuteReaderAsync(db, query, token);
|
||||||
|
|
||||||
var subsystemsOperationTimes = new List<SubsystemOperationTime>();
|
var subsystemsOperationTimes = new List<SubsystemOperationTime>();
|
||||||
|
|
||||||
(bool isEnable, DateTimeOffset date, float depth) akbPre = default;
|
(bool isEnable, DateTimeOffset date, float depth) akbPreRotor = default;
|
||||||
|
(bool isEnable, DateTimeOffset date, float depth) akbPreSlide = default;
|
||||||
(bool isEnable, DateTimeOffset date, float depth) msePre = default;
|
(bool isEnable, DateTimeOffset date, float depth) msePre = default;
|
||||||
|
|
||||||
while (result.Read())
|
while (result.Read())
|
||||||
@ -147,29 +159,50 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
var mode = result.GetFieldValue<short?>(1);
|
var mode = result.GetFieldValue<short?>(1);
|
||||||
var state = result.GetFieldValue<short?>(3);
|
var state = result.GetFieldValue<short?>(3);
|
||||||
|
|
||||||
var isAkbEnable = isSubsytemAkb(mode);
|
var isAkbRotorEnable = isSubsytemAkbRotor(mode);
|
||||||
|
var isAkbSlideEnable = isSubsytemAkbSlide(mode);
|
||||||
var isMseEnable = IsSubsystemMse(state);
|
var isMseEnable = IsSubsystemMse(state);
|
||||||
var date = result.GetFieldValue<DateTimeOffset>(0);
|
var date = result.GetFieldValue<DateTimeOffset>(0);
|
||||||
var depth = result.GetFieldValue<float>(2);
|
var depth = result.GetFieldValue<float>(2);
|
||||||
|
|
||||||
if (!akbPre.isEnable && isAkbEnable)
|
if (!akbPreRotor.isEnable && isAkbRotorEnable)
|
||||||
{
|
{
|
||||||
akbPre = (true, date, depth);
|
akbPreRotor = (true, date, depth);
|
||||||
}
|
}
|
||||||
else if (akbPre.isEnable && !isAkbEnable)
|
else if (akbPreRotor.isEnable && !isAkbRotorEnable)
|
||||||
{
|
{
|
||||||
var subsystemOperationTime = new SubsystemOperationTime
|
var subsystemOperationTime = new SubsystemOperationTime
|
||||||
{
|
{
|
||||||
IdTelemetry = idTelemetry,
|
IdTelemetry = idTelemetry,
|
||||||
IdSubsystem = idSubsytemAkb,
|
IdSubsystem = idSubsytemAkbRototor,
|
||||||
DateStart = akbPre.date,
|
DateStart = akbPreRotor.date,
|
||||||
DateEnd = date,
|
DateEnd = date,
|
||||||
DepthStart = akbPre.depth,
|
DepthStart = akbPreRotor.depth,
|
||||||
DepthEnd = depth,
|
DepthEnd = depth,
|
||||||
};
|
};
|
||||||
if (IsValid(subsystemOperationTime))
|
if (IsValid(subsystemOperationTime))
|
||||||
subsystemsOperationTimes.Add(subsystemOperationTime);
|
subsystemsOperationTimes.Add(subsystemOperationTime);
|
||||||
akbPre.isEnable = false;
|
akbPreRotor.isEnable = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!akbPreSlide.isEnable && isAkbSlideEnable)
|
||||||
|
{
|
||||||
|
akbPreSlide = (true, date, depth);
|
||||||
|
}
|
||||||
|
else if (akbPreSlide.isEnable && !isAkbSlideEnable)
|
||||||
|
{
|
||||||
|
var subsystemOperationTime = new SubsystemOperationTime
|
||||||
|
{
|
||||||
|
IdTelemetry = idTelemetry,
|
||||||
|
IdSubsystem = idSubsytemAkbSlide,
|
||||||
|
DateStart = akbPreSlide.date,
|
||||||
|
DateEnd = date,
|
||||||
|
DepthStart = akbPreSlide.depth,
|
||||||
|
DepthEnd = depth,
|
||||||
|
};
|
||||||
|
if (IsValid(subsystemOperationTime))
|
||||||
|
subsystemsOperationTimes.Add(subsystemOperationTime);
|
||||||
|
akbPreSlide.isEnable = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!msePre.isEnable && isMseEnable)
|
if (!msePre.isEnable && isMseEnable)
|
||||||
@ -182,21 +215,22 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
{
|
{
|
||||||
IdTelemetry = idTelemetry,
|
IdTelemetry = idTelemetry,
|
||||||
IdSubsystem = idSubsytemMse,
|
IdSubsystem = idSubsytemMse,
|
||||||
DateStart = akbPre.date,
|
DateStart = akbPreRotor.date < akbPreSlide.date ? akbPreRotor.date : akbPreSlide.date,
|
||||||
DateEnd = date,
|
DateEnd = date,
|
||||||
DepthStart = akbPre.depth,
|
DepthStart = akbPreRotor.depth < akbPreSlide.depth ? akbPreRotor.depth : akbPreSlide.depth,
|
||||||
DepthEnd = depth,
|
DepthEnd = depth,
|
||||||
};
|
};
|
||||||
if (IsValid(subsystemOperationTime))
|
if (IsValid(subsystemOperationTime))
|
||||||
subsystemsOperationTimes.Add(subsystemOperationTime);
|
subsystemsOperationTimes.Add(subsystemOperationTime);
|
||||||
|
|
||||||
msePre.isEnable = false;
|
msePre.isEnable = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
@ -215,7 +249,7 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
$"select " +
|
$"select " +
|
||||||
$" tspin.date, " +
|
$" tspin.date, " +
|
||||||
$" tspin.mode, " +
|
$" tspin.mode, " +
|
||||||
$" tspin.state " +
|
$" tspin.state " +
|
||||||
$"from ( " +
|
$"from ( " +
|
||||||
$" select " +
|
$" select " +
|
||||||
$" date, " +
|
$" date, " +
|
||||||
@ -226,7 +260,7 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
$" lag(state, 1) over (order by date) as state_lag " +
|
$" lag(state, 1) over (order by date) as state_lag " +
|
||||||
$" from t_telemetry_data_spin " +
|
$" from t_telemetry_data_spin " +
|
||||||
$" where id_telemetry = {idTelemetry} and date >= '{begin:u}'" +
|
$" where id_telemetry = {idTelemetry} and date >= '{begin:u}'" +
|
||||||
$" order by date ) as tspin " +
|
$" order by date ) as tspin " +
|
||||||
$"where mode_lag is null or state_lag is null or (mode != mode_lag and mode_lead != mode_lag) or state != state_lag " +
|
$"where mode_lag is null or state_lag is null or (mode != mode_lag and mode_lead != mode_lag) or state != state_lag " +
|
||||||
$"order by date;";
|
$"order by date;";
|
||||||
|
|
||||||
@ -239,12 +273,12 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
var mode = resultSpin.GetFieldValue<short?>(1);
|
var mode = resultSpin.GetFieldValue<short?>(1);
|
||||||
var state = resultSpin.GetFieldValue<short?>(2);
|
var state = resultSpin.GetFieldValue<short?>(2);
|
||||||
var idSubsystem = GetSubsytemId(mode, state);
|
var idSubsystem = GetSubsytemId(mode, state);
|
||||||
if(idSubsystemLast != idSubsystem)
|
if (idSubsystemLast != idSubsystem)
|
||||||
{
|
{
|
||||||
idSubsystemLast = idSubsystem;
|
idSubsystemLast = idSubsystem;
|
||||||
var date = resultSpin.GetFieldValue<DateTimeOffset>(0);
|
var date = resultSpin.GetFieldValue<DateTimeOffset>(0);
|
||||||
rows.Add((idSubsystem, date));
|
rows.Add((idSubsystem, date));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await resultSpin.DisposeAsync();
|
await resultSpin.DisposeAsync();
|
||||||
}
|
}
|
||||||
@ -260,7 +294,7 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
return Enumerable.Empty<SubsystemOperationTime>();
|
return Enumerable.Empty<SubsystemOperationTime>();
|
||||||
|
|
||||||
var subsystemsOperationTimes = new List<SubsystemOperationTime>(32);
|
var subsystemsOperationTimes = new List<SubsystemOperationTime>(32);
|
||||||
|
|
||||||
for (int i = 1; i < rows.Count; i++)
|
for (int i = 1; i < rows.Count; i++)
|
||||||
{
|
{
|
||||||
var r0 = rows[i - 1];
|
var r0 = rows[i - 1];
|
||||||
@ -276,12 +310,12 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
DepthStart = depthInterpolation.GetDepth(r0.Date),
|
DepthStart = depthInterpolation.GetDepth(r0.Date),
|
||||||
DepthEnd = depthInterpolation.GetDepth(r1.Date),
|
DepthEnd = depthInterpolation.GetDepth(r1.Date),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (IsValid(subsystemOperationTime))
|
if (IsValid(subsystemOperationTime))
|
||||||
subsystemsOperationTimes.Add(subsystemOperationTime);
|
subsystemsOperationTimes.Add(subsystemOperationTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return subsystemsOperationTimes;
|
return subsystemsOperationTimes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -336,7 +370,7 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
if (!dataDepthFromSaub.Any())
|
if (!dataDepthFromSaub.Any())
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
var depthInterpolation = new DepthInterpolation(dataDepthFromSaub.Select(i=>(i.DateMin, i.DepthMin)));
|
var depthInterpolation = new DepthInterpolation(dataDepthFromSaub.Select(i => (i.DateMin, i.DepthMin)));
|
||||||
return depthInterpolation;
|
return depthInterpolation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -146,28 +146,44 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
private IEnumerable<SubsystemStatDto> CalcStat(IEnumerable<SubsystemOperationTimeDto> dtos, (double depthIntervalRotor, double depthIntervalSlide) depthInterval)
|
private IEnumerable<SubsystemStatDto> CalcStat(IEnumerable<SubsystemOperationTimeDto> dtos, (double depthIntervalRotor, double depthIntervalSlide) depthInterval)
|
||||||
{
|
{
|
||||||
var groupedDataSubsystems = dtos
|
var groupedDataSubsystems = dtos
|
||||||
|
.OrderBy(o => o.Id)
|
||||||
.GroupBy(o => o.IdSubsystem);
|
.GroupBy(o => o.IdSubsystem);
|
||||||
var periodGroupTotal = dtos.Sum(o => (o.DateEnd - o.DateStart).TotalHours);
|
var periodGroupTotal = dtos.Sum(o => (o.DateEnd - o.DateStart).TotalHours);
|
||||||
|
|
||||||
var result = groupedDataSubsystems.Select(g =>
|
var result = groupedDataSubsystems.Select(g =>
|
||||||
{
|
{
|
||||||
var depthIntervalSubsystem = GetDepthIntervalSubsystem(g.Key, depthInterval);
|
var depthIntervalSubsystem = GetDepthIntervalSubsystem(g.Key, depthInterval);
|
||||||
var periodGroup = g.Sum(o => (o.DateEnd - o.DateStart).TotalHours);
|
var periodGroup = g.Sum(o => (o.DateEnd - o.DateStart).TotalHours);
|
||||||
var periodGroupDepth = g.Sum(o => o.DepthEnd - o.DepthStart);
|
var periodGroupDepth = g.Sum(o => o.DepthEnd - o.DepthStart);
|
||||||
var subsystemStat = new SubsystemStatDto()
|
var subsystemStat = new SubsystemStatDto()
|
||||||
{
|
{
|
||||||
IdSubsystem = g.Key,
|
IdSubsystem = g.Key,
|
||||||
SubsystemName = subsystemService.GetOrDefault(g.Key)?.Name ?? "unknown",
|
SubsystemName = subsystemService.GetOrDefault(g.Key)?.Name ?? "unknown",
|
||||||
UsedTimeHours = periodGroup,
|
UsedTimeHours = periodGroup,
|
||||||
KUsage = periodGroupDepth / depthIntervalSubsystem,
|
KUsage = periodGroupDepth / depthIntervalSubsystem,
|
||||||
SumDepthInterval = periodGroupDepth,
|
SumDepthInterval = periodGroupDepth,
|
||||||
OperationCount = g.Count()
|
OperationCount = g.Count()
|
||||||
};
|
};
|
||||||
if(subsystemStat.KUsage > 1)
|
if (subsystemStat.KUsage > 1)
|
||||||
subsystemStat.KUsage = 1;
|
subsystemStat.KUsage = 1;
|
||||||
return subsystemStat;
|
return subsystemStat;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var apdParts = result.Where(x => x.IdSubsystem == 11 || x.IdSubsystem == 12);
|
||||||
|
if (apdParts.Any())
|
||||||
|
{
|
||||||
|
var apdSum = new SubsystemStatDto()
|
||||||
|
{
|
||||||
|
IdSubsystem = 1,
|
||||||
|
SubsystemName = "АПД",
|
||||||
|
UsedTimeHours = apdParts.Sum(part => part.UsedTimeHours),
|
||||||
|
KUsage = apdParts.Sum(part => part.KUsage) / apdParts.Count(),
|
||||||
|
SumDepthInterval = apdParts.Sum(part => part.SumDepthInterval),
|
||||||
|
OperationCount = apdParts.Sum(part => part.OperationCount),
|
||||||
|
};
|
||||||
|
result = result.Append(apdSum).OrderBy(m => m.IdSubsystem);
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
private static (double depthIntervalRotor, double depthIntervalSlide) GetDepthInterval (IEnumerable<DetectedOperationDto> detectedOperations)
|
private static (double depthIntervalRotor, double depthIntervalSlide) GetDepthInterval (IEnumerable<DetectedOperationDto> detectedOperations)
|
||||||
@ -348,8 +364,8 @@ 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
|
//else
|
||||||
query = query.Take(3000);
|
//query = query.Take(3000);
|
||||||
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user