Commit c9341c1e authored by 潘栩锋's avatar 潘栩锋 🚴

1

parent 7158c9a0
......@@ -29,5 +29,5 @@ namespace FObjBase
}
}
public delegate void AsyncCBHandler(object AsyncState, object retData);
public delegate void AsyncCBHandler(object AsyncContext, object retData);
}
......@@ -150,7 +150,7 @@ namespace FObjBase
{
}
public virtual void PushCallFunction(IFConn from, uint srcid, UInt32 magic, ushort funcid, byte[] retdata, object AsyncDelegate, object AsyncState)
public virtual void PushCallFunction(IFConn from, uint srcid, UInt32 magic, ushort funcid, byte[] retdata, object AsyncDelegate, object AsyncContext)
{
}
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Misc
{
public static class Enumerable
{
//
// 摘要:
// 计算 System.Double 值序列的Sigma,该值可通过调用输入序列的每个元素的转换函数获取。
//
// 参数:
// source:
// 要计算其平均值的值序列。
//
// selector:
// 应用于每个元素的转换函数。
//
// 类型参数:
// TSource:
// source 中的元素的类型。
//
// 返回结果:
// 值序列的Sigma。
//
// 异常:
// T:System.ArgumentNullException:
// source 或 selector 为 null。
//
// T:System.InvalidOperationException:
// source 中不包含任何元素。
public static double Sigma<TSource>(this IEnumerable<TSource> source, Func<TSource, double> selector)
{
if (source.Count() == 0)
return -1;
double avg = source.Average(selector);
double sum_pow = source.Sum((s) => Math.Pow((selector(s) - avg), 2));
return Math.Sqrt(sum_pow / (source.Count() - 1));
}
public static double Sigma(this IEnumerable<double> source)
{
return source.Sigma(d => d);
}
public static double CPK<TSource>(this IEnumerable<TSource> source, Func<TSource, double> selector, double usl, double lsl)
{
if (source.Count() == 0)
return -1;
//CPK = Min(CPKu,CPKl)
//USL(Upper specification limit): 规格上限。
//LSL(Low specification limit): 规格下限。
//ˉx = (x1 + x2 +...+ xn) / n : 平均值。
//T = USL - LSL : 规格公差。
//U = (USL + LSL) / 2:规格中心。
//CPKu = | USL - ˉx | / 3σ
//CPKl = | ˉx - LSL | / 3σ
double avg = source.Average(selector);
double sigma3 = source.Sigma(selector) * 3;
double CPKu = Math.Abs(usl - avg) / sigma3;
double CPKl = Math.Abs(lsl - avg) / sigma3;
double CPK = Math.Min(CPKu, CPKl);
return CPK;
}
public static double CPK(this IEnumerable<double> source, double usl, double lsl)
{
return source.CPK(d => d, usl, lsl);
}
public static List<XY> GetHistogram<TSource>(this IEnumerable<TSource> source, Func<TSource, double> selector, double step)
{
List<XY> list = new List<XY>();
foreach (var v in source)
{
double x = ((int)(selector(v) / step)) * step;
XY xy = list.Find(_xy => _xy.X == x);
if (xy != null)
{
xy.Y++;
}
else
{
xy = new XY(x, 1);
list.Add(xy);
}
}
list.Sort();
return list;
}
public static List<XY> GetHistogram(this IEnumerable<double> source, double step)
{
return source.GetHistogram(d => d, step);
}
}
public class XY : IComparable, ICloneable, ICopiable
{
public double X { get; set; }
public double Y { get; set; }
public XY()
{
}
public XY(double x, double y)
{
X = x;
Y = y;
}
public int CompareTo(object obj)
{
XY xy = obj as XY;
return X.CompareTo(xy.X);
}
public object Clone()
{
XY xy = new XY();
xy.Copy(this);
return xy;
}
public void Copy(object src)
{
Misc.PropertiesManager.CopyTo(src, this);
}
}
}
......@@ -86,6 +86,7 @@
<Compile Include="CRC.cs" />
<Compile Include="DATARANGE.cs" />
<Compile Include="Debug.cs" />
<Compile Include="Enumerable.cs" />
<Compile Include="IgnoreAttribute.cs" />
<Compile Include="ITDParam.cs" />
<Compile Include="Log.cs" />
......
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