|
@@ -0,0 +1,104 @@
|
|
|
+using Shaker.Models;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.ComponentModel;
|
|
|
+using System.Linq;
|
|
|
+using System.Net.Http.Headers;
|
|
|
+using System.Text;
|
|
|
+using System.Threading.Tasks;
|
|
|
+
|
|
|
+namespace ShakerService.ViewModel
|
|
|
+{
|
|
|
+ internal class PSDCache
|
|
|
+ {
|
|
|
+ private List<double[]> LinearAverageCache = new List<double[]>();
|
|
|
+ public List<double[]> ExponentialAverageCache= new List<double[]>();
|
|
|
+ public void Clear()
|
|
|
+ {
|
|
|
+ LinearAverageCache.Clear();
|
|
|
+ ExponentialAverageCache.Clear();
|
|
|
+ }
|
|
|
+ public double[] CalcPSD(double[] data)
|
|
|
+ {
|
|
|
+ if(data ==null || data.Length ==0)return new double[0];
|
|
|
+ if (ServiceRandomConfigViewModel.Instance.LinearAverage > 1)
|
|
|
+ {
|
|
|
+ if (LinearAverageCache.Count == ServiceRandomConfigViewModel.Instance.LinearAverage)
|
|
|
+ {
|
|
|
+ for(int i=0;i<LinearAverageCache.Count-1;i++)
|
|
|
+ {
|
|
|
+ if (i == 0)
|
|
|
+ {
|
|
|
+ ServiceDataCacheViewModel.Instance.Calc.Add.Add(ref LinearAverageCache[i][0], ref LinearAverageCache[i + 1][0], (uint)data.Length, ref data[0]);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ServiceDataCacheViewModel.Instance.Calc.Add.Add(ref data[0], ref LinearAverageCache[i + 1][0], (uint)data.Length);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ServiceDataCacheViewModel.Instance.Calc.Division.Division(ref data[0], LinearAverageCache.Count, (uint)data.Length);
|
|
|
+ LinearAverageCache.Clear();
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ LinearAverageCache.Add(data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (ServiceRandomConfigViewModel.Instance.ExponentialAverage > 1)
|
|
|
+ {
|
|
|
+ ExponentialAverageCache.Add(data);
|
|
|
+ if (ExponentialAverageCache.Count > ServiceRandomConfigViewModel.Instance.ExponentialAverage)
|
|
|
+ {
|
|
|
+ ExponentialAverageCache.RemoveRange(0, (int)ServiceRandomConfigViewModel.Instance.ExponentialAverage - ExponentialAverageCache.Count);
|
|
|
+ }
|
|
|
+ if (ExponentialAverageCache.Count == 0 || ExponentialAverageCache.Count == 1) return data;
|
|
|
+ for(int i=0;i< ExponentialAverageCache.Count-2;i++)
|
|
|
+ {
|
|
|
+ if(i==0)
|
|
|
+ {
|
|
|
+ ServiceDataCacheViewModel.Instance.Calc.Add.Add(ref ExponentialAverageCache[i][0], ref ExponentialAverageCache[i + 1][0], (uint)data.Length, ref ExponentialAverageCache[^1][0]);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ServiceDataCacheViewModel.Instance.Calc.Add.Add(ref ExponentialAverageCache[^1][0], ref ExponentialAverageCache[i + 1][0], (uint)data.Length);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ServiceDataCacheViewModel.Instance.Calc.Division.Division(ref ExponentialAverageCache[^1][0], ExponentialAverageCache.Count, (uint)data.Length);
|
|
|
+ return ExponentialAverageCache[^1];
|
|
|
+ }
|
|
|
+ else return data;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ internal class ServiceRandomDataViewModel : BaseServiceViewModel<RandomDataModel>,IData
|
|
|
+ {
|
|
|
+ private List<PSDCache> AccelerationPSDCache { get; }= new List<PSDCache>();
|
|
|
+ private PSDCache DriverCache { get; }= new PSDCache();
|
|
|
+ public double CurrentIdentifyDisplacement { get => Model.CurrentIdentifyDisplacement; set => Model.CurrentIdentifyDisplacement = value; }
|
|
|
+ public double CurrentIdentifyRms { get => Model.CurrentIdentifyRms; set => Model.CurrentIdentifyRms = value; }
|
|
|
+ public int IdentifyIndex { get => Model.IdentifyIndex; set => Model.IdentifyIndex = value; }
|
|
|
+ public List<double[]> CurrentAccelerationPSD { get => Model.CurrentAccelerationPSD; set => Model.CurrentAccelerationPSD = value; }
|
|
|
+ public RandomTestStep RandomTestStep{ get => Model.RandomTestStep; set => Model.RandomTestStep = value; }
|
|
|
+ public double[] CurrentAccelerationSynthesisPSD { get => Model.CurrentAccelerationSynthesisPSD; set => Model.CurrentAccelerationSynthesisPSD = value; }
|
|
|
+ public double[] TransferFunction { get => Model.TransferFunction; set => Model.TransferFunction = value; }
|
|
|
+ public double[] DriverPSD { get => Model.DriverPSD; set => Model.DriverPSD = value; }
|
|
|
+ public double CurrentTestLevel { get => Model.CurrentTestLevel; set => Model.CurrentTestLevel = value; }
|
|
|
+ public double CurrentTestTime { get => Model.CurrentTestTime; set => Model.CurrentTestTime = value; }
|
|
|
+ public MainPageType MainPageType => Model.MainPageType;
|
|
|
+ public void InitCache()
|
|
|
+ {
|
|
|
+ AccelerationPSDCache.Clear();
|
|
|
+ AccelerationPSDCache.AddRange(Enumerable.Range(0, ServiceShakerConfigViewModel.Instance.AccelerationSensorCount).Select(x => new PSDCache()));
|
|
|
+ DriverCache.Clear();
|
|
|
+ }
|
|
|
+ public void ClearCache()
|
|
|
+ {
|
|
|
+ AccelerationPSDCache.ForEach(x => x.Clear());
|
|
|
+ DriverCache.Clear();
|
|
|
+ }
|
|
|
+ public void ReadFpgaData()
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|