constants.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. package utils
  2. import "time"
  3. // 常量定义
  4. const (
  5. FormatTime = "15:04:05" //时间格式
  6. FormatDate = "2006-01-02" //日期格式
  7. FormatDateUnSpace = "20060102" //日期格式
  8. FormatDateTime = "2006-01-02 15:04:05" //完整时间格式
  9. HlbFormatDateTime = "2006-01-02_15:04:05.999" //完整时间格式
  10. FormatDateTimeUnSpace = "20060102150405" //完整时间格式
  11. FormatShortDateTimeUnSpace = "060102150405" //省去开头两位年份的时间格式
  12. FormatYearMonthDate = "2006-01" //日期格式
  13. FormatYearMonthUnSpace = "200601" //年月的日期格式
  14. PageSize15 = 15 //列表页每页数据量
  15. PageSize5 = 5
  16. PageSize10 = 10
  17. PageSize20 = 20
  18. PageSize30 = 30
  19. )
  20. const (
  21. DATA_SOURCE_YONYI = 76 //涌益咨询
  22. DATA_SOURCE_FENWEI = 77 //汾渭煤炭
  23. )
  24. // 数据来源渠道
  25. const (
  26. DATA_SOURCE_THS = iota + 1 //同花顺
  27. DATA_SOURCE_WIND //wind
  28. DATA_SOURCE_PB //彭博
  29. DATA_SOURCE_CALCULATE //指标运算
  30. DATA_SOURCE_CALCULATE_LJZZY //累计值转月
  31. DATA_SOURCE_CALCULATE_TBZ //同比值
  32. DATA_SOURCE_CALCULATE_TCZ //同差值
  33. DATA_SOURCE_CALCULATE_NSZYDPJJS //N数值移动平均计算
  34. DATA_SOURCE_MANUAL //手工指标
  35. DATA_SOURCE_LZ //隆众
  36. DATA_SOURCE_YS //有色
  37. DATA_SOURCE_CALCULATE_HBZ //环比值->12
  38. DATA_SOURCE_CALCULATE_HCZ //环差值->13
  39. DATA_SOURCE_CALCULATE_BP //变频->14
  40. DATA_SOURCE_GL //钢联->15
  41. DATA_SOURCE_ZZ //郑商所->16
  42. DATA_SOURCE_DL //大商所->17
  43. DATA_SOURCE_SH //上期所->18
  44. DATA_SOURCE_CFFEX //中金所->19
  45. DATA_SOURCE_SHFE //上期能源->20
  46. DATA_SOURCE_GIE //欧洲天然气->21
  47. DATA_SOURCE_CALCULATE_TIME_SHIFT //时间移位->22
  48. DATA_SOURCE_CALCULATE_ZJPJ //直接拼接->23
  49. DATA_SOURCE_CALCULATE_LJZTBPJ //累计值同比拼接->24
  50. DATA_SOURCE_LT //路透->25
  51. DATA_SOURCE_COAL //煤炭网->26
  52. DATA_SOURCE_PYTHON //python代码->27
  53. DATA_SOURCE_PB_FINANCE //彭博财务数据->28
  54. DATA_SOURCE_GOOGLE_TRAVEL //谷歌出行数据->29
  55. DATA_SOURCE_PREDICT //普通预测指标->30
  56. DATA_SOURCE_PREDICT_CALCULATE //预测指标运算->31
  57. DATA_SOURCE_PREDICT_CALCULATE_TBZ //预测指标 - 同比值->32
  58. DATA_SOURCE_PREDICT_CALCULATE_TCZ //预测指标 - 同差值->33
  59. DATA_SOURCE_MYSTEEL_CHEMICAL //钢联化工->34
  60. DATA_SOURCE_CALCULATE_CJJX //超季节性->35
  61. DATA_SOURCE_EIA_STEO //eia steo报告->36
  62. DATA_SOURCE_CALCULATE_NHCC //计算指标(拟合残差)->37
  63. DATA_SOURCE_COM_TRADE //联合国商品贸易数据->38
  64. DATA_SOURCE_PREDICT_CALCULATE_NSZYDPJJS //预测指标 - N数值移动平均计算 -> 39
  65. DATA_SOURCE_CALCULATE_ADJUST //数据调整->40
  66. DATA_SOURCE_SCI //卓创数据(红桃三)->41
  67. DATA_SOURCE_PREDICT_CALCULATE_LJZZY //预测指标 - 累计值转月->42
  68. DATA_SOURCE_PREDICT_CALCULATE_HBZ //预测指标 - 环比值->43
  69. DATA_SOURCE_PREDICT_CALCULATE_HCZ //预测指标 - 环差值->44
  70. DATA_SOURCE_PREDICT_CALCULATE_BP //预测指标 - 变频->45
  71. DATA_SOURCE_PREDICT_CALCULATE_TIME_SHIFT //预测指标 - 时间移位->46
  72. DATA_SOURCE_PREDICT_CALCULATE_ZJPJ //预测指标 - 直接拼接->47
  73. DATA_SOURCE_PREDICT_CALCULATE_LJZTBPJ //预测指标 - 累计值同比拼接->48
  74. DATA_SOURCE_PREDICT_CALCULATE_CJJX //预测指标 - 超季节性->49
  75. DATA_SOURCE_PREDICT_CALCULATE_NHCC //预测指标 - 计算指标(拟合残差)->50
  76. DATA_SOURCE_CALCULATE_JP //降频->51
  77. DATA_SOURCE_CALCULATE_NH //年化->52
  78. DATA_SOURCE_CALCULATE_KSZS //扩散指数->53
  79. DATA_SOURCE_PREDICT_CALCULATE_JP //预测指标 - 计算指标(降频)->54
  80. DATA_SOURCE_PREDICT_CALCULATE_NH //预测指标 - 计算指标(年化)->55
  81. DATA_SOURCE_PREDICT_CALCULATE_KSZS //预测指标 - 计算指标(扩散指数)->56
  82. DATA_SOURCE_BAIINFO //百川盈孚 ->57
  83. DATA_SOURCE_STOCK_PLANT //存量装置 ->58
  84. DATA_SOURCE_CALCULATE_CORRELATION //相关性计算->59
  85. DATA_SOURCE_NATIONAL_STATISTICS //国家统计局->60
  86. DATA_SOURCE_CALCULATE_LJZZJ //累计值转季 -> 61
  87. DATA_SOURCE_CALCULATE_LJZ //累计值 -> 62
  88. DATA_SOURCE_CALCULATE_LJZNCZJ //累计值(年初至今) -> 63
  89. DATA_SOURCE_PREDICT_CALCULATE_LJZZJ //预测指标 - 累计值转季->64
  90. DATA_SOURCE_PREDICT_CALCULATE_LJZ //预测指标 - 累计值 -> 65
  91. DATA_SOURCE_PREDICT_CALCULATE_LJZNCZJ //预测指标 - 累计值(年初至今) -> 66
  92. DATA_SOURCE_CALCULATE_STANDARD_DEVIATION //标准差->67
  93. DATA_SOURCE_CALCULATE_PERCENTILE //百分位->68
  94. DATA_SOURCE_PREDICT_CALCULATE_STANDARD_DEVIATION //预测标准差->69
  95. DATA_SOURCE_PREDICT_CALCULATE_PERCENTILE //预测百分位->70
  96. DATA_SOURCE_FUBAO //富宝数据->71
  97. DATA_SOURCE_CALCULATE_ZSXY // 指数修匀->72
  98. DATA_SOURCE_PREDICT_CALCULATE_ZSXY // 预测指数修匀->73
  99. DATA_SOURCE_CALCULATE_ZDYFX // 自定义分析->74
  100. DATA_SOURCE_CALCULATE_RJZ // 日均值计算->75
  101. DATA_SOURCE_GFEX = 78 // 广州期货交易所->78
  102. DATA_SOURCE_ICPI = 79 // ICPI消费价格指数->79
  103. DATA_SOURCE_MTJH = 80 // 煤炭江湖->80
  104. DATA_SOURCE_CALCULATE_SUM = 81
  105. DATA_SOURCE_CALCULATE_AVG = 82
  106. )
  107. // 指标来源的中文展示
  108. const (
  109. DATA_SOURCE_NAME_THS = `同花顺` //同花顺
  110. DATA_SOURCE_NAME_WIND = `wind` //wind
  111. DATA_SOURCE_NAME_PB = `彭博` //彭博
  112. DATA_SOURCE_NAME_CALCULATE = `指标运算` //指标运算
  113. DATA_SOURCE_NAME_CALCULATE_LJZZY = `累计值转月值` //累计值转月
  114. DATA_SOURCE_NAME_CALCULATE_TBZ = `同比值` //同比值
  115. DATA_SOURCE_NAME_CALCULATE_TCZ = `同差值` //同差值
  116. DATA_SOURCE_NAME_CALCULATE_NSZYDPJJS = `N数值移动平均计算` //N数值移动平均计算
  117. DATA_SOURCE_NAME_MANUAL = `手工数据` //手工指标
  118. DATA_SOURCE_NAME_LZ = `隆众` //隆众
  119. DATA_SOURCE_NAME_YS = `SMM` //有色
  120. DATA_SOURCE_NAME_CALCULATE_HBZ = `环比值` //环比值->12
  121. DATA_SOURCE_NAME_CALCULATE_HCZ = `环差值` //环差值->13
  122. DATA_SOURCE_NAME_CALCULATE_BP = `升频` //变频,2023-2-10 13:56:01调整为"升频"->14
  123. DATA_SOURCE_NAME_GL = `钢联` //钢联->15
  124. DATA_SOURCE_NAME_ZZ = `郑商所` //郑商所->16
  125. DATA_SOURCE_NAME_DL = `大商所` //大商所->17
  126. DATA_SOURCE_NAME_SH = `上期所` //上期所->18
  127. DATA_SOURCE_NAME_CFFEX = `中金所` //中金所->19
  128. DATA_SOURCE_NAME_SHFE = `上期能源` //上期能源->20
  129. DATA_SOURCE_NAME_GIE = `欧洲天然气` //欧洲天然气->21
  130. DATA_SOURCE_NAME_CALCULATE_TIME_SHIFT = `时间移位` //时间移位->22
  131. DATA_SOURCE_NAME_CALCULATE_ZJPJ = `直接拼接` //直接拼接->23
  132. DATA_SOURCE_NAME_CALCULATE_LJZTBPJ = `累计值同比拼接` //累计值同比拼接->24
  133. DATA_SOURCE_NAME_LT = `路透` //路透->25
  134. DATA_SOURCE_NAME_COAL = `中国煤炭市场网` //中国煤炭市场网->26
  135. DATA_SOURCE_NAME_PYTHON = `代码运算` //python代码->27
  136. DATA_SOURCE_NAME_PB_FINANCE = `彭博财务` //彭博财务数据->28
  137. DATA_SOURCE_NAME_GOOGLE_TRAVEL = `our world in data` //谷歌出行数据->29
  138. DATA_SOURCE_NAME_PREDICT = `预测指标` //普通预测指标->30
  139. DATA_SOURCE_NAME_PREDICT_CALCULATE = `预测指标运算` //预测指标运算->31
  140. DATA_SOURCE_NAME_PREDICT_CALCULATE_TBZ = `预测同比` //预测指标 - 同比值->32
  141. DATA_SOURCE_NAME_PREDICT_CALCULATE_TCZ = `预测同差` //预测指标 - 同差值->33
  142. DATA_SOURCE_NAME_MYSTEEL_CHEMICAL = `钢联化工` //钢联化工->34
  143. DATA_SOURCE_NAME_CALCULATE_CJJX = `超季节性` //超季节性->35
  144. DATA_SOURCE_NAME_EIA_STEO = `EIA STERO报告` //eia stero报告->36
  145. DATA_SOURCE_NAME_CALCULATE_NHCC = `拟合残差` //计算指标(拟合残差)->37
  146. DATA_SOURCE_NAME_COM_TRADE = `UN` //联合国商品贸易数据->38
  147. DATA_SOURCE_NAME_PREDICT_CALCULATE_NSZYDPJJS = `预测N数值移动平均计算` //预测指标 - N数值移动平均计算 -> 39
  148. DATA_SOURCE_NAME_CALCULATE_ADJUST = `数据调整` //数据调整->40
  149. DATA_SOURCE_NAME_SCI = `SCI` //卓创数据(红桃三)->41
  150. DATA_SOURCE_NAME_PREDICT_CALCULATE_LJZZY = `预测累计值转月值` //预测指标 - 累计值转月->42
  151. DATA_SOURCE_NAME_PREDICT_CALCULATE_HBZ = `预测环比值` //预测指标 - 环比值->43
  152. DATA_SOURCE_NAME_PREDICT_CALCULATE_HCZ = `预测环差值` //预测指标 - 环差值->44
  153. DATA_SOURCE_NAME_PREDICT_CALCULATE_BP = `预测升频` //预测指标 - 升频->45
  154. DATA_SOURCE_NAME_PREDICT_CALCULATE_TIME_SHIFT = `预测时间移位` //预测指标 - 时间移位->46
  155. DATA_SOURCE_NAME_PREDICT_CALCULATE_ZJPJ = `预测直接拼接` //预测指标 - 直接拼接->47
  156. DATA_SOURCE_NAME_PREDICT_CALCULATE_LJZTBPJ = `预测累计值同比拼接` //预测指标 - 累计值同比拼接->48
  157. DATA_SOURCE_NAME_PREDICT_CALCULATE_CJJX = `预测超季节性` //预测指标 - 超季节性->49
  158. DATA_SOURCE_NAME_PREDICT_CALCULATE_NHCC = `预测拟合残差` //预测指标 - 计算指标(拟合残差)->50
  159. DATA_SOURCE_NAME_CALCULATE_JP = `降频` //降频->51
  160. DATA_SOURCE_NAME_CALCULATE_NH = `年化` //年化->52
  161. DATA_SOURCE_NAME_CALCULATE_KSZS = `扩散指数` //扩散指数->53
  162. DATA_SOURCE_NAME_PREDICT_CALCULATE_JP = `预测降频` //预测指标 - 计算指标(降频)->54
  163. DATA_SOURCE_NAME_PREDICT_CALCULATE_NH = `预测年化` //预测指标 - 计算指标(年化)->55
  164. DATA_SOURCE_NAME_PREDICT_CALCULATE_KSZS = `预测扩散指数` //预测指标 - 计算指标(扩散指数)->56
  165. DATA_SOURCE_NAME_BAIINFO = `百川盈孚` //百川盈孚 ->57
  166. DATA_SOURCE_NAME_STOCK_PLANT = `存量装置` //存量装置 ->58
  167. DATA_SOURCE_NAME_CALCULATE_CORRELATION = `相关性计算` //相关性计算->59
  168. DATA_SOURCE_NAME_NATIONAL_STATISTICS = `国家统计局` //国家统计局->60
  169. DATA_SOURCE_NAME_CALCULATE_LJZZJ = `累计值转季值` //累计值转季 -> 61
  170. DATA_SOURCE_NAME_CALCULATE_LJZ = `累计值` //累计值 -> 62
  171. DATA_SOURCE_NAME_CALCULATE_LJZNCZJ = `年初至今累计值` //累计值(年初至今) -> 63
  172. DATA_SOURCE_NAME_PREDICT_CALCULATE_LJZZJ = `预测累计值转季值` //预测指标 - 累计值转季->64
  173. DATA_SOURCE_NAME_PREDICT_CALCULATE_LJZ = `预测累计值` //预测指标 - 累计值 -> 65
  174. DATA_SOURCE_NAME_PREDICT_CALCULATE_LJZNCZJ = `预测年初至今累计值` //预测指标 - 累计值(年初至今) -> 66
  175. DATA_SOURCE_NAME_CALCULATE_STANDARD_DEVIATION = `标准差` //标准差->67
  176. DATA_SOURCE_NAME_CALCULATE_PERCENTILE = `百分位` //百分位->68
  177. DATA_SOURCE_NAME_PREDICT_CALCULATE_STANDARD_DEVIATION = `预测标准差` //预测标准差->69
  178. DATA_SOURCE_NAME_PREDICT_CALCULATE_PERCENTILE = `预测百分位` //预测百分位->70
  179. DATA_SOURCE_NAME_FUBAO = `富宝数据` //富宝数据->71
  180. DATA_SOURCE_NAME_CALCULATE_ZSXY = `指数修匀` //指数修匀->72
  181. DATA_SOURCE_NAME_PREDICT_CALCULATE_ZSXY = `预测指数修匀` //预测指数修匀->73
  182. DATA_SOURCE_NAME_CALCULATE_ZDYFX = `自定义分析` //自定义分析->74
  183. DATA_SOURCE_NAME_YONYI = `涌益咨询` // 涌益咨询
  184. DATA_SOURCE_NAME_FENWEI = `汾渭数据` // 汾渭煤炭
  185. DATA_SOURCE_NAME_MTJH = `煤炭江湖` // 煤炭江湖->80
  186. DATA_SOURCE_NAME_ICPI = "ICPI消费价格指数"
  187. DATA_SOURCE_NAME_CALCULATE_SUM = `多指标求和`
  188. DATA_SOURCE_NAME_CALCULATE_AVG = `多指标求平均`
  189. )
  190. // 基础数据初始化日期
  191. var (
  192. BASE_START_DATE = time.Now().AddDate(-30, 0, 0).Format(FormatDate) //基础数据开始日期
  193. BASE_END_DATE = time.Now().AddDate(4, 0, 0).Format(FormatDate) //基础数据结束日期
  194. BASE_START_DATE_UnSpace = time.Now().AddDate(-30, 0, 0).Format(FormatDateUnSpace) //基础数据开始日期
  195. BASE_END_DATE_UnSpace = time.Now().AddDate(4, 0, 0).Format(FormatDateUnSpace) //基础数据结束日期
  196. )
  197. const (
  198. DATA_PREFIX = "hz_data"
  199. CHART_PREFIX = "hz_chart"
  200. )
  201. // 数据刷新频率
  202. const (
  203. DATA_REFRESH = 7 //7个单位,日/周/月/季度/年
  204. DATA_END_DATE_LIMIT = 4 //数据结束日期为,当前日期,加上4年时间
  205. )
  206. const (
  207. CACHE_EDB_DATA_ADD = "CACHE_EDB_DATA_ADD_"
  208. CACHE_EDB_DATA_REFRESH = "CACHE_EDB_DATA_REFRESH_"
  209. CACHE_WIND_URL = "CACHE_WIND_URL"
  210. CACHE_CHART_INFO_DATA = "chart:info:data:" //图表数据
  211. CACHE_STOCK_PLANT_CALCULATE = "CACHE_STOCK_PLANT_CALCULATE_" // 库存装置减产计算
  212. CACHE_EDB_TERMINAL_CODE_URL = "edb:terminal_code:edb_code:" // 指标与终端关系的缓存
  213. CACHE_EDB_TERMINAL_CODE_GOOD_URL = "edb:terminal_code:good:edb_code:" // 指标与终端关系的缓存, 商品期货
  214. CACHE_EDB_THS_SERVER_TOKEN = "edb:ths_server_token:" //同花顺调用凭证
  215. )
  216. // 图表类型
  217. const (
  218. CHART_SOURCE_DEFAULT = 1
  219. CHART_SOURCE_FUTURE_GOOD = 2
  220. CHART_SOURCE_CORRELATION = 3 // 相关性图表
  221. CHART_SOURCE_ROLLING_CORRELATION = 4 // 滚动相关性图表
  222. CHART_SOURCE_FUTURE_GOOD_PROFIT = 5 // 商品利润曲线
  223. )
  224. // MonthQuarterMap 月份与季度的map
  225. var MonthQuarterMap = map[int]int{
  226. 1: 1,
  227. 2: 1,
  228. 3: 1,
  229. 4: 2,
  230. 5: 2,
  231. 6: 2,
  232. 7: 3,
  233. 8: 3,
  234. 9: 3,
  235. 10: 4,
  236. 11: 4,
  237. 12: 4,
  238. }
  239. // FrequencyDaysMap 频度日期的map关系
  240. var FrequencyDaysMap = map[string]int{
  241. "天": 1, "周": 7, "月": 30, "季": 90, "年": 365,
  242. }
  243. var (
  244. HZ_TRIAL_BUSSINESS_CODE = "E2023080700" //商家试用平台
  245. )
  246. // 指标类型:1:基础指标,2:计算指标
  247. const (
  248. DEFAULT_EDB_TYPE = 1 //基础指标
  249. CALCULATE_EDB_TYPE = 2 //计算指标
  250. )
  251. // ETA表格
  252. const (
  253. EXCEL_DEFAULT = 1 // 自定义excel
  254. TIME_TABLE = 2 // 时间序列表格
  255. MIXED_TABLE = 3 // 混合表格
  256. CUSTOM_ANALYSIS_TABLE = 4 // 自定义分析表格
  257. )
  258. // 子数据来源渠道
  259. const (
  260. DATA_SUB_SOURCE_EDB = iota //经济数据库
  261. DATA_SUB_SOURCE_DATE //日期序列
  262. )