/// <summary> /// 确保参数值的个数不会超限 /// </summary> /// <param name="cpmDetail"></param> /// <param name="cpm"></param> private static void AsureChartPointNums(CpmDetailViewStore cpmDetail, Cpm cpm) { if (cpmDetail.ChartCpmSourceDict[cpm.Code].Count > maxChartPointNums) { cpmDetail.ChartCpmSourceDict[cpm.Code].RemoveRange(0, removePointNums); cpmDetail.AvgDict[cpm.Code].RemoveRange(0, removePointNums); //更新平均值计算器 cpmDetail.AvgLast[cpm.Code] = cpmDetail.Avgcalculator[cpm.Code](cpm.GetFloatVal()); cpmDetail.Avgcalculator[cpm.Code] = YUtil.CreateExecAvgFunc(); } if (cpmDetail.MaxThresholdDict[cpm.Code].Count > maxChartPointNums) { cpmDetail.MaxThresholdDict[cpm.Code].RemoveRange(0, removePointNums); } if (cpmDetail.MinThresholdDict[cpm.Code].Count > maxChartPointNums) { cpmDetail.MinThresholdDict[cpm.Code].RemoveRange(0, removePointNums); } if (cpmDetail.CPKDict[cpm.Code].Count > maxChartPointNums) { cpmDetail.CPKDict[cpm.Code].RemoveRange(0, removePointNums); } }
public static SimpleReducer <Store> Create() { return(new SimpleReducer <Store>() .When <ViewStoreActions.Init>((state, action) => { state.NavView = new NavViewStore(); state.NavView.DMesSelectedMachineCode = MachineConfig.MachineDict.Keys.FirstOrDefault(); state.DMewCoreViewDict = new Dictionary <string, DMesCoreViewStore>(); state.CpmDetailViewDict = new Dictionary <string, CpmDetailViewStore>(); foreach (var pair in MachineConfig.MachineDict) { state.DMewCoreViewDict[pair.Key] = new DMesCoreViewStore(pair.Key); state.CpmDetailViewDict[pair.Key] = new CpmDetailViewStore(pair.Key); var cpmDetail = state.CpmDetailViewDict[pair.Key]; cpmDetail.ChartCpmSourceDict = new Dictionary <int, ObservableCollection <Cpm> >(); cpmDetail.MaxThresholdDict = new Dictionary <int, ObservableCollection <CpmChartThreshold> >(); cpmDetail.MinThresholdDict = new Dictionary <int, ObservableCollection <CpmChartThreshold> >(); cpmDetail.CPKDict = new Dictionary <int, ObservableCollection <CPK> >(); cpmDetail.AvgDict = new Dictionary <int, ObservableCollection <CpmAvg> >(); cpmDetail.Avgcalculator = new Dictionary <int, Func <double, double> >(); cpmDetail.AvgLast = new Dictionary <int, double?>(); foreach (var cpmPair in pair.Value.CodeToAllCpmDict) { cpmDetail.ChartCpmSourceDict[cpmPair.Key] = new ObservableCollection <Cpm>(); cpmDetail.MaxThresholdDict[cpmPair.Key] = new ObservableCollection <CpmChartThreshold>(); cpmDetail.MinThresholdDict[cpmPair.Key] = new ObservableCollection <CpmChartThreshold>(); cpmDetail.CPKDict[cpmPair.Key] = new ObservableCollection <CPK>(); cpmDetail.AvgDict[cpmPair.Key] = new ObservableCollection <CpmAvg>(); cpmDetail.Avgcalculator[cpmPair.Key] = YUtil.CreateExecAvgFunc(); cpmDetail.AvgLast[cpmPair.Key] = null; } } return state; }).When <ViewStoreActions.ChangeDMesSelectedMachineCode>((state, action) => { state.NavView.DMesSelectedMachineCode = action.MachineCode; return state; }).When <CpmActions.CpmUpdatedAll>((state, action) => { try { var cpmDetail = state.CpmDetailViewDict[action.MachineCode]; //当前是否处于曲线界面 //这个 6 表示为曲线界面 PageView 的 Index 为 6 var isInChartView = state.DMewCoreViewDict[action.MachineCode].TabSelectedIndex == 5; var machineCode = action.MachineCode; foreach (var cpm in action.Cpms) { if (cpm.ValueType != SmParamType.Signal) { continue; } //过滤掉时间有问题的点 var lastTime = cpmDetail.ChartCpmSourceDict[cpm.Code].LastOrDefault()?.PickTime; if (lastTime.HasValue && lastTime.Value >= cpm.PickTime) { continue; } var(maxThreshold, minThreshold) = getMaxMinThreshold(state, machineCode, cpm); var cpk = getCPK(cpm, maxThreshold, minThreshold); //减少主线程调用次数 //只有更新的参数Id为选中的 && 当前处于曲线界面才唤起主线程 && 当前导航机台位参数机台 if (state.NavView.DMesSelectedMachineCode == action.MachineCode && cpm.Code == cpmDetail.SelectedCpm?.Code && isInChartView) { Application.Current.Dispatcher.Invoke(() => { //有的机台会抛错,别问我为什么 try { updateChartView(cpmDetail, cpm, maxThreshold, minThreshold, cpk); } catch (Exception e) { //App.Logger.Warn("更新曲线异常" + e, true); } }); } else { //防止多线程错误 try { updateChartView(cpmDetail, cpm, maxThreshold, minThreshold, cpk); } catch { } } } } catch (Exception e) { App.Logger.Error("实时曲线异常", e); } return state; })); }