diff --git a/AsbCloudInfrastructure/Services/Subsystems/SubsystemOperationTimeService.cs b/AsbCloudInfrastructure/Services/Subsystems/SubsystemOperationTimeService.cs index 19157e5f..1faa769f 100644 --- a/AsbCloudInfrastructure/Services/Subsystems/SubsystemOperationTimeService.cs +++ b/AsbCloudInfrastructure/Services/Subsystems/SubsystemOperationTimeService.cs @@ -111,30 +111,31 @@ namespace AsbCloudInfrastructure.Services.Subsystems private static IEnumerable TrimOperation(IEnumerable data, DateTimeOffset? gtDate, DateTimeOffset? ltDate) { - if (!ltDate.HasValue && !gtDate.HasValue) return data; + if (!ltDate.HasValue && !gtDate.HasValue) + return data.Select(d => d.Adapt()); var items = data.Select((item) => { - var dateDiff = (ltDate!.Value - gtDate!.Value).TotalSeconds; - var depthDiff = (item.DepthEnd ?? 0) - (item.DepthStart ?? 0); - var a = depthDiff / (float)dateDiff; - var x = (float)(item.DateStart - gtDate.Value).TotalSeconds; - var b = item.DepthStart; - var cutDepth = a * x + b; - var operationTime = item.Adapt(); + if (!(item.DepthStart.HasValue && item.DepthEnd.HasValue)) + return operationTime; + + var dateDiff = (item.DateEnd - item.DateStart).TotalSeconds; + var depthDiff = item.DepthEnd.Value - item.DepthStart.Value; + var a = depthDiff / dateDiff; + var b = item.DepthStart.Value; if (gtDate.HasValue && item.DateStart < gtDate.Value) { operationTime.DateStart = gtDate.Value; - operationTime.DepthStart = cutDepth; + var x = (gtDate.Value - item.DateStart).TotalSeconds; + operationTime.DepthStart = (float)(a * x + b); } if (ltDate.HasValue && item.DateEnd > ltDate.Value) { operationTime.DateEnd = ltDate.Value; - operationTime.DepthEnd = cutDepth; - - var test = data; + var x = (ltDate.Value - item.DateStart).TotalSeconds; + operationTime.DepthEnd = (float)(a * x + b); } return operationTime; });