This commit is contained in:
Фролов 2021-07-21 18:03:58 +05:00
commit e9d1abe58f
4 changed files with 233 additions and 84 deletions

View File

@ -113,29 +113,6 @@ namespace AsbCloudDb.Model
.HasConstraintName("t_event_t_telemetry_id_fk");
});
modelBuilder.Entity<UserRole>(entity =>
{
entity.HasData(new List<UserRole>{
new UserRole{ Id = 1, Caption = "Администратор", },
});
});
modelBuilder.Entity<CompanyType>(entity =>
{
entity.HasData(new List<CompanyType>{
new CompanyType{ Id = 1, Caption = "Недрапользователь", },
new CompanyType{ Id = 2, Caption = "Буровой подрядчик", },
new CompanyType{ Id = 3, Caption = "Сервис автоматизации бурения", },
});
});
modelBuilder.Entity<Company>(entity =>
{
entity.HasData(new List<Company>{
new Company{ Id = 1, Caption = "\"ООО\" АСБ", IdCompanyType = 3},
});
});
modelBuilder.Entity<User>(entity =>
{
entity.HasOne(d => d.Company)
@ -145,18 +122,6 @@ namespace AsbCloudDb.Model
entity.HasIndex(d => d.Login)
.IsUnique();
entity.HasData(new List<User>{
new User{
Id = 1,
IdCompany = 1,
IdRole = 1,
Level = int.MaxValue,
Login = "dev",
PasswordHash = "Vlcj|4fa529103dde7ff72cfe76185f344d4aa87931f8e1b2044e8a7739947c3d18923464eaad93843e4f809c5e126d013072", // dev
Name = "Разработчик",
},
});
});
modelBuilder.Entity<Well>(entity =>
@ -170,8 +135,6 @@ namespace AsbCloudDb.Model
.WithOne(p => p.Well)
.HasForeignKey<Well>(d => d.IdTelemetry)
.HasConstraintName("t_well_t_telemetry_id_fk");
});
modelBuilder.Entity<RelationCompanyWell>(entity => {
@ -190,54 +153,37 @@ namespace AsbCloudDb.Model
});
FillData(modelBuilder);
FillDemoData(modelBuilder);
}
private static void FillData(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Deposit>(entity =>
modelBuilder.Entity<UserRole>(entity =>
{
entity.HasData(new List<Deposit> {
new Deposit{Id = 1, Caption = "м/р 1", Latitude = 60.8705722222222, Longitude = 70.3811888888889 },
entity.HasData(new List<UserRole>{
new UserRole{ Id = 1, Caption = "Администратор", },
});
});
modelBuilder.Entity<Cluster>(entity =>
modelBuilder.Entity<User>(entity =>
{
entity.HasData(new List<Cluster> {
new Cluster{Id = 1, Caption = "к221", IdDeposit = 1, Latitude = 60.8705722222222, Longitude = 70.3811888888889},
new Cluster{Id = 2, Caption = "к151", IdDeposit = 1, Latitude = 60.8205750000000, Longitude = 70.1343833333334},
new Cluster{Id = 3, Caption = "к611", IdDeposit = 1, Latitude = 60.8100666666667, Longitude = 69.7778388888889},
new Cluster{Id = 4, Caption = "к203", IdDeposit = 1, Latitude = 60.8928805555556, Longitude = 70.3272055555556},
new Cluster{Id = 5, Caption = "к39.1", IdDeposit = 1, Latitude = 60.6672055555556, Longitude = 69.6603861111111},
entity.HasData(new List<User>{
new User{
Id = 1,
IdCompany = 1,
IdRole = 1,
Level = int.MaxValue,
Login = "dev",
PasswordHash = "Vlcj|4fa529103dde7ff72cfe76185f344d4aa87931f8e1b2044e8a7739947c3d18923464eaad93843e4f809c5e126d013072", // dev
Name = "Разработчик",
},
});
});
modelBuilder.Entity<Well>(entity =>
modelBuilder.Entity<Company>(entity =>
{
entity.HasData(new List<Well> {
new Well{Id = 1, IdCluster = 1, Caption = "скв 42669", Latitude = 60.8705722222222, Longitude = 70.3811888888889},
new Well{Id = 2, IdCluster = 1, Caption = "скв 16311", Latitude = 60.8705722222222, Longitude = 70.3811888888889},
new Well{Id = 3, IdCluster = 2, Caption = "скв 16315", Latitude = 60.8205750000000, Longitude = 70.1343833333334},
new Well{Id = 4, IdCluster = 2, Caption = "скв 16318", Latitude = 60.8205750000000, Longitude = 70.1343833333334},
new Well{Id = 5, IdCluster = 3, Caption = "скв 16310", Latitude = 60.8100666666667, Longitude = 69.7778388888889},
new Well{Id = 6, IdCluster = 4, Caption = "скв 16316", Latitude = 60.8928805555556, Longitude = 70.3272055555556},
new Well{Id = 7, IdCluster = 5, Caption = "скв 16312", Latitude = 60.6672055555556, Longitude = 69.6603861111111},
new Well{Id = 8, IdCluster = 5, Caption = "скв 16313", Latitude = 60.6672055555556, Longitude = 69.6603861111111},
new Well{Id = 9, IdCluster = 5, Caption = "скв 16314", Latitude = 60.6672055555556, Longitude = 69.6603861111111},
});
});
modelBuilder.Entity<RelationCompanyWell>(entity => {
entity.HasData(new List<RelationCompanyWell> {
new RelationCompanyWell{ IdWell = 1, IdCompany = 1},
new RelationCompanyWell{ IdWell = 2, IdCompany = 1},
new RelationCompanyWell{ IdWell = 3, IdCompany = 1},
new RelationCompanyWell{ IdWell = 4, IdCompany = 1},
new RelationCompanyWell{ IdWell = 5, IdCompany = 1},
new RelationCompanyWell{ IdWell = 6, IdCompany = 1},
new RelationCompanyWell{ IdWell = 7, IdCompany = 1},
new RelationCompanyWell{ IdWell = 8, IdCompany = 1},
new RelationCompanyWell{ IdWell = 9, IdCompany = 1},
entity.HasData(new List<Company>{
new Company{ Id = 1, Caption = "\"ООО\" АСБ", IdCompanyType = 3},
});
});
@ -265,6 +211,209 @@ namespace AsbCloudDb.Model
});
}
private static void FillDemoData(ModelBuilder modelBuilder)
{
modelBuilder.Entity<CompanyType>(entity =>
{
entity.HasData(new List<CompanyType>{
new CompanyType{ Id = 1, Caption = "Недрапользователь", },
new CompanyType{ Id = 2, Caption = "Буровой подрядчик", },
new CompanyType{ Id = 3, Caption = "Сервис автоматизации бурения", },
});
});
modelBuilder.Entity<Deposit>(entity =>
{
entity.HasData(new List<Deposit> {
new Deposit{Id = 1, Caption = "м/р 1", Latitude = 60.8705722222222, Longitude = 70.3811888888889 },
});
});
modelBuilder.Entity<Cluster>(entity =>
{
entity.HasData(new List<Cluster> {
new Cluster{Id = 1, Caption = "к39.1", IdDeposit = 1, Latitude = 60.8705722222222, Longitude = 70.3811888888889},
new Cluster{Id = 2, Caption = "к151", IdDeposit = 1, Latitude = 60.8205750000000, Longitude = 70.1343833333334},
new Cluster{Id = 3, Caption = "к611", IdDeposit = 1, Latitude = 60.8100666666667, Longitude = 69.7778388888889},
new Cluster{Id = 4, Caption = "к203", IdDeposit = 1, Latitude = 60.8928805555556, Longitude = 70.3272055555556},
new Cluster{Id = 5, Caption = "к221", IdDeposit = 1, Latitude = 60.6672055555556, Longitude = 69.6603861111111},
});
});
modelBuilder.Entity<Well>(entity =>
{
entity.HasData(new List<Well> {
new Well{Id = 1, IdCluster = 1, Caption = "скв 16314", Latitude = 60.8705722222222, Longitude = 70.3811888888889},
new Well{Id = 2, IdCluster = 1, Caption = "скв 16311", Latitude = 60.8705722222222, Longitude = 70.3811888888889},
new Well{Id = 3, IdCluster = 2, Caption = "скв 16315", Latitude = 60.8205750000000, Longitude = 70.1343833333334},
new Well{Id = 4, IdCluster = 2, Caption = "скв 16318", Latitude = 60.8205750000000, Longitude = 70.1343833333334},
new Well{Id = 5, IdCluster = 3, Caption = "скв 16310", Latitude = 60.8100666666667, Longitude = 69.7778388888889},
new Well{Id = 6, IdCluster = 4, Caption = "скв 16316", Latitude = 60.8928805555556, Longitude = 70.3272055555556},
new Well{Id = 7, IdCluster = 5, Caption = "скв 16312", Latitude = 60.6672055555556, Longitude = 69.6603861111111},
new Well{Id = 8, IdCluster = 5, Caption = "скв 16313", Latitude = 60.6672055555556, Longitude = 69.6603861111111},
new Well{Id = 9, IdCluster = 5, Caption = "скв 42669", Latitude = 60.6672055555556, Longitude = 69.6603861111111},
});
});
modelBuilder.Entity<Telemetry>(entity =>
{
entity.HasData(new List<Telemetry>{
new Telemetry{
Id = 1,
RemoteUid = "123",
Info = new TelemetryInfo
{
Well = "1",
Cluster = "1",
Comment = "",
Deposit = "1",
Customer = "1",
HmiVersion = "1",
PlcVersion = "1",
TimeZoneId = "1",
DrillingStartDate = DateTime.Parse("2021-06-29T12:01:19.000000"),
TimeZoneOffsetTotalHours = 5.0
},
}
});
});
modelBuilder.Entity<RelationCompanyWell>(entity => {
entity.HasData(new List<RelationCompanyWell> {
new RelationCompanyWell{ IdWell = 1, IdCompany = 1},
new RelationCompanyWell{ IdWell = 2, IdCompany = 1},
new RelationCompanyWell{ IdWell = 3, IdCompany = 1},
new RelationCompanyWell{ IdWell = 4, IdCompany = 1},
new RelationCompanyWell{ IdWell = 5, IdCompany = 1},
new RelationCompanyWell{ IdWell = 6, IdCompany = 1},
new RelationCompanyWell{ IdWell = 7, IdCompany = 1},
new RelationCompanyWell{ IdWell = 8, IdCompany = 1},
new RelationCompanyWell{ IdWell = 9, IdCompany = 1},
});
});
modelBuilder.Entity<TelemetryAnalysis>(entity =>
{
entity.HasData(new List<TelemetryAnalysis>{
new TelemetryAnalysis
{
Id = 1,
IdTelemetry = 1,
IdOperation = 17,
UnixDate = 1626870355,
DurationSec = 10,
OperationStartDepth = null,
OperationEndDepth = 206,
IsWellDepthIncreasing = false,
IsWellDepthDecreasing = false,
IsBitPositionIncreasing = false,
IsBitPositionDecreasing = false,
IsBitPositionLt20 = true,
IsBlockPositionIncreasing = false,
IsBlockPositionDecreasing = false,
IsRotorSpeedLt3 = true,
IsRotorSpeedGt3 = false,
IsPressureLt20 = true,
IsPressureGt20 = false,
IsHookWeightNotChanges = true,
IsHookWeightLt3 = true
},
new TelemetryAnalysis
{
Id = 2,
IdTelemetry = 1,
IdOperation = 8,
UnixDate = 1626870364,
DurationSec = 6,
OperationStartDepth = 206,
OperationEndDepth = 206,
IsWellDepthIncreasing = false,
IsWellDepthDecreasing = false,
IsBitPositionIncreasing = true,
IsBitPositionDecreasing = false,
IsBitPositionLt20 = true,
IsBlockPositionIncreasing = true,
IsBlockPositionDecreasing = false,
IsRotorSpeedLt3 = true,
IsRotorSpeedGt3 = false,
IsPressureLt20 = true,
IsPressureGt20 = false,
IsHookWeightNotChanges = true,
IsHookWeightLt3 = true
},
new TelemetryAnalysis
{
Id = 3,
IdTelemetry = 1,
IdOperation = 10,
UnixDate = 1626870370,
DurationSec = 2,
OperationStartDepth = null,
OperationEndDepth = 206,
IsWellDepthIncreasing = false,
IsWellDepthDecreasing = false,
IsBitPositionIncreasing = false,
IsBitPositionDecreasing = true,
IsBitPositionLt20 = true,
IsBlockPositionIncreasing = false,
IsBlockPositionDecreasing = true,
IsRotorSpeedLt3 = true,
IsRotorSpeedGt3 = false,
IsPressureLt20 = true,
IsPressureGt20 = false,
IsHookWeightNotChanges = true,
IsHookWeightLt3 = true
},
new TelemetryAnalysis
{
Id = 4,
IdTelemetry = 1,
IdOperation = 17,
UnixDate = 1626870372,
DurationSec = 7,
OperationStartDepth = 206,
OperationEndDepth = 206,
IsWellDepthIncreasing = false,
IsWellDepthDecreasing = false,
IsBitPositionIncreasing = false,
IsBitPositionDecreasing = false,
IsBitPositionLt20 = true,
IsBlockPositionIncreasing = false,
IsBlockPositionDecreasing = false,
IsRotorSpeedLt3 = true,
IsRotorSpeedGt3 = false,
IsPressureLt20 = true,
IsPressureGt20 = false,
IsHookWeightNotChanges = true,
IsHookWeightLt3 = true
},
new TelemetryAnalysis
{
Id = 5,
IdTelemetry = 1,
IdOperation = 8,
UnixDate = 1626870379,
DurationSec = 7,
OperationStartDepth = 206,
OperationEndDepth = 206,
IsWellDepthIncreasing = false,
IsWellDepthDecreasing = false,
IsBitPositionIncreasing = true,
IsBitPositionDecreasing = false,
IsBitPositionLt20 = true,
IsBlockPositionIncreasing = true,
IsBlockPositionDecreasing = false,
IsRotorSpeedLt3 = true,
IsRotorSpeedGt3 = false,
IsPressureLt20 = true,
IsPressureGt20 = false,
IsHookWeightNotChanges = true,
IsHookWeightLt3 = true
}
});
});
}
public IQueryable<Well> GetWellsForCompany(int idCompany)
{
return from well in Wells

View File

@ -36,7 +36,7 @@ namespace AsbCloudDb.Model
public long UnixDate { get; set; }
[Column("duration_sec"), Comment("Кол-во секунд после предыдущей операции")]
public int Duration { get; set; }
public int DurationSec { get; set; }
[Column("operation_start_depth"), Comment("Глубина, на которой началась операция")]
public double? OperationStartDepth { get; set; }
@ -57,7 +57,7 @@ namespace AsbCloudDb.Model
public bool IsBitPositionDecreasing { get; set; }
[Column("is_bit_posision_lt_20"), Comment("Положение долота меньше 20м")]
public bool IsBitDepthLess20 { get; set; }
public bool IsBitPositionLt20 { get; set; }
[Column("is_block_posision_incresing"), Comment("Талевый блок спускается")]
public bool IsBlockPositionIncreasing { get; set; }

View File

@ -116,7 +116,7 @@ namespace AsbCloudInfrastructure.Services
if (end != default)
{
var unixEnd = (end - new DateTime(1970, 1, 1)).TotalSeconds;
operations = operations.Where(m => (m.UnixDate + m.Duration) <= unixEnd);
operations = operations.Where(m => (m.UnixDate + m.DurationSec) <= unixEnd);
}
result.Count = operations.Count();
@ -136,7 +136,7 @@ namespace AsbCloudInfrastructure.Services
Id = operation.Id,
Name = operation.Operation.Name,
BeginDate = DateTimeOffset.FromUnixTimeSeconds(operation.UnixDate).DateTime,
EndDate = DateTimeOffset.FromUnixTimeSeconds(operation.UnixDate + operation.Duration).DateTime,
EndDate = DateTimeOffset.FromUnixTimeSeconds(operation.UnixDate + operation.DurationSec).DateTime,
StartWellDepth = operation.OperationStartDepth ?? 0.0,
EndWellDepth = operation.OperationEndDepth ?? 0.0
};
@ -166,8 +166,8 @@ namespace AsbCloudInfrastructure.Services
select new OperationDurationDto
{
OperationName = g.Key.Name,
Duration = g.Where(g => g.Duration > 0)
.Sum(a => a.Duration)
Duration = g.Where(g => g.DurationSec > 0)
.Sum(a => a.DurationSec)
}).ToList();
return operations;
@ -198,7 +198,7 @@ namespace AsbCloudInfrastructure.Services
{
IntervalStart = g.Min(d => d.UnixDate),
OperationName = g.Key.Name,
OperationsDuration = g.Sum(an => an.Duration)
OperationsDuration = g.Sum(an => an.DurationSec)
}).ToList();
var operationsGroupedByInterval = operations.GroupBy(op => op.IntervalStart)
@ -232,8 +232,8 @@ namespace AsbCloudInfrastructure.Services
if (saubDataCache.CurrentAnalysis.IdOperation == telemetryAnalysis.IdOperation)
{
saubDataCache.CurrentAnalysis.Duration +=
telemetryAnalysis.Duration;
saubDataCache.CurrentAnalysis.DurationSec +=
telemetryAnalysis.DurationSec;
saubDataCache.CurrentAnalysis.OperationEndDepth = dataSaub.WellDepth;
}
else
@ -283,14 +283,14 @@ namespace AsbCloudInfrastructure.Services
{
IdTelemetry = dataSaubBases.First().IdTelemetry,
UnixDate = (long)(lastSaubDate - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds,
Duration = (int)(dataSaubBases.Last().Date - dataSaubBases.ElementAt(dataSaubBases.Count() - 2).Date).TotalSeconds,
DurationSec = (int)(dataSaubBases.Last().Date - dataSaubBases.ElementAt(dataSaubBases.Count() - 2).Date).TotalSeconds,
OperationStartDepth = null,
OperationEndDepth = null,
IsWellDepthDecreasing = InterpolationLine.IsValueDecreases(wellDepthChangingIndex, -0.0001),
IsWellDepthIncreasing = InterpolationLine.IsValueIncreases(wellDepthChangingIndex, 0.0001),
IsBitPositionDecreasing = InterpolationLine.IsValueDecreases(bitPositionChangingIndex, -0.0001),
IsBitPositionIncreasing = InterpolationLine.IsValueIncreases(bitPositionChangingIndex, 0.0001),
IsBitDepthLess20 = InterpolationLine.IsAverageLessThanBound(saubBitDepths, 20),
IsBitPositionLt20 = InterpolationLine.IsAverageLessThanBound(saubBitDepths, 20),
IsBlockPositionDecreasing = InterpolationLine.IsValueDecreases(blockPositionChangingIndex, -0.0001),
IsBlockPositionIncreasing = InterpolationLine.IsValueIncreases(blockPositionChangingIndex, 0.0001),
IsRotorSpeedLt3 = InterpolationLine.IsAverageLessThanBound(saubRotorSpeeds, 3),

View File

@ -19,7 +19,7 @@ namespace AsbCloudInfrastructure.Services
Detect = (data) =>
{
return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing
&& data.IsBitDepthLess20 && data.IsHookWeightLt3;
&& data.IsBitPositionLt20 && data.IsHookWeightLt3;
}
},
new OperationDetector