FormulaModel.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. 
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. namespace MuchInfo.Chart.Data.Models
  6. {
  7. /// <summary>
  8. /// 公式模型与编辑器中FormulaBase对应,保存一些图表参数。
  9. /// </summary>
  10. public class FormulaModel
  11. {
  12. /// <summary>
  13. /// 获取或设置编辑器中转换的用于生图表数据
  14. /// </summary>
  15. public List<IndicatorModel> IndicatorList { get; set; }
  16. /// <summary>
  17. /// 公式名称
  18. /// </summary>
  19. public string FormulaName { get; set; }
  20. public FormulaModel()
  21. {
  22. }
  23. public FormulaModel(string formulaName)
  24. {
  25. this.FormulaName = formulaName;
  26. }
  27. /// <summary>
  28. /// 是否是主图
  29. /// </summary>
  30. public bool IsMain
  31. {
  32. get
  33. {
  34. if (string.IsNullOrWhiteSpace(FormulaName)) return false;
  35. else
  36. {
  37. return FormulaName.ToLower() == "main";
  38. }
  39. }
  40. }
  41. /// <summary>
  42. /// 是否是成交量
  43. /// </summary>
  44. public bool IsVolume
  45. {
  46. get
  47. {
  48. if (string.IsNullOrWhiteSpace(FormulaName)) return false;
  49. else
  50. {
  51. return FormulaName.ToLower() == "vol";
  52. }
  53. }
  54. }
  55. /// <summary>
  56. /// 是否为主图指标
  57. /// </summary>
  58. public bool IsMainIndicator { get; set; }
  59. /// <summary>
  60. /// 编辑副图指标
  61. /// </summary>
  62. public ProgramModel EditProgram { get; set; }
  63. /// <summary>
  64. /// 设置计算公式的参数
  65. /// </summary>
  66. public void SetParamValue()
  67. {
  68. //formulaModel.FormulaName = this.Name;
  69. if (EditProgram == null || EditProgram.CustomParams==null || !EditProgram.CustomParams.Any()) return;
  70. string paramsStr = "(";
  71. foreach (var paramsName in EditProgram.CustomParams.Keys)
  72. {
  73. if (!EditProgram.DefaultParams.ContainsKey(paramsName)) throw new Exception("公式默认参数获取异常!");
  74. paramsStr += (string.IsNullOrEmpty(EditProgram.CustomParams[paramsName].Value)
  75. ? EditProgram.DefaultParams[paramsName]
  76. : EditProgram.CustomParams[paramsName].Value) + ",";
  77. }
  78. paramsStr = paramsStr.TrimEnd(',') + ")";
  79. this.FormulaName = EditProgram.Name + (paramsStr.Equals("()") ? string.Empty : paramsStr);
  80. }
  81. }
  82. }