FdcDataItem.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System;
  2. using System.Runtime.Serialization;
  3. namespace MECF.Framework.Common.CommonData
  4. {
  5. [DataContract]
  6. [Serializable]
  7. public class FdcDataItem
  8. {
  9. [DataMember]
  10. public string Name { get; set; }
  11. [DataMember]
  12. public float MaxValue { get; set; }
  13. [DataMember]
  14. public float MinValue { get; set; }
  15. [DataMember]
  16. public float MeanValue
  17. {
  18. get
  19. {
  20. if (SampleCount == 0)
  21. return 0f;
  22. return Total / SampleCount;
  23. }
  24. }
  25. [DataMember]
  26. public float StdValue
  27. {
  28. get
  29. {
  30. if (SampleCount <= 1)
  31. return 0f;
  32. return (float)Math.Sqrt(Math.Abs((SqrtTotal - 2 * (Total / SampleCount) * Total + SampleCount * (Total / SampleCount) * (Total / SampleCount)) / (SampleCount - 1)));
  33. }
  34. }
  35. [DataMember]
  36. public float SetPoint { get; set; }
  37. [DataMember]
  38. public float Total { get; set; }
  39. [DataMember]
  40. public float SqrtTotal { get; set; }
  41. [DataMember]
  42. public int SampleCount { get; set; }
  43. public void Clear()
  44. {
  45. MaxValue = float.MinValue;
  46. MinValue = float.MaxValue;
  47. SetPoint = 0f;
  48. Total = 0f;
  49. SampleCount = 0;
  50. SqrtTotal = 0f;
  51. }
  52. public void Update(float value)
  53. {
  54. if (value < MinValue)
  55. MinValue = value;
  56. if (value > MaxValue)
  57. MaxValue = value;
  58. Total += value;
  59. SqrtTotal += value * value;
  60. SampleCount++;
  61. }
  62. }
  63. }