calculate_residual_analysis_config.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. LeftIndexMin float64 `description:"指标A左侧下限"`
  108. LeftIndexMax float64 `description:"指标A左侧上限"`
  109. RightIndexMin float64 `description:"指标B右侧下限"`
  110. RightIndexMax float64 `description:"指标B右侧上限"`
  111. ResidualIndexMin float64 `description:"残差指标下限"`
  112. ResidualIndexMax float64 `description:"残差指标上限"`
  113. ContrastIndexMin float64 `description:"对比指标下限"`
  114. ContrastIndexMax float64 `description:"对比指标上限"`
  115. }
  116. type ResidualAnalysisIndexSaveReq struct {
  117. EdbInfoIdA int `description:"指标A"`
  118. EdbInfoIdB int `description:"指标B"`
  119. Source int `description:"99-映射残差 100-拟合残差"`
  120. EdbCode string `description:"指标编码"`
  121. EdbName string `description:"指标名称"`
  122. EdbNameEn string `description:"英文指标名称"`
  123. EdbType int `description:"指标类型:1:基础指标,2:计算指标"`
  124. Frequency string `description:"频率"`
  125. FrequencyEn string `description:"英文频率"`
  126. Unit string `description:"单位"`
  127. UnitEn string `description:"英文单位"`
  128. Calendar string `description:"公历/农历"`
  129. ClassifyId int `description:"分类id"`
  130. ConfigId int `description:"残差配置id"`
  131. ResidualType int `orm:"column(residual_type)" description:"残差类型: 1-映射残差 2-拟合残差"`
  132. IndexType int `orm:"column(index_type)" description:"指标类型:1-映射指标 2-残差指标 3-因变量指标 4-自变量指标"`
  133. DataList []edbDataResidualAnalysis `description:"指标数据"`
  134. }
  135. // ResidualAnalysisConfigVo 残差分析配置vo
  136. type ResidualAnalysisConfigVo struct {
  137. ResidualType int `description:"残差类型: 1-映射残差 2-拟合残差"`
  138. DateType int `description:"时间类型 -1-自定义时间 0-至今 n-枚举时间(近n年)"`
  139. StartDate string `description:"自定义开始日期"`
  140. EndDate string `description:"自定义结束日期"`
  141. IsOrder bool `description:"true:正序,false:逆序"`
  142. IndexType int `description:"1-标准指标 2-领先指标"`
  143. LeadValue int `description:"领先值"`
  144. LeadFrequency string `description:"领先频度"`
  145. LeftIndexMin float64 `description:"指标A左侧下限"`
  146. LeftIndexMax float64 `description:"指标A左侧上限"`
  147. RightIndexMin float64 `description:"指标B右侧下限"`
  148. RightIndexMax float64 `description:"指标B右侧上限"`
  149. ResidualIndexMin float64 `description:"残差指标下限"`
  150. ResidualIndexMax float64 `description:"残差指标上限"`
  151. ContrastIndexMin float64 `description:"对比指标下限"`
  152. ContrastIndexMax float64 `description:"对比指标上限"`
  153. }
  154. type DetailEdbInfoList struct {
  155. EdbInfoId int `orm:"column(edb_info_id);pk"`
  156. EdbInfoType int `description:"指标类型,0:普通指标,1:预测指标"`
  157. IndexType int `orm:"column(index_type)" description:"指标类型:1-映射指标 2-残差指标 3-因变量指标 4-自变量指标"`
  158. SourceName string `description:"来源名称"`
  159. Source int `description:"来源id"`
  160. EdbCode string `description:"指标编码"`
  161. EdbNameEn string `description:"英文指标名称"`
  162. EdbName string `description:"指标名称"`
  163. Frequency string `description:"频率"`
  164. FrequencyEn string `description:"英文频率"`
  165. Unit string `description:"单位"`
  166. UnitEn string `description:"英文单位"`
  167. ClassifyId int `description:"分类id"`
  168. }
  169. // ResidualAnalysisDetailResp 详情响应接口
  170. type ResidualAnalysisDetailResp struct {
  171. ConfigInfo *CalculateResidualAnalysisConfig
  172. EdbInfoList []*DetailEdbInfoList
  173. ResidualType int `description:"残差类型: 1-映射残差 2-拟合残差"`
  174. }
  175. // GetResidualAnalysisConfigById 根据配置id查询配置信息
  176. func GetResidualAnalysisConfigById(configId int) (residualAnalysisConfig CalculateResidualAnalysisConfig, err error) {
  177. o := orm.NewOrmUsingDB("data")
  178. sql := "SELECT * FROM calculate_residual_analysis_config WHERE calculate_residual_analysis_config_id=?"
  179. err = o.Raw(sql, configId).QueryRow(&residualAnalysisConfig)
  180. return residualAnalysisConfig, nil
  181. }
  182. // UpdateResidualAnalysisConfig 更新配置信息
  183. func UpdateResidualAnalysisConfig(config CalculateResidualAnalysisConfig) (err error) {
  184. o := orm.NewOrmUsingDB("data")
  185. _, err = o.Update(&config)
  186. if err != nil {
  187. return err
  188. }
  189. return nil
  190. }
  191. // SaveResidualAnalysisConfig 保存配置信息
  192. func SaveResidualAnalysisConfig(config CalculateResidualAnalysisConfig) (id int64, err error) {
  193. o := orm.NewOrmUsingDB("data")
  194. id, err = o.Insert(&config)
  195. if err != nil {
  196. return 0, err
  197. }
  198. return id, nil
  199. }