using System;
using System.Collections.Generic;
using System.Linq;
namespace MuchInfo.Chart.Data.Models
{
///
/// 公式模型与编辑器中FormulaBase对应,保存一些图表参数。
///
public class FormulaModel
{
///
/// 获取或设置编辑器中转换的用于生图表数据
///
public List IndicatorList { get; set; }
///
/// 公式名称
///
public string FormulaName { get; set; }
public FormulaModel()
{
}
public FormulaModel(string formulaName)
{
this.FormulaName = formulaName;
}
///
/// 是否是主图
///
public bool IsMain
{
get
{
if (string.IsNullOrWhiteSpace(FormulaName)) return false;
else
{
return FormulaName.ToLower() == "main";
}
}
}
///
/// 是否是成交量
///
public bool IsVolume
{
get
{
if (string.IsNullOrWhiteSpace(FormulaName)) return false;
else
{
return FormulaName.ToLower() == "vol";
}
}
}
///
/// 是否为主图指标
///
public bool IsMainIndicator { get; set; }
///
/// 编辑副图指标
///
public ProgramModel EditProgram { get; set; }
///
/// 设置计算公式的参数
///
public void SetParamValue()
{
//formulaModel.FormulaName = this.Name;
if (EditProgram == null || EditProgram.CustomParams==null || !EditProgram.CustomParams.Any()) return;
string paramsStr = "(";
foreach (var paramsName in EditProgram.CustomParams.Keys)
{
if (!EditProgram.DefaultParams.ContainsKey(paramsName)) throw new Exception("公式默认参数获取异常!");
paramsStr += (string.IsNullOrEmpty(EditProgram.CustomParams[paramsName].Value)
? EditProgram.DefaultParams[paramsName]
: EditProgram.CustomParams[paramsName].Value) + ",";
}
paramsStr = paramsStr.TrimEnd(',') + ")";
this.FormulaName = EditProgram.Name + (paramsStr.Equals("()") ? string.Empty : paramsStr);
}
}
}