forked from ddrilling/AsbCloudServer
-changing background subsystem service logic
-add migration, delete all subsystem table data -edit EntityFillerSubsystem (new subsystem)
This commit is contained in:
parent
9ca7bf75e7
commit
43f3a12651
6478
AsbCloudDb/Migrations/20220914072422_Remove_Subsystem_AllData.Designer.cs
generated
Normal file
6478
AsbCloudDb/Migrations/20220914072422_Remove_Subsystem_AllData.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,19 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace AsbCloudDb.Migrations
|
||||
{
|
||||
public partial class Remove_Subsystem_AllData : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.Sql("DELETE FROM t_subsystem", true);
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -19,7 +19,7 @@ namespace AsbCloudDb.Migrations
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.UseCollation("Russian_Russia.1251")
|
||||
.HasAnnotation("ProductVersion", "6.0.1")
|
||||
.HasAnnotation("ProductVersion", "6.0.7")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "adminpack");
|
||||
|
@ -4,16 +4,9 @@ namespace AsbCloudDb.Model.DefaultData
|
||||
internal class EntityFillerSubsystem : EntityFiller<Subsystem>
|
||||
{
|
||||
protected override Subsystem[] GetData() => new Subsystem[]{
|
||||
// САУБ - ид подсистем с 1 до 65_535
|
||||
new () {Id = 1, Name = "Ручной", Description = "Ручной"},
|
||||
new () {Id = 2, Name = "Бурение в роторе", Description = "Бурение в роторе"},
|
||||
new () {Id = 3, Name = "Проработка", Description = "Проработка"},
|
||||
new () {Id = 4, Name = "Бурение в слайде", Description = "Бурение в слайде"},
|
||||
new () {Id = 5, Name = "Спуск СПО", Description = "Спуск СПО"},
|
||||
new () {Id = 6, Name = "Подъем СПО", Description = "Подъем СПО"},
|
||||
new () {Id = 7, Name = "Подъем с проработкой", Description = "Подъем с проработкой"},
|
||||
new () {Id = 11, Name = "Блокировка", Description = "Блокировка"},
|
||||
|
||||
// САУБ - ид подсистем с 1 до 65_535
|
||||
new () {Id = 1, Name = "АКБ", Description = "Совместная работа режимов \"Бурение в роторе\" и \"Бурение в слайде\""},
|
||||
new () {Id = 2, Name = "MSE", Description = "Алгоритм поиска оптимальных параметров бурения САУБ"},
|
||||
//Spin master - id подсистем с 65_536 до 131_071
|
||||
new () {Id = 65536, Name = "Spin master", Description = "Spin master"},
|
||||
new () {Id = 65537, Name = "Torque master", Description = "Torque master"}
|
||||
|
@ -21,6 +21,8 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
||||
private readonly TimeSpan period = TimeSpan.FromHours(1);
|
||||
private const int idSubsytemTorqueMaster = 65537;
|
||||
private const int idSubsytemSpinMaster = 65536;
|
||||
private const int idSubsytemAkb = 1;
|
||||
private const int idSubsytemMse = 2;
|
||||
public SubsystemOperationTimeBackgroundService(IConfiguration configuration)
|
||||
{
|
||||
connectionString = configuration.GetConnectionString("DefaultConnection");
|
||||
@ -106,17 +108,22 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
||||
}
|
||||
private static async Task<IEnumerable<SubsystemOperationTime>> OperationTimeSaubAsync(int idTelemetry, DateTimeOffset begin, IAsbCloudDbContext db, CancellationToken token)
|
||||
{
|
||||
static int? GetSubsytemId(short mode)
|
||||
static int? GetSubsytemId(short mode, short state)
|
||||
{
|
||||
return mode +1;
|
||||
if (mode == 1 | mode == 3)
|
||||
return 1;
|
||||
if ((state & 1) > 0)
|
||||
return 2;
|
||||
return null;
|
||||
}
|
||||
|
||||
var query =
|
||||
$"select tt.date, tt.mode, tt.well_depth " +
|
||||
$"select tt.date, tt.mode, tt.well_depth, tt.mse_state " +
|
||||
$"from ( " +
|
||||
$" select " +
|
||||
$" date, " +
|
||||
$" mode, " +
|
||||
$" mse_state, " +
|
||||
$" well_depth, " +
|
||||
$" lag(mode,1) over (order by date) as mode_prev " +
|
||||
$" from t_telemetry_data_saub " +
|
||||
@ -138,31 +145,51 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
||||
|
||||
var subsystemOperationTime = new List<SubsystemOperationTime>(32);
|
||||
|
||||
var prevSubsystem1 = false;
|
||||
DateTimeOffset? prevDate = null;
|
||||
if (result.Read())
|
||||
{
|
||||
var mode = result.GetFieldValue<short>(1);
|
||||
var idSubsystem = GetSubsytemId(mode);
|
||||
var mseState = result.GetFieldValue<short>(3);
|
||||
var idSubsystem = GetSubsytemId(mode, mseState);
|
||||
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 operationTimeItem = new SubsystemOperationTime()
|
||||
if (idSubsystem == 1)
|
||||
{
|
||||
IdTelemetry = idTelemetry,
|
||||
IdSubsystem = idSubsystem.Value,
|
||||
DateStart = dateStart,
|
||||
DateEnd = dateEnd,
|
||||
DepthStart = depthStart,
|
||||
DepthEnd = depthEnd
|
||||
};
|
||||
subsystemOperationTime.Add(operationTimeItem);
|
||||
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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
mode = result.GetFieldValue<short>(1);
|
||||
idSubsystem = GetSubsytemId(mode);
|
||||
mseState = result.GetFieldValue<short>(3);
|
||||
idSubsystem = GetSubsytemId(mode, mseState);
|
||||
dateStart = dateEnd;
|
||||
depthStart = depthEnd;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user