calculate_residual_analysis_config.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. package residual_analysis_model
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CalculateResidualAnalysisConfig struct {
  7. CalculateResidualAnalysisConfigId int `orm:"column(calculate_residual_analysis_config_id);pk;auto" description:"自增id"`
  8. Config string `orm:"column(config)" description:"计算参数配置"`
  9. SysUserId int `orm:"column(sys_user_id)" description:"操作人id"`
  10. CreateTime time.Time `orm:"column(create_time)" description:"创建时间"`
  11. ModifyTime time.Time `orm:"column(modify_time)" description:"修改时间"`
  12. }
  13. func init() {
  14. orm.RegisterModel(new(CalculateResidualAnalysisConfig))
  15. }
  16. // ResidualAnalysisReq 残差分析预览请求
  17. type ResidualAnalysisReq struct {
  18. EdbInfoIdA int `description:"指标A"`
  19. EdbInfoIdB int `description:"指标B"`
  20. EdbInfoId int `description:"残差指标id"`
  21. ConfigId int `description:"配置id"`
  22. QueryType int `description:"查询类型区分 避免查询过慢 1-查询第一个表格 2-查询需要计算的表格"`
  23. ResidualType int `description:"残差类型: 1-映射残差 2-拟合残差"`
  24. DateType int `description:"时间类型 -1-自定义时间 0-至今 n-枚举时间(近n年)"`
  25. StartDate string `description:"自定义开始日期"`
  26. EndDate string `description:"自定义结束日期"`
  27. IsOrder bool `description:"true:正序,false:逆序"`
  28. IndexType int `description:"1-标准指标 2-领先指标"`
  29. LeadValue int `description:"领先值"`
  30. LeadFrequency string `description:"领先频度"`
  31. LeftIndexMin float64 `description:"指标A左侧下限"`
  32. LeftIndexMax float64 `description:"指标A左侧上限"`
  33. RightIndexMin float64 `description:"指标B右侧下限"`
  34. RightIndexMax float64 `description:"指标B右侧上限"`
  35. ResidualIndexMin float64 `description:"残差指标下限"`
  36. ResidualIndexMax float64 `description:"残差指标上限"`
  37. ContrastIndexMin float64 `description:"对比指标下限"`
  38. ContrastIndexMax float64 `description:"对比指标上限"`
  39. }
  40. // ResidualAnalysisResp 残差分析预览响应
  41. type ResidualAnalysisResp struct {
  42. OriginalChartData ChartResp `description:"原始图数据"`
  43. MappingChartData ChartResp `description:"映射图数据"`
  44. ResidualChartData ChartResp `description:"残差图数据"`
  45. A float64 `description:"斜率"`
  46. B float64 `description:"截距"`
  47. R float64 `description:"相关系数"`
  48. R2 float64 `description:"决定系数"`
  49. }
  50. type ChartResp struct {
  51. ChartInfo ResidualAnalysisChartInfo
  52. EdbInfoList []ResidualAnalysisChartEdbInfoMapping
  53. }
  54. type ResidualAnalysisChartInfo struct {
  55. ChartName string `description:"来源名称"`
  56. ChartNameEn string `description:"英文图表名称"`
  57. Unit string `description:"中文单位名称"`
  58. UnitEn string `description:"英文单位名称"`
  59. UniqueCode string `description:"图表唯一编码"`
  60. DateType int `description:"时间类型 0-自定义时间 1-至今 n-枚举时间(近n年)"`
  61. StartDate string `description:"自定义开始日期"`
  62. EndDate string `description:"自定义结束日期"`
  63. ChartType int `description:"生成样式:1:曲线图,2:季节性图"`
  64. ChartWidth float64 `description:"线条大小"`
  65. Calendar string `description:"公历/农历"`
  66. Disabled int `description:"是否禁用,0:启用,1:禁用,默认:0"`
  67. Source int `description:"1:ETA图库;2:商品价格曲线;3:相关性图表"`
  68. ChartSource string `description:"图表来源str"`
  69. ChartSourceEn string `description:"图表来源(英文)"`
  70. SourcesFrom string `description:"图表来源"`
  71. Instructions string `description:"图表说明"`
  72. }
  73. type ResidualAnalysisChartEdbInfoMapping struct {
  74. EdbInfoId int `description:"指标id"`
  75. SourceName string `description:"来源名称"`
  76. Source int `description:"来源id"`
  77. EdbCode string `description:"指标编码"`
  78. EdbName string `description:"指标名称"`
  79. EdbNameEn string `description:"英文指标名称"`
  80. EdbType int `description:"指标类型:1:基础指标,2:计算指标"`
  81. Frequency string `description:"频率"`
  82. FrequencyEn string `description:"英文频率"`
  83. Unit string `description:"单位"`
  84. UnitEn string `description:"英文单位"`
  85. StartDate string `description:"起始日期"`
  86. EndDate string `description:"终止日期"`
  87. ModifyTime string `description:"指标最后更新时间"`
  88. MaxData float64 `description:"上限"`
  89. MinData float64 `description:"下限"`
  90. IsOrder bool `description:"true:逆序:,false:正序"`
  91. IsAxis int `description:"1:左轴,0:右轴"`
  92. EdbInfoType int `description:"1:标准指标,0:领先指标"`
  93. EdbInfoCategoryType int `description:"0:普通指标,1:预测指标"`
  94. LeadValue int `description:"领先值"`
  95. LeadUnit string `description:"领先单位"`
  96. LeadUnitEn string `description:"领先英文单位"`
  97. ChartStyle string `description:"图表类型"`
  98. ChartColor string `description:"颜色"`
  99. PredictChartColor string `description:"预测数据的颜色"`
  100. ChartWidth float64 `description:"线条大小"`
  101. ChartType int `description:"生成样式:1:曲线图,2:季节性图,3:面积图,4:柱状图,5:散点图,6:组合图,7:柱方图,8:商品价格曲线图,9:相关性图"`
  102. LatestDate string `description:"数据最新日期"`
  103. LatestValue float64 `description:"数据最新值"`
  104. MinValue float64 `description:"最小值"`
  105. MaxValue float64 `description:"最大值"`
  106. DataList interface{}
  107. }
  108. type ResidualAnalysisIndexSaveReq struct {
  109. EdbInfoIdA int `description:"指标A"`
  110. EdbInfoIdB int `description:"指标B"`
  111. Source int `description:"99-映射残差 100-拟合残差"`
  112. EdbCode string `description:"指标编码"`
  113. EdbName string `description:"指标名称"`
  114. EdbNameEn string `description:"英文指标名称"`
  115. EdbType int `description:"指标类型:1:基础指标,2:计算指标"`
  116. Frequency string `description:"频率"`
  117. FrequencyEn string `description:"英文频率"`
  118. Unit string `description:"单位"`
  119. UnitEn string `description:"英文单位"`
  120. Calendar string `description:"公历/农历"`
  121. ClassifyId int `description:"分类id"`
  122. ConfigId int `description:"残差配置id"`
  123. ResidualType int `orm:"column(residual_type)" description:"残差类型: 1-映射残差 2-拟合残差"`
  124. IndexType int `orm:"column(index_type)" description:"指标类型:1-映射指标 2-残差指标 3-因变量指标 4-自变量指标"`
  125. DataList []edbDataResidualAnalysis `description:"指标数据"`
  126. }
  127. // ResidualAnalysisConfigVo 残差分析配置vo
  128. type ResidualAnalysisConfigVo struct {
  129. DateType int `description:"时间类型 -1-自定义时间 0-至今 n-枚举时间(近n年)"`
  130. StartDate string `description:"自定义开始日期"`
  131. EndDate string `description:"自定义结束日期"`
  132. IsOrder bool `description:"true:正序,false:逆序"`
  133. IndexType int `description:"1-标准指标 2-领先指标"`
  134. LeadValue int `description:"领先值"`
  135. LeadFrequency string `description:"领先频度"`
  136. LeftIndexMin float64 `description:"指标A左侧下限"`
  137. LeftIndexMax float64 `description:"指标A左侧上限"`
  138. RightIndexMin float64 `description:"指标B右侧下限"`
  139. RightIndexMax float64 `description:"指标B右侧上限"`
  140. ResidualIndexMin float64 `description:"残差指标下限"`
  141. ResidualIndexMax float64 `description:"残差指标上限"`
  142. ContrastIndexMin float64 `description:"对比指标下限"`
  143. ContrastIndexMax float64 `description:"对比指标上限"`
  144. }
  145. type DetailEdbInfoList struct {
  146. EdbInfoId int `orm:"column(edb_info_id);pk"`
  147. EdbInfoType int `description:"指标类型,0:普通指标,1:预测指标"`
  148. IndexType int `orm:"column(index_type)" description:"指标类型:1-映射指标 2-残差指标 3-因变量指标 4-自变量指标"`
  149. SourceName string `description:"来源名称"`
  150. Source int `description:"来源id"`
  151. EdbCode string `description:"指标编码"`
  152. EdbNameEn string `description:"英文指标名称"`
  153. EdbName string `description:"指标名称"`
  154. Frequency string `description:"频率"`
  155. FrequencyEn string `description:"英文频率"`
  156. Unit string `description:"单位"`
  157. UnitEn string `description:"英文单位"`
  158. ClassifyId int `description:"分类id"`
  159. }
  160. // ResidualAnalysisDetailResp 详情响应接口
  161. type ResidualAnalysisDetailResp struct {
  162. ConfigInfo *CalculateResidualAnalysisConfig
  163. EdbInfoList []*DetailEdbInfoList
  164. ResidualType int `description:"残差类型: 1-映射残差 2-拟合残差"`
  165. }
  166. // GetResidualAnalysisConfigById 根据配置id查询配置信息
  167. func GetResidualAnalysisConfigById(configId int) (residualAnalysisConfig CalculateResidualAnalysisConfig, err error) {
  168. o := orm.NewOrmUsingDB("data")
  169. sql := "SELECT * FROM calculate_residual_analysis_config WHERE calculate_residual_analysis_config_id=?"
  170. err = o.Raw(sql, configId).QueryRow(&residualAnalysisConfig)
  171. return residualAnalysisConfig, nil
  172. }
  173. // UpdateResidualAnalysisConfig 更新配置信息
  174. func UpdateResidualAnalysisConfig(config CalculateResidualAnalysisConfig) (err error) {
  175. o := orm.NewOrmUsingDB("data")
  176. _, err = o.Update(&config)
  177. if err != nil {
  178. return err
  179. }
  180. return nil
  181. }
  182. // SaveResidualAnalysisConfig 保存配置信息
  183. func SaveResidualAnalysisConfig(config CalculateResidualAnalysisConfig) (id int64, err error) {
  184. o := orm.NewOrmUsingDB("data")
  185. id, err = o.Insert(&config)
  186. if err != nil {
  187. return 0, err
  188. }
  189. return id, nil
  190. }