TagInfo.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using NEIntelligentControl2.Models.Datas;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace NEIntelligentControl2.Models.AGC
  8. {
  9. /// <summary>
  10. /// AGC数据标签
  11. /// </summary>
  12. public class TagInfo
  13. {
  14. /// <summary>
  15. /// 名称
  16. /// </summary>
  17. public string Name { get; set; }
  18. private string tag;
  19. /// <summary>
  20. /// 标签
  21. /// </summary>
  22. public string Tag { get => tag; set { tag = value; Tags = tag?.Split(','); } }
  23. /// <summary>
  24. /// 倍率
  25. /// </summary>
  26. public float Multiplier { get; set; } = 1;
  27. /// <summary>
  28. /// 单位
  29. /// </summary>
  30. public string Unit { get; set; }
  31. /// <summary>
  32. /// 类型
  33. /// </summary>
  34. public TagType Type { get; set; }
  35. /// <summary>
  36. /// 标签们
  37. /// </summary>
  38. public string[] Tags { get; set; }
  39. /// <summary>
  40. /// 时间戳
  41. /// </summary>
  42. public long Ts { get; set; }
  43. /// <summary>
  44. /// 值改变
  45. /// </summary>
  46. public Action<double> ValueChanged { get; internal set; }
  47. /// <summary>
  48. /// 值
  49. /// </summary>
  50. private double value;
  51. public double Value { get { return value; } set { this.value = value * Multiplier; ValueChanged?.Invoke(this.value); } }
  52. /// <summary>
  53. /// 数据历史值改变
  54. /// </summary>
  55. public Action<TagInfo, List<TsData>> HistoryValueChanged { get; set; }
  56. /// <summary>
  57. /// 更新数据
  58. /// </summary>
  59. internal void UpdateData(Dictionary<string, TsData> vs)
  60. {
  61. if (vs == null || this.Tags == null) return;
  62. double d = 0;
  63. foreach (var v in this.Tags)
  64. {
  65. if (!vs.ContainsKey(v)) continue;
  66. var td = vs[v];
  67. d += td.Value;
  68. Ts = td.Ts;
  69. }
  70. this.Value = d;
  71. }
  72. /// <summary>
  73. /// 更新历史数据
  74. /// </summary>
  75. internal void UpdateHistoryData(List<TsData> dts)
  76. {
  77. HistoryValueChanged?.Invoke(this, dts);
  78. }
  79. }
  80. }