Commit 28b5f8d3 authored by 潘栩锋's avatar 潘栩锋 🚴

getsample 只要任何一个样品点,获取还没成功, 都是采样未完成。 且把上一次采样完成记录下来,用于 比较数据 异常报警用。

parent d242251b
......@@ -88,7 +88,7 @@
</StackPanel>
</StackPanel>
<StackPanel Orientation="Horizontal">
<StackPanel Margin="{StaticResource ControlMargin}">
<TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="差异比例" />
......@@ -98,14 +98,6 @@
<TextBlock Style="{StaticResource Styles.Text.FieldHeader.Comment}" Text="样品1AD/样品0AD&#13;与上一次比较" />
</StackPanel>
</StackPanel>
<StackPanel Margin="{StaticResource ControlMargin}">
<TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="差异时间范围" />
<StackPanel Orientation="Horizontal">
<TextBox Style="{StaticResource Styles.Text.FieldContent.Input.Card}" Text="{Binding ErrIntervalMin}" />
<TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" Text="min"/>
<TextBlock Style="{StaticResource Styles.Text.FieldHeader.Comment}" Text="两次时间点比较,&#13;时间点的间隔最大时长。 大于它无效,不能比较" />
</StackPanel>
</StackPanel>
</StackPanel>
</StackPanel>
</Border>
......@@ -277,38 +269,6 @@
</StackPanel>
</Border>
<Border Style="{StaticResource Styles.Card.Border}">
<StackPanel>
<TextBlock Style="{StaticResource Styles.Card.Title}"
Text="采集记录"/>
<StackPanel Orientation="Horizontal">
<Button Style="{StaticResource Styles.Button.Square2}" Content="获取" Command="{Binding GetTempDataCmd}"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<ItemsControl ItemsSource="{Binding TempData}" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<DataGrid ItemsSource="{Binding .}" IsReadOnly="True" Margin="{StaticResource ControlMargin}" AutoGenerateColumns="False" Width="400" TextBlock.FontSize="12" TextBlock.FontWeight="Normal"
>
<DataGrid.Columns>
<DataGridTextColumn Header="复位" Binding="{Binding IsReset}" Width="100"/>
<DataGridTextColumn Header="时间" Binding="{Binding Time,StringFormat={}{0:HH:mm:ss}}" FontSize="10" Width="100"/>
<DataGridTextColumn Header="AD" Binding="{Binding Ad}" Width="100"/>
<DataGridTextColumn Header="滤波AD" Binding="{Binding FilterAd}" Width="100"/>
</DataGrid.Columns>
</DataGrid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</StackPanel>
</Border>
</StackPanel>
</ScrollViewer>
<Button Style="{StaticResource Styles.Button.Apply}" VerticalAlignment="Bottom" Margin="0,0,20,20"
......
......@@ -85,12 +85,6 @@ namespace FLY.Thick.Base.UI
/// </summary>
public double CrossErrPercent { get; set; }
/// <summary>
/// 异常比较 时间间隔范围;
/// 两次时间点比较, 时间点的间隔最大时长。 大于它无效,不能比较
/// </summary>
public int ErrIntervalMin { get; set; }
/// <summary>
/// 参数:样品点参数
/// </summary>
......@@ -108,12 +102,11 @@ namespace FLY.Thick.Base.UI
#region Command
public RelayCommand ApplyCmd { get; private set; }
public RelayCommand GetTempDataCmd { get; private set; }
#endregion
public event PropertyChangedEventHandler PropertyChanged;
public List<List<TempFilterData>> TempData { get; private set; }
public string InfoName { get; set; }
IGetSampleService getSampleService;
......@@ -121,7 +114,6 @@ namespace FLY.Thick.Base.UI
public PgGetSampleVm()
{
ApplyCmd = new RelayCommand(Apply);
GetTempDataCmd = new RelayCommand(GetTempData);
}
......@@ -139,7 +131,6 @@ namespace FLY.Thick.Base.UI
Misc.BindingOperations.SetBinding(this.getSampleService, nameof(this.getSampleService.ErrPercent), this, nameof(ErrPercent));
Misc.BindingOperations.SetBinding(this.getSampleService, nameof(this.getSampleService.ErrValue), this, nameof(ErrValue));
Misc.BindingOperations.SetBinding(this.getSampleService, nameof(this.getSampleService.CrossErrPercent), this, nameof(CrossErrPercent));
Misc.BindingOperations.SetBinding(this.getSampleService, nameof(this.getSampleService.ErrIntervalMin), this, nameof(ErrIntervalMin));
Misc.BindingOperations.SetBinding(this.getSampleService, nameof(this.getSampleService.SearchRange), this, nameof(SearchRange));
......@@ -257,7 +248,7 @@ namespace FLY.Thick.Base.UI
this.getSampleService.ErrPercent = this.ErrPercent;
this.getSampleService.ErrValue = this.ErrValue;
this.getSampleService.CrossErrPercent = this.CrossErrPercent;
this.getSampleService.ErrIntervalMin = this.ErrIntervalMin;
for (int i = 0; i < Samples.Count(); i++)
{
......@@ -287,17 +278,7 @@ namespace FLY.Thick.Base.UI
TimeSpan.FromSeconds(2));
}
private void GetTempData()
{
getSampleService.GetTempFilterDatas((asyncContext, retData) =>
{
var ll = retData as List<List<TempFilterData>>;
TempData = ll;
FLY.ControlLibrary.Window_Tip.Show("加载完成",
$"共加载{ll.Count()}列数据",
TimeSpan.FromSeconds(2));
}, null);
}
}
public class PgGetSampleVmUt : PgGetSampleVm
{
......
......@@ -61,13 +61,6 @@ namespace FLY.Thick.Base.IService
/// </summary>
double CrossErrPercent { get; set; }
/// <summary>
/// 异常比较 时间间隔范围;
/// 两次时间点比较, 时间点的间隔最大时长。 大于它无效,不能比较
/// </summary>
int ErrIntervalMin { get; set; }
/// <summary>
/// 参数:样品点参数
/// </summary>
......@@ -191,10 +184,6 @@ namespace FLY.Thick.Base.IService
/// </summary>
public double SampleValue { get; set; }
/// <summary>
/// 采集失败了
/// </summary>
public bool IsFailure { get; set; }
#region INotifyPropertyChanged 成员
public event PropertyChangedEventHandler PropertyChanged;
......
......@@ -70,12 +70,6 @@ namespace FLY.Thick.Base.Server
/// </summary>
public double CrossErrPercent { get; set; } = 0.02;
/// <summary>
/// 异常比较 时间间隔范围;
/// 两次时间点比较, 时间点的间隔最大时长。 大于它无效,不能比较
/// </summary>
public int ErrIntervalMin { get; set; } = 30;
/// <summary>
/// 样品
/// </summary>
......@@ -98,9 +92,29 @@ namespace FLY.Thick.Base.Server
TempFilter2[] tempFilters;
DIRECTION[] directions;
/// <summary>
/// 采集状态
/// </summary>
public SampleState[] states;
public enum SampleState
{
/// <summary>
/// 准备采集
/// </summary>
ReadyToCapture,
/// <summary>
/// 采集成功
/// </summary>
Ok,
/// <summary>
/// 采集失败
/// </summary>
IsFailure
}
IGageInfoService mGageInfo;
OBJComponents.Server.WarningSystem2 warningSystem;
FlyAD7 flyad;
SampleData last_sampleData;
public event SampleChangedEventHandler SampleChangedEvent;
private string param_path;
......@@ -119,7 +133,7 @@ namespace FLY.Thick.Base.Server
Features = new SampleFeature[2];
tempFilters = new TempFilter2[Samples.Count()];
directions = new DIRECTION[Samples.Count()];
states = new SampleState[Samples.Count()];
for (int i = 0; i < Samples.Count(); i++)
tempFilters[i] = new TempFilter2();
......@@ -196,6 +210,7 @@ namespace FLY.Thick.Base.Server
/// <param name="scanend"></param>
public virtual void Reset(int scanbegin, int scanend)
{
last_sampleData = null;
for (int i = 0; i < Samples.Count(); i++) {
SampleCell sample = Samples[i];
......@@ -203,24 +218,20 @@ namespace FLY.Thick.Base.Server
directions[i] = (Math.Abs(pos - scanbegin) < Math.Abs(pos - scanend)) ? Misc.DIRECTION.BACKWARD : Misc.DIRECTION.FORWARD;
sample.AD = -1;
states[i] = SampleState.ReadyToCapture;
tempFilters[i].Reset();
}
}
/// <summary>
///
/// 进入采集周期,设置全部采样点 为准备采集状态
/// </summary>
public void Reset()
public void ReadyToCapture()
{
for (int i = 0; i < Samples.Count(); i++)
{
SampleCell sample = Samples[i];
sample.AD = -1;
tempFilters[i].Reset();
states[i] = SampleState.ReadyToCapture;
}
}
/// <summary>
/// 获取样品测量范围
/// </summary>
......@@ -414,11 +425,40 @@ namespace FLY.Thick.Base.Server
if ((directions[i] == direction) && (sample.Enable))
{
tempre.Reset();
sample.IsFailure = true;
states[i] = SampleState.IsFailure;
}
}
}
/// <summary>
/// 设置全部样品为失败
/// </summary>
void SetFailure()
{
for (int i = 0; i < Samples.Count(); i++)
{
SampleCell sample = Samples[i];
var tempre = tempFilters[i];
if (sample.Enable)
{
tempre.Reset();
states[i] = SampleState.IsFailure;
}
}
}
public bool HasSampleAd()
{
for (int i = 0; i < Samples.Count(); i++)
{
SampleCell sample = Samples[i];
if (sample.Enable)
{
if (sample.AD <= 0)
return false;
}
}
return true;
}
enum GetSampleAdResult
{
OK,
......@@ -433,11 +473,7 @@ namespace FLY.Thick.Base.Server
/// <summary>
/// 滤波 异常
/// </summary>
FilterErr,
/// <summary>
/// 与上一个比较,变化太大
/// </summary>
TimeCompareErr
FilterErr
}
GetSampleAdResult GetSampleAd(SampleCell sample, TempFilter2 tempre, int grid_start, int[] buf, int grid_offset, out int ad)
{
......@@ -487,21 +523,9 @@ namespace FLY.Thick.Base.Server
return GetSampleAdResult.FilterErr;
}
}
//获取以前的Ad
int lastAd = tempre.GetLastAd(GetErrIntervalTime);
if (lastAd != -1) {
//找到了
diff = Math.Abs(ad - lastAd);
if (diff / ad >= ErrPercent) //大于2% 异常
{
return GetSampleAdResult.TimeCompareErr;
}
}
}
return GetSampleAdResult.OK;
}
DateTime GetErrIntervalTime => DateTime.Now - TimeSpan.FromMinutes(ErrIntervalMin);
GetSampleAdResult SetSampleAds(Misc.DIRECTION direction, int grid_start, int[] buf, int grid_offset)
{
......@@ -516,7 +540,7 @@ namespace FLY.Thick.Base.Server
if(ret == GetSampleAdResult.OK)
{
sample.AD = ad;
sample.IsFailure = false;
states[i] = SampleState.Ok;
}
else
{
......@@ -525,35 +549,6 @@ namespace FLY.Thick.Base.Server
}
}
}
if (Samples[0].AD > 0 && Samples[0].IsFailure == false)
{
//交叉比较
for (int i = 1; i < Samples.Count(); i++)
{
SampleCell sample = Samples[i];
if ((directions[i] == direction) && (sample.Enable))
{
double p = 1.0 * Samples[i].AD / Samples[0].AD;
if (p <= 0)
break;
int lastAdi = tempFilters[i].GetLastAd(GetErrIntervalTime);
int lastAd0 = tempFilters[0].GetLastAd(GetErrIntervalTime);
if (lastAd0 == 0)
break;
double last_p = 1.0 * lastAdi / lastAd0;
double diff = Math.Abs(last_p - p);
if (diff / p >= CrossErrPercent) //大于2% 异常
{
//TODO
//TODO
return GetSampleAdResult.TimeCompareErr;
}
}
}
}
return GetSampleAdResult.OK;
}
/// <summary>
......@@ -600,7 +595,7 @@ namespace FLY.Thick.Base.Server
//获取这个方向全部样品AD
var ret = SetSampleAds(direction, grid_start, buf, grid_offset);
switch (ret)
switch (ret)
{
case GetSampleAdResult.Zero:
{
......@@ -620,56 +615,151 @@ namespace FLY.Thick.Base.Server
{
this.warningSystem.Update(
ERRNOs.Instance.SAMPLE_ERRNO_Failure.Code,
$"{ERRNOs.Instance.SAMPLE_ERRNO_Failure.Descrption}:滤波异常");
$"{ERRNOs.Instance.SAMPLE_ERRNO_Failure.Descrption}:滤波数据与原始数据差异{ErrPercent:P0}");
}
break;
}
if(ret != GetSampleAdResult.OK)
if (ret != GetSampleAdResult.OK)
{
//有问题,全部复位
SetFailure(direction);
}
_end:
if (OK())
{
//全部都采集完成
if (!IsErr())//没有异常
{
//备份
last_sampleData = new SampleData();
last_sampleData.Time = DateTime.Now;
last_sampleData.SampleADs = new int[Samples.Count()];
for (int i = 0; i < Samples.Count(); i++)
{
last_sampleData.SampleADs[i] = Samples[i].AD;
}
}
}
_end:
SampleChangedEvent?.Invoke(this);
}
bool IsErr()
{
if (last_sampleData == null)
return false;
if (IsPercentErr())
{
//历史比较有问题
this.warningSystem.Update(
ERRNOs.Instance.SAMPLE_ERRNO_Failure.Code,
$"{ERRNOs.Instance.SAMPLE_ERRNO_Failure.Descrption}:样品AD与上次大于{ErrPercent:P0}变化");
//设置全部都是异常,重新测量
SetFailure();
last_sampleData = null;
return true;
}
if (IsCrossErr())
{
//交叉比较有问题
this.warningSystem.Update(
ERRNOs.Instance.SAMPLE_ERRNO_Failure.Code,
$"{ERRNOs.Instance.SAMPLE_ERRNO_Failure.Descrption}:样品比值与上次大于{CrossErrPercent:P0}变化");
//设置全部都是异常,重新测量
SetFailure();
last_sampleData = null;
return true;
}
return false;
}
/// <summary>
/// 检测是否成功
/// </summary>
/// <returns></returns>
public virtual bool OK()
{
return !IsFailure();
}
/// <summary>
/// 刚才报警了,采样失败
/// </summary>
/// <returns></returns>
public bool IsFailure()
{
if (Enable)
{
foreach (SampleCell sample in Samples)
for (int i = 0; i < Samples.Count(); i++)
{
SampleCell sample = Samples[i];
if (sample.Enable)
{
if ((sample.AD <= 0))
return false;
if (states[i] != SampleState.Ok)
return true;
}
}
}
return false;
}
return true;
/// <summary>
/// 全部采集完成,与上次采集比较 大于2% 异常
/// </summary>
/// <returns></returns>
bool IsPercentErr()
{
for (int i = 0; i < Samples.Count(); i++)
{
SampleCell sample = Samples[i];
if (sample.Enable)
{
int ad = sample.AD;
if (ad <= 0)//写错程序
break;
int lastAd = last_sampleData.SampleADs[i];
double diff = Math.Abs(ad - lastAd);
if (diff / ad > ErrPercent) //大于2% 异常
{
return true;
}
}
}
return false;
}
/// <summary>
/// 刚才报警了,采样失败
/// 全部采集完成,再做 交叉比较
/// </summary>
/// <returns></returns>
public bool IsFailure()
bool IsCrossErr()
{
if (Enable)
//交叉比较
for (int i = 1; i < Samples.Count(); i++)
{
foreach (SampleCell sample in Samples)
SampleCell sample = Samples[i];
if (sample.Enable)
{
if (sample.Enable)
double p = 1.0 * sample.AD / Samples[0].AD;
if (p <= 0)//写错程序
break;
int lastAdi = last_sampleData.SampleADs[i];
int lastAd0 = last_sampleData.SampleADs[0];
if (lastAd0 <= 0)//写错程序
break;
double last_p = 1.0 * lastAdi / lastAd0;
double diff = Math.Abs(last_p - p);
if (diff / p > CrossErrPercent) //大于2% 异常
{
if ((sample.AD <= 0) || (sample.IsFailure))
return true;
return true;
}
}
}
......@@ -726,6 +816,18 @@ _end:
}
public class SampleData : INotifyPropertyChanged
{
public DateTime Time { get; set; }
/// <summary>
/// 样品采集AD值
/// </summary>
public int[] SampleADs { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
}
public delegate void SampleChangedEventHandler(GSample gsample);
public class GSampleJsonDb
......@@ -813,7 +915,6 @@ _end:
public double ErrPercent { get; set; } = 2;
public int ErrValue { get; set; } = 200;
public double CrossErrPercent { get; set; } = 0.02;
public int ErrIntervalMin { get; set; } = 30;
public SampleCellParam[] Samples { get; set; }
public int SearchRange { get; set; } = 100;
public SampleFeatureParam[] Features { get; set; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment