изменение класса интерполяции

This commit is contained in:
eugeniy_ivanov 2022-10-11 12:12:32 +05:00
parent 684a56a100
commit b487f01fae
3 changed files with 76 additions and 90 deletions

View File

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace AsbCloudInfrastructure.Services.Subsystems.Utils
{
#nullable enable
internal class Interpolation
{
private IEnumerator<(DateTimeOffset dateMin, float? depthMin, DateTimeOffset dateMax, float? depthMax)> enumerator;
(DateTimeOffset dateMin, float? depthMin, DateTimeOffset dateMax, float? depthMax) lastValue = default;
public Interpolation(IOrderedEnumerable<(DateTimeOffset dateMin, float? depthMin, DateTimeOffset dateMax, float? depthMax)> collection)
{
enumerator = collection.GetEnumerator();
enumerator.MoveNext();
}
public float GetDepth(DateTimeOffset date)
{
if (lastValue.depthMin is not null &&
lastValue.depthMax is not null)
{
while (date > enumerator.Current.dateMax)
{
if (isLess(date))
CalcValue(enumerator.Current, date.Second);
enumerator.MoveNext();
}
}
return (float)lastValue.depthMin;
}
private bool isLess(DateTimeOffset date)
{
if (date <= enumerator.Current.dateMax && date >= enumerator.Current.dateMin)
return true;
return false;
}
private float CalcValue((DateTimeOffset dateMin, float? depthMin, DateTimeOffset dateMax, float? depthMax) item, int x)
{
var a = (item.depthMax - item.depthMin) / (item.dateMax.Second - item.dateMin.Second);
var b = item.depthMin * (item.dateMax.Second - (item.depthMax - item.depthMin) / (item.dateMax.Second - item.dateMin.Second));
var resultDepth = a * x + b;
return (float)resultDepth;
}
}
#nullable disable
}

View File

@ -257,27 +257,17 @@ namespace AsbCloudInfrastructure.Services.Subsystems
$"where mode_pre is null or state_pre is null or mode != mode_pre or state != state_pre " +
$"order by date;";
//var queryDepthFromSaub =
// "select " +
// " min(\"date\") as min_date, " +
// " min(well_depth) as min_well_depth, " +
// " max(\"date\") as max_date, " +
// " max(well_depth) as max_well_depth " +
// "from " +
// " t_telemetry_data_saub " +
// "where id_telemetry = @idTelemetry and \"date\" > @begin " +
// "group by ceil(well_depth * 10) " +
// "order by min_date; ";
var saubDepthAndDate = await db.TelemetryDataSaub.Where(s => s.IdTelemetry == idTelemetry & s.DateTime >= begin)
.Select(s => new DataRow()
{
Date = s.DateTime,
Depth = s.WellDepth
})
.ToListAsync(token);
var queryDepthFromSaub =
"select " +
" min(\"date\") as min_date, " +
" min(well_depth) as min_well_depth, " +
" max(\"date\") as max_date, " +
" max(well_depth) as max_well_depth " +
"from " +
" t_telemetry_data_saub " +
"where id_telemetry = @idTelemetry and \"date\" > @begin " +
"group by ceil(well_depth * 10) " +
"order by min_date; ";
var resultSpin = await GetResultFromQueryAsync(querySpin,begin,idTelemetry,db,token);
@ -296,28 +286,22 @@ namespace AsbCloudInfrastructure.Services.Subsystems
await resultSpin.DisposeAsync();
//using var resultDepthFromSaub = await GetResultFromQueryAsync(queryDepthFromSaub, begin, idTelemetry, db, token);
using var resultDepthFromSaub = await GetResultFromQueryAsync(queryDepthFromSaub, begin, idTelemetry, db, token);
//var dataDepthFromSaub = new List<(DateTimeOffset dateMin, float? depthMin, DateTimeOffset dateMax, float? depthMax)>();
//while (resultDepthFromSaub.Read())
//{
// var dateRowItem =
// (
// resultDepthFromSaub.GetFieldValue<DateTimeOffset>(0),
// resultDepthFromSaub.GetFieldValue<float?>(1),
// resultDepthFromSaub.GetFieldValue<DateTimeOffset>(2),
// resultDepthFromSaub.GetFieldValue<float?>(3)
var dataDepthFromSaub = new List<(DateTimeOffset dateMin, float? depthMin, DateTimeOffset dateMax, float? depthMax)>();
while (resultDepthFromSaub.Read())
{
var dateRowItem =
(
resultDepthFromSaub.GetFieldValue<DateTimeOffset>(0),
resultDepthFromSaub.GetFieldValue<float?>(1),
resultDepthFromSaub.GetFieldValue<DateTimeOffset>(2),
resultDepthFromSaub.GetFieldValue<float?>(3)
// );
// dataDepthFromSaub.Add(dateRowItem);
//}
var interp = new Interp(saubDepthAndDate.Select(t => (
t.Date,
t.Depth
))
.OrderBy(t => t.Date));
);
dataDepthFromSaub.Add(dateRowItem);
}
var interp = new Interpolation(dataDepthFromSaub.OrderBy(t => t.depthMin));
if (dataSpinList.Any())
{
var mode = dataSpinList[0].Mode;

View File

@ -1,49 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace AsbCloudInfrastructure.Services.Subsystems.Utils
{
internal class Interp
{
//private IEnumerator<(DateTimeOffset dateMin, float? depthMin,DateTimeOffset dateMax, float? depthMax)> enumerator;
//(DateTimeOffset dateMin, float? depthMin, DateTimeOffset dateMax, float? depthMax) lastValue = default;
//public Interp (IOrderedEnumerable<(DateTimeOffset dateMin, float? depthMin, DateTimeOffset dateMax, float? depthMax)> collection)
//{
// enumerator = collection.GetEnumerator();
// enumerator.MoveNext();
//}
//public float? GetDepth (DateTimeOffset date)
//{
// while(date < enumerator.Current.dateMax)
// {
// lastValue = enumerator.Current;
// enumerator.MoveNext();
// }
// return lastValue.depthMin;
//}
private IEnumerator<(DateTimeOffset date, float? y)> enumerator;
(DateTimeOffset date, float? y) lastValue = default;
public Interp(IOrderedEnumerable<(DateTimeOffset date, float? y)> collection)
{
enumerator = collection.GetEnumerator();
enumerator.MoveNext();
}
public float? GetDepth(DateTimeOffset date)
{
while (date > enumerator.Current.date)
{
lastValue = enumerator.Current;
enumerator.MoveNext();
}
return lastValue.y;
}
}
}