diff --git a/AsbCloudInfrastructure/Services/WorkLimitingParameterCalc.cs b/AsbCloudInfrastructure/Background/WorkLimitingParameterCalc.cs similarity index 92% rename from AsbCloudInfrastructure/Services/WorkLimitingParameterCalc.cs rename to AsbCloudInfrastructure/Background/WorkLimitingParameterCalc.cs index 3ab159e0..76749e07 100644 --- a/AsbCloudInfrastructure/Services/WorkLimitingParameterCalc.cs +++ b/AsbCloudInfrastructure/Background/WorkLimitingParameterCalc.cs @@ -7,14 +7,13 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using System.Collections.Generic; -using AsbCloudInfrastructure.Background; using Microsoft.Extensions.DependencyInjection; -namespace AsbCloudInfrastructure.Services; +namespace AsbCloudInfrastructure.Background; public class WorkLimitingParameterCalc : Work { - public WorkLimitingParameterCalc() + public WorkLimitingParameterCalc() : base("Limiting parameter calc") { Timeout = TimeSpan.FromMinutes(30); @@ -51,7 +50,7 @@ public class WorkLimitingParameterCalc : Work var i = 0d; foreach (var item in telemetryLastDetectedDates) { - onProgressCallback($"Start hanling telemetry: {item.IdTelemetry} from {item.LastDate}", i++/count); + onProgressCallback($"Start hanling telemetry: {item.IdTelemetry} from {item.LastDate}", i++ / count); var newLimitingParameters = await GetLimitingParameterAsync(item.IdTelemetry, item.LastDate ?? DateTimeOffset.MinValue, db, token); if (newLimitingParameters?.Any() == true) { @@ -63,7 +62,7 @@ public class WorkLimitingParameterCalc : Work private static async Task> GetLimitingParameterAsync(int idTelemetry, DateTimeOffset begin, IAsbCloudDbContext db, CancellationToken token) { - var query = + var query = $"select " + $"limiting_parameters.date, limiting_parameters.id_feed_regulator, limiting_parameters.well_depth " + $"from ( " + @@ -72,9 +71,9 @@ public class WorkLimitingParameterCalc : Work $"lag(id_feed_regulator, 1) over (order by date) as id_feed_regulator_lag, " + $"lead(id_feed_regulator, 1) over (order by date) as id_feed_regulator_lead " + $"from t_telemetry_data_saub " + - $"where id_feed_regulator is not null " + - $"and id_telemetry = {idTelemetry}" + - $"and date >= '{begin:u}'" + + $"where id_feed_regulator is not null " + + $"and id_telemetry = {idTelemetry} " + + $"and date >= '{begin:u}' " + $"order by date) as limiting_parameters " + $"where id_feed_regulator_lag is null " + $"or (id_feed_regulator != id_feed_regulator_lag and id_feed_regulator_lead != id_feed_regulator_lag) " + @@ -102,14 +101,15 @@ public class WorkLimitingParameterCalc : Work if (limitingLast.IdFeedRegulator != idLimiting || limitingLast.DepthStart < wellDepth) { - limitingParameters.Add(new LimitingParameter { + limitingParameters.Add(new LimitingParameter + { IdTelemetry = idTelemetry, IdFeedRegulator = limitingLast.IdFeedRegulator, DateStart = limitingLast.DateStart, DateEnd = date, DepthStart = limitingLast.DepthStart, DepthEnd = wellDepth - }); + }); limitingLast = new LimitingParameter {