From e3c4b262d9d9fbd32e4cb3b4b1df580376d3e367 Mon Sep 17 00:00:00 2001 From: KharchenkoVV Date: Mon, 19 Jul 2021 15:31:50 +0500 Subject: [PATCH] =?UTF-8?q?CS2-29:=20=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=B8=D0=BC=D1=8F=20=D0=B8=20=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D0=B8=20DrillingAnalysi?= =?UTF-8?q?s=20(=D0=BD=D0=B0=20TelemetryAnalysis)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Data/OperationInfoDto.cs | 2 +- AsbCloudApp/Services/IAnalyticsService.cs | 2 +- AsbCloudDb/Model/AsbCloudDbContext.cs | 4 +- AsbCloudDb/Model/DrillingAnalysis.cs | 88 ------------------- AsbCloudDb/Model/IAsbCloudDbContext.cs | 2 +- AsbCloudDb/Model/Operation.cs | 4 +- AsbCloudDb/Model/Telemetry.cs | 4 +- AsbCloudDb/Model/TelemetryAnalysis.cs | 83 +++++++++++++++++ AsbCloudInfrastructure/DependencyInjection.cs | 1 + .../Services/AnalyticsService.cs | 79 +++++------------ .../Services/DataService.cs | 2 +- .../Services/LinearFunctionCalculator.cs | 8 +- .../Services/OperationDetector.cs | 2 +- .../Services/OperationDetectorService.cs | 75 ++++++++++------ .../Services/СlusterService.cs | 4 +- .../AnalyticsControllerTests.cs | 4 +- .../Controllers/ClusterController.cs | 2 +- 17 files changed, 173 insertions(+), 193 deletions(-) delete mode 100644 AsbCloudDb/Model/DrillingAnalysis.cs create mode 100644 AsbCloudDb/Model/TelemetryAnalysis.cs diff --git a/AsbCloudApp/Data/OperationInfoDto.cs b/AsbCloudApp/Data/OperationInfoDto.cs index fcc3bc08..b7a1bdcd 100644 --- a/AsbCloudApp/Data/OperationInfoDto.cs +++ b/AsbCloudApp/Data/OperationInfoDto.cs @@ -5,7 +5,7 @@ namespace AsbCloudApp.Data { public class OperationInfoDto { - public DateTime IntervalBegin { get; set; } + public DateTimeOffset IntervalBegin { get; set; } public IEnumerable Operations { get; set; } } } diff --git a/AsbCloudApp/Services/IAnalyticsService.cs b/AsbCloudApp/Services/IAnalyticsService.cs index 9a8aea55..06d24be1 100644 --- a/AsbCloudApp/Services/IAnalyticsService.cs +++ b/AsbCloudApp/Services/IAnalyticsService.cs @@ -14,6 +14,6 @@ namespace AsbCloudApp.Services DateTime begin = default, DateTime end = default); IEnumerable GetOperationsToInterval(int wellId, int intervalHoursTimestamp, int workBeginTimestamp); - DrillingAnalysis GetDrillingAnalysis(IEnumerable dataSaubBases); + TelemetryAnalysis GetDrillingAnalysis(IEnumerable dataSaubBases); } } diff --git a/AsbCloudDb/Model/AsbCloudDbContext.cs b/AsbCloudDb/Model/AsbCloudDbContext.cs index 69175f00..1c3b9d20 100644 --- a/AsbCloudDb/Model/AsbCloudDbContext.cs +++ b/AsbCloudDb/Model/AsbCloudDbContext.cs @@ -26,7 +26,7 @@ namespace AsbCloudDb.Model public virtual DbSet Wells { get; set; } public virtual DbSet Reports { get; set; } public virtual DbSet Operations { get; set; } - public virtual DbSet DrillingAnalysis { get; set; } + public virtual DbSet TelemetryAnalysis { get; set; } //public AsbCloudDbContext(string connectionString = "Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True") //{ @@ -88,7 +88,7 @@ namespace AsbCloudDb.Model .HasConstraintName("t_telemetry_user_t_telemetry_id_fk"); }); - modelBuilder.Entity(entity => + modelBuilder.Entity(entity => { entity.HasOne(d => d.Telemetry) .WithMany(p => p.Analysis) diff --git a/AsbCloudDb/Model/DrillingAnalysis.cs b/AsbCloudDb/Model/DrillingAnalysis.cs deleted file mode 100644 index 1b4ca234..00000000 --- a/AsbCloudDb/Model/DrillingAnalysis.cs +++ /dev/null @@ -1,88 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; -using System.Text.Json.Serialization; - -namespace AsbCloudDb.Model -{ - - [Table("t_analysis"), Comment("События на скважине")] - public class DrillingAnalysis - { - [Key] - [Column("id")] - public int Id { get; set; } - - [Column("id_telemetry")] - public int IdTelemetry { get; set; } - - [Column("date", TypeName = "timestamp with time zone"), Comment("'2021-10-19 18:23:54+05'")] - public DateTime Date { get; set; } - - [Column("unix_date", TypeName = "bigint"), Comment("Unix timestamp для Linq запросов с вычислением дат")] - public long UnixDate { get; set; } - - [Column("duration"), Comment("Кол-во секунд после предыдущей операции")] - public int Duration { get; set; } - - [Column("id_operation")] - public int? IdOperation { get; set; } - - - [JsonIgnore] - [ForeignKey(nameof(IdTelemetry))] - [InverseProperty(nameof(Model.Telemetry.Analysis))] - public virtual Telemetry Telemetry { get; set; } - - [JsonIgnore] - [ForeignKey(nameof(IdOperation))] - [InverseProperty(nameof(Model.Operation.Analysis))] - public virtual Operation Operation { get; set; } - - [Column("depth_changes"), Comment("Глубина забоя увеличивается")] - public bool IsDepthChanges { get; set; } - - [Column("depth_not_changes"), Comment("Глубина забоя не увеличивается")] - public bool IsDepthNotChanges { get; set; } - - [Column("bit_is_rising"), Comment("Долото поднимается")] - public bool IsBitRising { get; set; } - - [Column("bit_goes_down"), Comment("Глубина спускается")] - public bool IsBitGoesDown { get; set; } - - [Column("bit_stands_still"), Comment("Положение долота не изменяется")] - public bool IsBitStandsStill { get; set; } - - [Column("bit_depth_less_20"), Comment("Положение долота меньше 20м")] - public bool IsBitDepthLess20 { get; set; } - - [Column("block_is_rising"), Comment("Талевый блок поднимается")] - public bool IsBlockRising { get; set; } - - [Column("block_goes_down"), Comment("Талевый блок спускается")] - public bool IsBlockGoesDown { get; set; } - - [Column("block_stands_still"), Comment("Положение блок не изменяется")] - public bool IsBlockStandsStill { get; set; } - - [Column("rotor_speed_less_3"), Comment("Обороты ротора ниже 3")] - public bool IsRotorSpeedLess3 { get; set; } - - [Column("rotor_speed_more_3"), Comment("Обороты ротора выше 3")] - public bool IsRotorSpeedMore3 { get; set; } - - [Column("pressure_less_20"), Comment("Давление менее 20")] - public bool IsPressureLess20 { get; set; } - - [Column("pressure_more_20"), Comment("Давоение более 20")] - public bool IsPressureMore20 { get; set; } - - [Column("hook_weight_not_changes"), Comment("Вес на крюке не меняется")] - public bool IsHookWeightNotChanges { get; set; } - - [Column("hook_weight_less_3"), Comment("Вес на крюке менее 3т")] - public bool IsHookWeightLess3 { get; set; } - } -} diff --git a/AsbCloudDb/Model/IAsbCloudDbContext.cs b/AsbCloudDb/Model/IAsbCloudDbContext.cs index 9b5958a0..c429966e 100644 --- a/AsbCloudDb/Model/IAsbCloudDbContext.cs +++ b/AsbCloudDb/Model/IAsbCloudDbContext.cs @@ -22,7 +22,7 @@ namespace AsbCloudDb.Model DbSet UserRoles { get; set; } DbSet Reports { get; set; } DbSet Operations { get; set; } - DbSet DrillingAnalysis { get; set; } + DbSet TelemetryAnalysis { get; set; } int SaveChanges(); int SaveChanges(bool acceptAllChangesOnSuccess); diff --git a/AsbCloudDb/Model/Operation.cs b/AsbCloudDb/Model/Operation.cs index 02a7a78e..7fb6aff9 100644 --- a/AsbCloudDb/Model/Operation.cs +++ b/AsbCloudDb/Model/Operation.cs @@ -14,7 +14,7 @@ namespace AsbCloudDb.Model [Column("name"), Comment("Название операции")] public string Name { get; set; } - [InverseProperty(nameof(DrillingAnalysis.Operation))] - public virtual ICollection Analysis { get; set; } + [InverseProperty(nameof(TelemetryAnalysis.Operation))] + public virtual ICollection Analysis { get; set; } } } diff --git a/AsbCloudDb/Model/Telemetry.cs b/AsbCloudDb/Model/Telemetry.cs index e1bfb43d..59759f56 100644 --- a/AsbCloudDb/Model/Telemetry.cs +++ b/AsbCloudDb/Model/Telemetry.cs @@ -43,7 +43,7 @@ namespace AsbCloudDb.Model [InverseProperty(nameof(Event.Telemetry))] public virtual ICollection Events { get; set; } - [InverseProperty(nameof(DrillingAnalysis.Telemetry))] - public virtual ICollection Analysis { get; set; } + [InverseProperty(nameof(TelemetryAnalysis.Telemetry))] + public virtual ICollection Analysis { get; set; } } } diff --git a/AsbCloudDb/Model/TelemetryAnalysis.cs b/AsbCloudDb/Model/TelemetryAnalysis.cs new file mode 100644 index 00000000..add26302 --- /dev/null +++ b/AsbCloudDb/Model/TelemetryAnalysis.cs @@ -0,0 +1,83 @@ +using Microsoft.EntityFrameworkCore; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Text.Json.Serialization; + +namespace AsbCloudDb.Model +{ + + [Table("t_telemetry_analysis"), Comment("События на скважине")] + public class TelemetryAnalysis + { + [Key] + [Column("id")] + public int Id { get; set; } + + [Column("id_telemetry")] + public int IdTelemetry { get; set; } + + [Column("id_operation")] + public int? IdOperation { get; set; } + + + + [JsonIgnore] + [ForeignKey(nameof(IdTelemetry))] + [InverseProperty(nameof(Model.Telemetry.Analysis))] + public virtual Telemetry Telemetry { get; set; } + + [JsonIgnore] + [ForeignKey(nameof(IdOperation))] + [InverseProperty(nameof(Model.Operation.Analysis))] + public virtual Operation Operation { get; set; } + + + [Column("unix_date", TypeName = "bigint"), Comment("Unix timestamp для Linq запросов с вычислением дат")] + public long UnixDate { get; set; } + + [Column("duration_sec"), Comment("Кол-во секунд после предыдущей операции")] + public int Duration { get; set; } + + [Column("well_depth"), Comment("Глубина, на которой закончилась операция")] + public double WellDepth { get; set; } + + [Column("is_well_depth_increasing"), Comment("Глубина забоя увеличивается")] + public bool IsWellDepthIncreasing { get; set; } + + [Column("is_well_depth_decreasing"), Comment("Глубина забоя не увеличивается")] + public bool IsWellDepthDecreasing { get; set; } + + [Column("is_bit_position_increasing"), Comment("Долото спускается")] + public bool IsBitPositionIncreasing { get; set; } + + [Column("is_bit_position_decreasing"), Comment("Долото поднимается")] + public bool IsBitPositionDecreasing { get; set; } + + [Column("is_bit_posision_lt_20"), Comment("Положение долота меньше 20м")] + public bool IsBitDepthLess20 { get; set; } + + [Column("is_block_posision_incresing"), Comment("Талевый блок спускается")] + public bool IsBlockPositionIncreasing { get; set; } + + [Column("is_block_posision_decresing"), Comment("Талевый блок поднимается")] + public bool IsBlockPositionDecreasing { get; set; } + + [Column("is_rotor_speed_lt_3"), Comment("Обороты ротора ниже 3")] + public bool IsRotorSpeedLt3 { get; set; } + + [Column("is_rotor_speed_gt_3"), Comment("Обороты ротора выше 3")] + public bool IsRotorSpeedGt3 { get; set; } + + [Column("is_pressure_lt_20"), Comment("Давление менее 20")] + public bool IsPressureLt20 { get; set; } + + [Column("is_pressure_gt_20"), Comment("Давоение более 20")] + public bool IsPressureGt20 { get; set; } + + [Column("is_hook_weight_not_changes"), Comment("Вес на крюке не меняется")] + public bool IsHookWeightNotChanges { get; set; } + + [Column("is_hook_weight_lt_3"), Comment("Вес на крюке менее 3т")] + public bool IsHookWeightLt3 { get; set; } + } +} diff --git a/AsbCloudInfrastructure/DependencyInjection.cs b/AsbCloudInfrastructure/DependencyInjection.cs index 3095e222..5d820b15 100644 --- a/AsbCloudInfrastructure/DependencyInjection.cs +++ b/AsbCloudInfrastructure/DependencyInjection.cs @@ -29,6 +29,7 @@ namespace AsbCloudInfrastructure services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/AsbCloudInfrastructure/Services/AnalyticsService.cs b/AsbCloudInfrastructure/Services/AnalyticsService.cs index fca59dfa..31c78098 100644 --- a/AsbCloudInfrastructure/Services/AnalyticsService.cs +++ b/AsbCloudInfrastructure/Services/AnalyticsService.cs @@ -79,7 +79,7 @@ namespace AsbCloudInfrastructure.Services return wellDepthToIntervalData; } - public IEnumerable GetOperationsSummary(int wellId, + public IEnumerable GetOperationsSummary(int wellId, DateTime begin = default, DateTime end = default) { var telemetry = telemetryService.GetTelemetryByWellId(wellId); @@ -87,9 +87,12 @@ namespace AsbCloudInfrastructure.Services if (telemetry is null) return null; - var operations = (from a in db.DrillingAnalysis + var unixBegin = (begin - new DateTime(1970, 1, 1)).TotalSeconds; + var unixEnd = (end - new DateTime(1970, 1, 1)).TotalSeconds; + + var operations = (from a in db.TelemetryAnalysis where a.IdTelemetry == telemetry.Id && - a.Date > begin && a.Date < end && + a.UnixDate > unixBegin && a.UnixDate < unixEnd && a.IdOperation != null join o in db.Operations on a.IdOperation equals o.Id group a by new { a.IdOperation, o.Name } into g @@ -115,7 +118,7 @@ namespace AsbCloudInfrastructure.Services var timezoneOffset = telemetryService.GetTimezoneOffsetByTelemetryId(telemetry.Id); - var operations = (from a in db.DrillingAnalysis + var operations = (from a in db.TelemetryAnalysis where a.IdTelemetry == telemetry.Id && a.IdOperation != null join o in db.Operations on a.IdOperation equals o.Id @@ -125,14 +128,14 @@ namespace AsbCloudInfrastructure.Services o.Name } into g select new { - IntervalStart = g.Min(d => d.Date).Date, + IntervalStart = g.Min(d => d.UnixDate), OperationName = g.Key.Name, OperationsDuration = g.Sum(an => an.Duration) }).ToList(); var operationsGroupedByInterval = operations.GroupBy(op => op.IntervalStart) .Select(o => new OperationInfoDto { - IntervalBegin = o.Key, + IntervalBegin = DateTimeOffset.FromUnixTimeSeconds(o.Key), Operations = o.Select(opr => new OperationDetailsDto { OperationName = opr.OperationName, Duration = opr.OperationsDuration @@ -143,7 +146,7 @@ namespace AsbCloudInfrastructure.Services return operationsGroupedByInterval; } - public DrillingAnalysis GetDrillingAnalysis(IEnumerable dataSaubBases) + public TelemetryAnalysis GetDrillingAnalysis(IEnumerable dataSaubBases) { var lastSaubDate = dataSaubBases.Last().Date; @@ -177,27 +180,25 @@ namespace AsbCloudInfrastructure.Services var IsBlockGoesDown = LinearFunctionCalculator.IsValueGoesUp(blockPositionChangingIndex, 0.0001); var IsBlockStandsStill = LinearFunctionCalculator.IsValueNotChanges(blockPositionChangingIndex, (0.0001, -0.0001)); - var drillingAnalysis = new DrillingAnalysis + var drillingAnalysis = new TelemetryAnalysis { IdTelemetry = dataSaubBases.First().IdTelemetry, - Date = lastSaubDate, - UnixDate = (long)(lastSaubDate - new DateTime(1970,1,1,0,0,0)).TotalSeconds, + UnixDate = (long)(lastSaubDate - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds, Duration = (int)(dataSaubBases.Last().Date - dataSaubBases.ElementAt(dataSaubBases.Count() - 2).Date).TotalSeconds, - IsDepthChanges = LinearFunctionCalculator.IsValueChanges(wellDepthChangingIndex, (0.0001, -0.0001)), - IsDepthNotChanges = LinearFunctionCalculator.IsValueNotChanges(wellDepthChangingIndex, (0.0001, -0.0001)), - IsBitRising = LinearFunctionCalculator.IsValueGoesDown(bitPositionChangingIndex, -0.0001), - IsBitGoesDown = LinearFunctionCalculator.IsValueGoesUp(bitPositionChangingIndex, 0.0001), - IsBitStandsStill = LinearFunctionCalculator.IsValueNotChanges(bitPositionChangingIndex, (0.0001, -0.0001)), + WellDepth = (double)dataSaubBases.Last().WellDepth, + IsWellDepthDecreasing = LinearFunctionCalculator.IsValueGoesDown(wellDepthChangingIndex, -0.0001), + IsWellDepthIncreasing = LinearFunctionCalculator.IsValueGoesUp(wellDepthChangingIndex, 0.0001), + IsBitPositionDecreasing = LinearFunctionCalculator.IsValueGoesDown(bitPositionChangingIndex, -0.0001), + IsBitPositionIncreasing = LinearFunctionCalculator.IsValueGoesUp(bitPositionChangingIndex, 0.0001), IsBitDepthLess20 = LinearFunctionCalculator.IsAverageLessThanBound(saubBitDepths, 20), - IsBlockRising = LinearFunctionCalculator.IsValueGoesDown(blockPositionChangingIndex, -0.0001), - IsBlockGoesDown = LinearFunctionCalculator.IsValueGoesUp(blockPositionChangingIndex, 0.0001), - IsBlockStandsStill = LinearFunctionCalculator.IsValueNotChanges(blockPositionChangingIndex, (0.0001, -0.0001)), - IsRotorSpeedLess3 = LinearFunctionCalculator.IsAverageLessThanBound(saubRotorSpeeds, 3), - IsRotorSpeedMore3 = LinearFunctionCalculator.IsAverageMoreThanBound(saubRotorSpeeds, 3), - IsPressureLess20 = LinearFunctionCalculator.IsAverageLessThanBound(saubPressures, 20), - IsPressureMore20 = LinearFunctionCalculator.IsAverageMoreThanBound(saubPressures, 20), + IsBlockPositionDecreasing = LinearFunctionCalculator.IsValueGoesDown(blockPositionChangingIndex, -0.0001), + IsBlockPositionIncreasing = LinearFunctionCalculator.IsValueGoesUp(blockPositionChangingIndex, 0.0001), + IsRotorSpeedLt3 = LinearFunctionCalculator.IsAverageLessThanBound(saubRotorSpeeds, 3), + IsRotorSpeedGt3 = LinearFunctionCalculator.IsAverageMoreThanBound(saubRotorSpeeds, 3), + IsPressureLt20 = LinearFunctionCalculator.IsAverageLessThanBound(saubPressures, 20), + IsPressureGt20 = LinearFunctionCalculator.IsAverageMoreThanBound(saubPressures, 20), IsHookWeightNotChanges = LinearFunctionCalculator.IsValueNotChanges(hookWeightChangingIndex, (0.0001, -0.0001)), - IsHookWeightLess3 = LinearFunctionCalculator.IsAverageLessThanBound(saubHookWeights, 3), + IsHookWeightLt3 = LinearFunctionCalculator.IsAverageLessThanBound(saubHookWeights, 3), IdOperation = 1 }; @@ -205,37 +206,5 @@ namespace AsbCloudInfrastructure.Services return drillingAnalysis; } - - private static double GetAForLinearFormula(IEnumerable<(double?, double)> rawData) - { - var (xSum, ySum, xySum, x2Sum) = GetFormulaVariables(rawData); - - return (xSum * ySum - rawData.Count() * xySum) / - (xSum * xSum - rawData.Count() * x2Sum); - } - - private static double GetBForLinearFormula(IEnumerable<(double?, double)> rawData) - { - var (xSum, ySum, xySum, x2Sum) = GetFormulaVariables(rawData); - - return (xSum * xySum - x2Sum * ySum) / - (xSum * xSum - rawData.Count() * x2Sum); - } - - private static (double xSum, double ySum, double xySum, double x2Sum) GetFormulaVariables( - IEnumerable<(double? value, double timestamp)> rawData) - { - var data = rawData.Select((d) => new - { - X = d.timestamp, - Y = d.value ?? 0.0 - }); - var xSum = data.Sum(d => d.X); - var ySum = data.Sum(d => d.Y); - var xySum = data.Sum(d => d.X * d.Y); - var x2Sum = data.Sum(d => d.X * d.X); - - return (xSum, ySum, xySum, x2Sum); - } } } diff --git a/AsbCloudInfrastructure/Services/DataService.cs b/AsbCloudInfrastructure/Services/DataService.cs index 43c0c52b..c24f3a00 100644 --- a/AsbCloudInfrastructure/Services/DataService.cs +++ b/AsbCloudInfrastructure/Services/DataService.cs @@ -108,7 +108,7 @@ namespace AsbCloudInfrastructure.Services var drillingAnalysis = analyticsService.GetDrillingAnalysis(dataSaubs); - db.DrillingAnalysis.Add(drillingAnalysis); + db.TelemetryAnalysis.Add(drillingAnalysis); } } diff --git a/AsbCloudInfrastructure/Services/LinearFunctionCalculator.cs b/AsbCloudInfrastructure/Services/LinearFunctionCalculator.cs index 5f905b67..05b0a0c6 100644 --- a/AsbCloudInfrastructure/Services/LinearFunctionCalculator.cs +++ b/AsbCloudInfrastructure/Services/LinearFunctionCalculator.cs @@ -25,19 +25,15 @@ namespace AsbCloudInfrastructure.Services return (double)result; } - public static bool IsValueChanges(double value, - (double upperBound, double lowerBound) bounds) => - value >= bounds.upperBound || value <= bounds.lowerBound; - public static bool IsValueNotChanges(double value, (double upperBound, double lowerBound) bounds) => value < bounds.upperBound && value > bounds.lowerBound; public static bool IsValueGoesUp(double value, double bound) => - value >= bound; + value > bound; public static bool IsValueGoesDown(double value, double bound) => - value <= bound; + value < bound; public static bool IsAverageLessThanBound(IEnumerable<(double Value, double TotalSeconds)> values, double bound) => diff --git a/AsbCloudInfrastructure/Services/OperationDetector.cs b/AsbCloudInfrastructure/Services/OperationDetector.cs index 0f15c484..fbcec8e6 100644 --- a/AsbCloudInfrastructure/Services/OperationDetector.cs +++ b/AsbCloudInfrastructure/Services/OperationDetector.cs @@ -7,6 +7,6 @@ namespace AsbCloudInfrastructure.Services { public int Order { get; set; } public Operation Operation { get; set; } - public Func Detect { get; set; } + public Func Detect { get; set; } } } diff --git a/AsbCloudInfrastructure/Services/OperationDetectorService.cs b/AsbCloudInfrastructure/Services/OperationDetectorService.cs index f9d72218..96555fa8 100644 --- a/AsbCloudInfrastructure/Services/OperationDetectorService.cs +++ b/AsbCloudInfrastructure/Services/OperationDetectorService.cs @@ -18,7 +18,8 @@ namespace AsbCloudInfrastructure.Services Operation = operations.FirstOrDefault(o => o.Name.Equals("На поверхности")), Detect = (data) => { - return data.IsDepthNotChanges && data.IsBitDepthLess20 && data.IsHookWeightLess3; + return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing + && data.IsBitDepthLess20 && data.IsHookWeightLt3; } }, new OperationDetector @@ -27,8 +28,10 @@ namespace AsbCloudInfrastructure.Services Operation = operations.FirstOrDefault(o => o.Name.Equals("Удержание в клиньях")), Detect = (data) => { - return data.IsDepthNotChanges && data.IsBitStandsStill && - data.IsBlockStandsStill && data.IsHookWeightLess3; + return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing && + !data.IsBitPositionIncreasing && !data.IsBitPositionDecreasing && + data.IsBlockPositionDecreasing && !data.IsBlockPositionIncreasing && + data.IsHookWeightLt3; } }, new OperationDetector @@ -37,8 +40,9 @@ namespace AsbCloudInfrastructure.Services Operation = operations.FirstOrDefault(o => o.Name.Equals("Подъем с проработкой")), Detect = (data) => { - return data.IsDepthNotChanges && data.IsBitRising && - data.IsBlockRising && data.IsRotorSpeedMore3 && data.IsPressureMore20; + return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing && + data.IsBitPositionDecreasing && data.IsBlockPositionDecreasing && + data.IsRotorSpeedGt3 && data.IsPressureGt20; } }, new OperationDetector @@ -47,8 +51,9 @@ namespace AsbCloudInfrastructure.Services Operation = operations.FirstOrDefault(o => o.Name.Equals("Спуск с проработкой")), Detect = (data) => { - return data.IsDepthNotChanges && data.IsBitGoesDown && - data.IsBlockGoesDown && data.IsRotorSpeedMore3 && data.IsPressureMore20; + return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing && + data.IsBitPositionIncreasing && data.IsBitPositionIncreasing && + data.IsRotorSpeedGt3 && data.IsPressureGt20; } }, new OperationDetector @@ -57,8 +62,9 @@ namespace AsbCloudInfrastructure.Services Operation = operations.FirstOrDefault(o => o.Name.Equals("Подъем с промывкой")), Detect = (data) => { - return data.IsDepthNotChanges && data.IsBitRising && - data.IsBlockRising && data.IsRotorSpeedLess3 && data.IsPressureMore20; + return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing && + data.IsBitPositionDecreasing && data.IsBitPositionDecreasing && + data.IsRotorSpeedLt3 && data.IsPressureGt20; } }, new OperationDetector @@ -67,8 +73,9 @@ namespace AsbCloudInfrastructure.Services Operation = operations.FirstOrDefault(o => o.Name.Equals("Спуск с промывкой")), Detect = (data) => { - return data.IsDepthNotChanges && data.IsBitGoesDown && - data.IsBlockGoesDown && data.IsRotorSpeedLess3 && data.IsPressureMore20; + return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing && + data.IsBitPositionIncreasing && data.IsBlockPositionIncreasing && + data.IsRotorSpeedLt3 && data.IsPressureGt20; } }, new OperationDetector @@ -77,8 +84,9 @@ namespace AsbCloudInfrastructure.Services Operation = operations.FirstOrDefault(o => o.Name.Equals("Спуск в скважину")), Detect = (data) => { - return data.IsDepthNotChanges && data.IsBitGoesDown && - data.IsBlockGoesDown && data.IsRotorSpeedLess3 && data.IsPressureLess20; + return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing && + data.IsBitPositionIncreasing && data.IsBlockPositionIncreasing && + data.IsRotorSpeedLt3 && data.IsPressureLt20; } }, new OperationDetector @@ -87,8 +95,9 @@ namespace AsbCloudInfrastructure.Services Operation = operations.FirstOrDefault(o => o.Name.Equals("Спуск с вращением")), Detect = (data) => { - return data.IsDepthNotChanges && data.IsBitGoesDown && - data.IsBlockGoesDown && data.IsRotorSpeedMore3 && data.IsPressureLess20; + return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing && + data.IsBitPositionIncreasing && data.IsBlockPositionIncreasing && + data.IsRotorSpeedGt3 && data.IsPressureLt20; } }, new OperationDetector @@ -97,8 +106,9 @@ namespace AsbCloudInfrastructure.Services Operation = operations.FirstOrDefault(o => o.Name.Equals("Подъем из скважины")), Detect = (data) => { - return data.IsDepthNotChanges && data.IsBitRising && - data.IsBlockRising && data.IsRotorSpeedLess3 && data.IsPressureLess20; + return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing && + data.IsBitPositionDecreasing && data.IsBlockPositionDecreasing && + data.IsRotorSpeedLt3 && data.IsPressureLt20; } }, new OperationDetector @@ -107,8 +117,9 @@ namespace AsbCloudInfrastructure.Services Operation = operations.FirstOrDefault(o => o.Name.Equals("Подъем с вращением")), Detect = (data) => { - return data.IsDepthNotChanges && data.IsBitRising && - data.IsBlockRising && data.IsRotorSpeedMore3 && data.IsPressureLess20; + return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing && + data.IsBitPositionDecreasing && data.IsBlockPositionDecreasing && + data.IsRotorSpeedGt3 && data.IsPressureLt20; } }, new OperationDetector @@ -117,8 +128,10 @@ namespace AsbCloudInfrastructure.Services Operation = operations.FirstOrDefault(o => o.Name.Equals("Промывка в покое")), Detect = (data) => { - return data.IsDepthNotChanges && data.IsBitStandsStill && - data.IsBlockStandsStill && data.IsRotorSpeedLess3 && data.IsPressureMore20; + return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing && + !data.IsBitPositionDecreasing && !data.IsBitPositionIncreasing && + !data.IsBlockPositionDecreasing && !data.IsBlockPositionIncreasing && + data.IsRotorSpeedLt3 && data.IsPressureGt20; } }, new OperationDetector @@ -127,8 +140,10 @@ namespace AsbCloudInfrastructure.Services Operation = operations.FirstOrDefault(o => o.Name.Equals("Промывка с вращением")), Detect = (data) => { - return data.IsDepthNotChanges && data.IsBitStandsStill && - data.IsBlockStandsStill && data.IsRotorSpeedMore3 && data.IsPressureMore20; + return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing && + !data.IsBitPositionDecreasing && !data.IsBitPositionIncreasing && + !data.IsBlockPositionDecreasing && !data.IsBlockPositionIncreasing && + data.IsRotorSpeedGt3 && data.IsPressureGt20; } }, new OperationDetector @@ -137,8 +152,10 @@ namespace AsbCloudInfrastructure.Services Operation = operations.FirstOrDefault(o => o.Name.Equals("Неподвижное состояние")), Detect = (data) => { - return data.IsDepthNotChanges && data.IsBitStandsStill && data.IsBlockStandsStill - && data.IsRotorSpeedLess3 && data.IsPressureLess20 && data.IsHookWeightNotChanges; + return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing && + !data.IsBitPositionDecreasing && !data.IsBitPositionIncreasing && + !data.IsBlockPositionDecreasing && !data.IsBlockPositionIncreasing && + data.IsRotorSpeedLt3 && data.IsPressureLt20 && data.IsHookWeightNotChanges; } }, new OperationDetector @@ -147,8 +164,10 @@ namespace AsbCloudInfrastructure.Services Operation = operations.FirstOrDefault(o => o.Name.Equals("Вращение без циркуляции")), Detect = (data) => { - return data.IsDepthNotChanges && data.IsBitStandsStill && - data.IsBlockStandsStill && data.IsRotorSpeedMore3 && data.IsPressureLess20; + return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing && + !data.IsBitPositionDecreasing && !data.IsBitPositionIncreasing && + !data.IsBlockPositionDecreasing && !data.IsBlockPositionIncreasing && + data.IsRotorSpeedGt3 && data.IsPressureLt20; } }, new OperationDetector @@ -160,7 +179,7 @@ namespace AsbCloudInfrastructure.Services }; } - public Operation DetectOperation(DrillingAnalysis data) => + public Operation DetectOperation(TelemetryAnalysis data) => detectors.OrderBy(d => d.Order).First(o => o.Detect(data)).Operation ?? new Operation { Id = 1, Name = "Невозможно определить операцию" }; } diff --git a/AsbCloudInfrastructure/Services/СlusterService.cs b/AsbCloudInfrastructure/Services/СlusterService.cs index ff8883d9..8de76465 100644 --- a/AsbCloudInfrastructure/Services/СlusterService.cs +++ b/AsbCloudInfrastructure/Services/СlusterService.cs @@ -11,11 +11,11 @@ using System.Threading.Tasks; namespace AsbCloudInfrastructure.Services { - public class СlusterService : IClusterService + public class ClusterService : IClusterService { private readonly IAsbCloudDbContext db; - public СlusterService(IAsbCloudDbContext db) + public ClusterService(IAsbCloudDbContext db) { this.db = db; } diff --git a/AsbCloudWebApi.Tests/ControllersTests/AnalyticsControllerTests.cs b/AsbCloudWebApi.Tests/ControllersTests/AnalyticsControllerTests.cs index 398fa8ce..b26abf30 100644 --- a/AsbCloudWebApi.Tests/ControllersTests/AnalyticsControllerTests.cs +++ b/AsbCloudWebApi.Tests/ControllersTests/AnalyticsControllerTests.cs @@ -38,7 +38,7 @@ namespace AsbCloudWebApi.Tests.ControllersTests .Returns(true); controller = new AnalyticsController(analyticsService.Object, - wellService.Object); + wellService.Object); var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { @@ -129,7 +129,7 @@ namespace AsbCloudWebApi.Tests.ControllersTests var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { - new Claim("idCustomer", "1"), + new Claim("idCustomer", "1"), }, "mock")); newControllerInstance.ControllerContext = new ControllerContext() diff --git a/AsbCloudWebApi/Controllers/ClusterController.cs b/AsbCloudWebApi/Controllers/ClusterController.cs index cbca7f05..601ebd79 100644 --- a/AsbCloudWebApi/Controllers/ClusterController.cs +++ b/AsbCloudWebApi/Controllers/ClusterController.cs @@ -48,7 +48,7 @@ namespace AsbCloudWebApi.Controllers /// /// /// - [HttpGet("{clusterId}")] + [HttpGet("{clusterId}/Analysis")] [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] public IActionResult GetAnalysis(int clusterId) {