diff --git a/AsbCloudDb/Model/AsbCloudDbContext.cs b/AsbCloudDb/Model/AsbCloudDbContext.cs index 2055d509..e8c5e104 100644 --- a/AsbCloudDb/Model/AsbCloudDbContext.cs +++ b/AsbCloudDb/Model/AsbCloudDbContext.cs @@ -113,29 +113,6 @@ namespace AsbCloudDb.Model .HasConstraintName("t_event_t_telemetry_id_fk"); }); - modelBuilder.Entity(entity => - { - entity.HasData(new List{ - new UserRole{ Id = 1, Caption = "Администратор", }, - }); - }); - - modelBuilder.Entity(entity => - { - entity.HasData(new List{ - new CompanyType{ Id = 1, Caption = "Недрапользователь", }, - new CompanyType{ Id = 2, Caption = "Буровой подрядчик", }, - new CompanyType{ Id = 3, Caption = "Сервис автоматизации бурения", }, - }); - }); - - modelBuilder.Entity(entity => - { - entity.HasData(new List{ - new Company{ Id = 1, Caption = "\"ООО\" АСБ", IdCompanyType = 3}, - }); - }); - modelBuilder.Entity(entity => { entity.HasOne(d => d.Company) @@ -145,18 +122,6 @@ namespace AsbCloudDb.Model entity.HasIndex(d => d.Login) .IsUnique(); - - entity.HasData(new List{ - new User{ - Id = 1, - IdCompany = 1, - IdRole = 1, - Level = int.MaxValue, - Login = "dev", - PasswordHash = "Vlcj|4fa529103dde7ff72cfe76185f344d4aa87931f8e1b2044e8a7739947c3d18923464eaad93843e4f809c5e126d013072", // dev - Name = "Разработчик", - }, - }); }); modelBuilder.Entity(entity => @@ -170,8 +135,6 @@ namespace AsbCloudDb.Model .WithOne(p => p.Well) .HasForeignKey(d => d.IdTelemetry) .HasConstraintName("t_well_t_telemetry_id_fk"); - - }); modelBuilder.Entity(entity => { @@ -190,54 +153,37 @@ namespace AsbCloudDb.Model }); FillData(modelBuilder); + FillDemoData(modelBuilder); } private static void FillData(ModelBuilder modelBuilder) { - modelBuilder.Entity(entity => + modelBuilder.Entity(entity => { - entity.HasData(new List { - new Deposit{Id = 1, Caption = "м/р 1", Latitude = 60.8705722222222, Longitude = 70.3811888888889 }, + entity.HasData(new List{ + new UserRole{ Id = 1, Caption = "Администратор", }, }); }); - modelBuilder.Entity(entity => + modelBuilder.Entity(entity => { - entity.HasData(new List { - 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{ + new User{ + Id = 1, + IdCompany = 1, + IdRole = 1, + Level = int.MaxValue, + Login = "dev", + PasswordHash = "Vlcj|4fa529103dde7ff72cfe76185f344d4aa87931f8e1b2044e8a7739947c3d18923464eaad93843e4f809c5e126d013072", // dev + Name = "Разработчик", + }, }); }); - modelBuilder.Entity(entity => + modelBuilder.Entity(entity => { - entity.HasData(new List { - 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(entity => { - entity.HasData(new List { - 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{ + new Company{ Id = 1, Caption = "\"ООО\" АСБ", IdCompanyType = 3}, }); }); @@ -265,6 +211,209 @@ namespace AsbCloudDb.Model }); } + private static void FillDemoData(ModelBuilder modelBuilder) + { + modelBuilder.Entity(entity => + { + entity.HasData(new List{ + new CompanyType{ Id = 1, Caption = "Недрапользователь", }, + new CompanyType{ Id = 2, Caption = "Буровой подрядчик", }, + new CompanyType{ Id = 3, Caption = "Сервис автоматизации бурения", }, + }); + }); + + modelBuilder.Entity(entity => + { + entity.HasData(new List { + new Deposit{Id = 1, Caption = "м/р 1", Latitude = 60.8705722222222, Longitude = 70.3811888888889 }, + }); + }); + + modelBuilder.Entity(entity => + { + entity.HasData(new List { + 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(entity => + { + entity.HasData(new List { + 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(entity => + { + entity.HasData(new List{ + 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(entity => { + entity.HasData(new List { + 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(entity => + { + entity.HasData(new List{ + 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 GetWellsForCompany(int idCompany) { return from well in Wells diff --git a/AsbCloudDb/Model/TelemetryAnalysis.cs b/AsbCloudDb/Model/TelemetryAnalysis.cs index 114c6b16..2ef09d85 100644 --- a/AsbCloudDb/Model/TelemetryAnalysis.cs +++ b/AsbCloudDb/Model/TelemetryAnalysis.cs @@ -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; } diff --git a/AsbCloudInfrastructure/Services/AnalyticsService.cs b/AsbCloudInfrastructure/Services/AnalyticsService.cs index 9e81e0fd..31b2e601 100644 --- a/AsbCloudInfrastructure/Services/AnalyticsService.cs +++ b/AsbCloudInfrastructure/Services/AnalyticsService.cs @@ -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), diff --git a/AsbCloudInfrastructure/Services/OperationDetectorService.cs b/AsbCloudInfrastructure/Services/OperationDetectorService.cs index b1d5a8d2..4940c0e2 100644 --- a/AsbCloudInfrastructure/Services/OperationDetectorService.cs +++ b/AsbCloudInfrastructure/Services/OperationDetectorService.cs @@ -19,7 +19,7 @@ namespace AsbCloudInfrastructure.Services Detect = (data) => { return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing - && data.IsBitDepthLess20 && data.IsHookWeightLt3; + && data.IsBitPositionLt20 && data.IsHookWeightLt3; } }, new OperationDetector