diff --git a/AsbCloudApp/Services/ISaubDataCache.cs b/AsbCloudApp/Services/ISaubDataCache.cs index 60fa3710..117b09d9 100644 --- a/AsbCloudApp/Services/ISaubDataCache.cs +++ b/AsbCloudApp/Services/ISaubDataCache.cs @@ -5,6 +5,7 @@ namespace AsbCloudApp.Services { public interface ISaubDataCache { + TelemetryAnalysis CurrentAnalysis { get; set; } IEnumerable GetOrCreateCache(int telemetryId); void AddData(DataSaubBase data); } diff --git a/AsbCloudDb/Model/TelemetryAnalysis.cs b/AsbCloudDb/Model/TelemetryAnalysis.cs index add26302..0312ecf2 100644 --- a/AsbCloudDb/Model/TelemetryAnalysis.cs +++ b/AsbCloudDb/Model/TelemetryAnalysis.cs @@ -38,8 +38,11 @@ namespace AsbCloudDb.Model [Column("duration_sec"), Comment("Кол-во секунд после предыдущей операции")] public int Duration { get; set; } - [Column("well_depth"), Comment("Глубина, на которой закончилась операция")] - public double WellDepth { get; set; } + [Column("operation_start_depth"), Comment("Глубина, на которой началась операция")] + public double? OperationStartDepth { get; set; } + + [Column("operation_end_depth"), Comment("Глубина, на которой закончилась операция")] + public double? OperationEndDepth { get; set; } [Column("is_well_depth_increasing"), Comment("Глубина забоя увеличивается")] public bool IsWellDepthIncreasing { get; set; } diff --git a/AsbCloudInfrastructure/Services/AnalyticsService.cs b/AsbCloudInfrastructure/Services/AnalyticsService.cs index 31c78098..6b12e3ea 100644 --- a/AsbCloudInfrastructure/Services/AnalyticsService.cs +++ b/AsbCloudInfrastructure/Services/AnalyticsService.cs @@ -185,7 +185,8 @@ 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, - WellDepth = (double)dataSaubBases.Last().WellDepth, + OperationStartDepth = null, + OperationEndDepth = null, IsWellDepthDecreasing = LinearFunctionCalculator.IsValueGoesDown(wellDepthChangingIndex, -0.0001), IsWellDepthIncreasing = LinearFunctionCalculator.IsValueGoesUp(wellDepthChangingIndex, 0.0001), IsBitPositionDecreasing = LinearFunctionCalculator.IsValueGoesDown(bitPositionChangingIndex, -0.0001), diff --git a/AsbCloudInfrastructure/Services/DataService.cs b/AsbCloudInfrastructure/Services/DataService.cs index c24f3a00..daaa4366 100644 --- a/AsbCloudInfrastructure/Services/DataService.cs +++ b/AsbCloudInfrastructure/Services/DataService.cs @@ -106,9 +106,23 @@ namespace AsbCloudInfrastructure.Services var dataSaubs = saubDataCache.GetOrCreateCache(dataSaub.IdTelemetry) .OrderBy(d => d.Date); - var drillingAnalysis = analyticsService.GetDrillingAnalysis(dataSaubs); + var telemetryAnalysis = analyticsService.GetDrillingAnalysis(dataSaubs); - db.TelemetryAnalysis.Add(drillingAnalysis); + if(saubDataCache.CurrentAnalysis is null) + saubDataCache.CurrentAnalysis = telemetryAnalysis; + + if (saubDataCache.CurrentAnalysis.IdOperation == telemetryAnalysis.IdOperation) + { + saubDataCache.CurrentAnalysis.Duration += + telemetryAnalysis.Duration; + saubDataCache.CurrentAnalysis.OperationEndDepth = item.WellDepth; + } + else + { + db.TelemetryAnalysis.Add(saubDataCache.CurrentAnalysis); + saubDataCache.CurrentAnalysis = telemetryAnalysis; + saubDataCache.CurrentAnalysis.OperationStartDepth = item.WellDepth; + } } } diff --git a/AsbCloudInfrastructure/Services/SaubDataCache.cs b/AsbCloudInfrastructure/Services/SaubDataCache.cs index 3621a6dc..d2a9b659 100644 --- a/AsbCloudInfrastructure/Services/SaubDataCache.cs +++ b/AsbCloudInfrastructure/Services/SaubDataCache.cs @@ -6,7 +6,9 @@ namespace AsbCloudInfrastructure.Services { public class SaubDataCache : ISaubDataCache { - private readonly Dictionary> saubData = + public TelemetryAnalysis CurrentAnalysis { get; set; } + + private readonly Dictionary> saubData = new Dictionary>(); public IEnumerable GetOrCreateCache(int telemetryId)