predict_edb_info.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. package chart
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "github.com/shopspring/decimal"
  6. edbDataModel "hongze/hongze_yb/models/tables/edb_data"
  7. edbInfoModel "hongze/hongze_yb/models/tables/edb_info"
  8. predictEdbConfModel "hongze/hongze_yb/models/tables/predict_edb_conf"
  9. predictEdbRuleDataModel "hongze/hongze_yb/models/tables/predict_edb_rule_data"
  10. "hongze/hongze_yb/utils"
  11. "strconv"
  12. "time"
  13. )
  14. // GetChartPredictEdbInfoDataList 获取图表的预测指标的未来数据
  15. func GetChartPredictEdbInfoDataList(predictEdbConf predictEdbConfModel.PredictEdbConf, filtrateStartDateStr, latestDateStr string, lastDataValue float64, endDateStr, frequency string) (predictEdbInfoData []*edbDataModel.EdbDataList, err error) {
  16. endDate, err := time.ParseInLocation(utils.FormatDate, endDateStr, time.Local)
  17. if err != nil {
  18. return
  19. }
  20. latestDate, err := time.ParseInLocation(utils.FormatDate, latestDateStr, time.Local)
  21. if err != nil {
  22. return
  23. }
  24. // 开始预测数据的时间
  25. startDate := latestDate
  26. // 如果有筛选时间的话
  27. if filtrateStartDateStr != `` {
  28. filtrateStartDate, tmpErr := time.ParseInLocation(utils.FormatDate, filtrateStartDateStr, time.Local)
  29. if tmpErr != nil {
  30. err = tmpErr
  31. return
  32. }
  33. //如果筛选时间晚于实际数据时间,那么就以筛选时间作为获取预测数据的时间
  34. if filtrateStartDate.After(latestDate) {
  35. startDate = filtrateStartDate.AddDate(0, 0, -1)
  36. }
  37. }
  38. dataValue := lastDataValue
  39. if predictEdbConf.RuleType == 2 {
  40. dataValue = predictEdbConf.FixedValue
  41. }
  42. //获取后面的预测数据
  43. dayList := getPredictEdbDayList(startDate, endDate, frequency)
  44. predictEdbInfoData = make([]*edbDataModel.EdbDataList, 0)
  45. for k, v := range dayList {
  46. predictEdbInfoData = append(predictEdbInfoData, &edbDataModel.EdbDataList{
  47. EdbDataId: int(predictEdbConf.PredictEdbInfoID) + 10000000000 + k,
  48. EdbInfoId: int(predictEdbConf.PredictEdbInfoID),
  49. DataTime: v.Format(utils.FormatDate),
  50. Value: dataValue,
  51. DataTimestamp: v.UnixNano() / 1e6,
  52. })
  53. }
  54. return
  55. }
  56. // GetChartPredictEdbInfoDataListByConfList 获取图表的预测指标的未来数据
  57. func GetChartPredictEdbInfoDataListByConfList(predictEdbConfList []*predictEdbConfModel.PredictEdbConf, filtrateStartDateStr, latestDateStr, endDateStr, frequency string, realPredictEdbInfoData []*edbDataModel.EdbDataList) (predictEdbInfoData []*edbDataModel.EdbDataList, minValue, maxValue float64, err error) {
  58. endDate, err := time.ParseInLocation(utils.FormatDate, endDateStr, time.Local)
  59. if err != nil {
  60. return
  61. }
  62. latestDate, err := time.ParseInLocation(utils.FormatDate, latestDateStr, time.Local)
  63. if err != nil {
  64. return
  65. }
  66. // 开始预测数据的时间
  67. startDate := latestDate
  68. // 如果有筛选时间的话
  69. if filtrateStartDateStr != `` {
  70. filtrateStartDate, tmpErr := time.ParseInLocation(utils.FormatDate, filtrateStartDateStr, time.Local)
  71. if tmpErr != nil {
  72. err = tmpErr
  73. return
  74. }
  75. //如果筛选时间晚于实际数据时间,那么就以筛选时间作为获取预测数据的时间
  76. if filtrateStartDate.After(latestDate) {
  77. startDate = filtrateStartDate.AddDate(0, 0, -1)
  78. }
  79. }
  80. //var dateArr []string
  81. // 对应日期的值
  82. existMap := make(map[string]float64)
  83. for _, v := range realPredictEdbInfoData {
  84. //dateArr = append(dateArr, v.DataTime)
  85. existMap[v.DataTime] = v.Value
  86. }
  87. predictEdbInfoData = make([]*edbDataModel.EdbDataList, 0)
  88. //dataValue := lastDataValue
  89. //预测规则,1:最新,2:固定值,3:同比,4:同差,5:环比,6:环差,7:N期移动均值,8:N期段线性外推值
  90. for _, predictEdbConf := range predictEdbConfList {
  91. dataEndTime := endDate
  92. if predictEdbConf.EndDate.Before(dataEndTime) {
  93. dataEndTime = predictEdbConf.EndDate
  94. }
  95. var tmpMinValue, tmpMaxValue float64 // 当前预测结果中的最大/最小值
  96. dayList := getPredictEdbDayList(startDate, dataEndTime, frequency)
  97. if len(dayList) <= 0 { // 如果未来没有日期的话,那么就退出当前循环,进入下一个循环
  98. continue
  99. }
  100. switch predictEdbConf.RuleType {
  101. case 1: //1:最新
  102. var lastDataValue float64 //最新值
  103. tmpAllData := make([]*edbDataModel.EdbDataList, 0)
  104. tmpAllData = append(tmpAllData, realPredictEdbInfoData...)
  105. tmpAllData = append(tmpAllData, predictEdbInfoData...)
  106. lenTmpAllData := len(tmpAllData)
  107. if lenTmpAllData > 0 {
  108. lastDataValue = tmpAllData[lenTmpAllData-1].Value
  109. }
  110. predictEdbInfoData = GetChartPredictEdbInfoDataListByRule1(int(predictEdbConf.PredictEdbInfoID), lastDataValue, startDate, dataEndTime, frequency, predictEdbInfoData, existMap)
  111. tmpMaxValue = lastDataValue
  112. tmpMinValue = lastDataValue
  113. case 2: //2:固定值
  114. tmpValDecimal, tmpErr := decimal.NewFromString(predictEdbConf.Value)
  115. if tmpErr != nil {
  116. err = tmpErr
  117. return
  118. }
  119. dataValue, _ := tmpValDecimal.Float64()
  120. predictEdbInfoData = GetChartPredictEdbInfoDataListByRule1(int(predictEdbConf.PredictEdbInfoID), dataValue, startDate, dataEndTime, frequency, predictEdbInfoData, existMap)
  121. tmpMaxValue = dataValue
  122. tmpMinValue = dataValue
  123. case 3: //3:同比
  124. tmpValDecimal, tmpErr := decimal.NewFromString(predictEdbConf.Value)
  125. if tmpErr != nil {
  126. err = tmpErr
  127. return
  128. }
  129. tbValue, _ := tmpValDecimal.Float64()
  130. predictEdbInfoData, tmpMinValue, tmpMaxValue = GetChartPredictEdbInfoDataListByRuleTb(int(predictEdbConf.PredictEdbInfoID), tbValue, startDate, dataEndTime, frequency, realPredictEdbInfoData, predictEdbInfoData, existMap)
  131. case 4: //4:同差
  132. tmpValDecimal, tmpErr := decimal.NewFromString(predictEdbConf.Value)
  133. if tmpErr != nil {
  134. err = tmpErr
  135. return
  136. }
  137. tcValue, _ := tmpValDecimal.Float64()
  138. predictEdbInfoData, tmpMinValue, tmpMaxValue = GetChartPredictEdbInfoDataListByRuleTc(int(predictEdbConf.PredictEdbInfoID), tcValue, startDate, dataEndTime, frequency, realPredictEdbInfoData, predictEdbInfoData, existMap)
  139. case 5: //5:环比
  140. tmpValDecimal, tmpErr := decimal.NewFromString(predictEdbConf.Value)
  141. if tmpErr != nil {
  142. err = tmpErr
  143. return
  144. }
  145. hbValue, _ := tmpValDecimal.Float64()
  146. predictEdbInfoData, tmpMinValue, tmpMaxValue = GetChartPredictEdbInfoDataListByRuleHb(int(predictEdbConf.PredictEdbInfoID), hbValue, startDate, dataEndTime, frequency, realPredictEdbInfoData, predictEdbInfoData, existMap)
  147. case 6: //6:环差
  148. tmpValDecimal, tmpErr := decimal.NewFromString(predictEdbConf.Value)
  149. if tmpErr != nil {
  150. err = tmpErr
  151. return
  152. }
  153. hcValue, _ := tmpValDecimal.Float64()
  154. predictEdbInfoData, tmpMinValue, tmpMaxValue = GetChartPredictEdbInfoDataListByRuleHc(int(predictEdbConf.PredictEdbInfoID), hcValue, startDate, dataEndTime, frequency, realPredictEdbInfoData, predictEdbInfoData, existMap)
  155. case 7: //7:N期移动均值
  156. nValue, tmpErr := strconv.Atoi(predictEdbConf.Value)
  157. if tmpErr != nil {
  158. err = tmpErr
  159. return
  160. }
  161. predictEdbInfoData, tmpMinValue, tmpMaxValue = GetChartPredictEdbInfoDataListByRuleNMoveMeanValue(int(predictEdbConf.PredictEdbInfoID), nValue, startDate, dataEndTime, frequency, realPredictEdbInfoData, predictEdbInfoData, existMap)
  162. case 8: //8:N期段线性外推值
  163. nValue, tmpErr := strconv.Atoi(predictEdbConf.Value)
  164. if tmpErr != nil {
  165. err = tmpErr
  166. return
  167. }
  168. predictEdbInfoData, tmpMinValue, tmpMaxValue, err = GetChartPredictEdbInfoDataListByRuleNLinearRegression(int(predictEdbConf.PredictEdbInfoID), nValue, startDate, dataEndTime, frequency, realPredictEdbInfoData, predictEdbInfoData, existMap)
  169. if err != nil {
  170. return
  171. }
  172. case 9: //9:动态环差”预测规则;
  173. predictEdbInfoData, tmpMinValue, tmpMaxValue = GetChartPredictEdbInfoDataListByRuleTrendsHC(int(predictEdbConf.PredictEdbInfoID), int(predictEdbConf.ConfigID), startDate, dataEndTime, frequency, realPredictEdbInfoData, predictEdbInfoData, existMap)
  174. case 10: //10:根据 给定终值后插值 规则获取预测数据
  175. tmpValDecimal, tmpErr := decimal.NewFromString(predictEdbConf.Value)
  176. if tmpErr != nil {
  177. err = tmpErr
  178. return
  179. }
  180. finalValue, _ := tmpValDecimal.Float64()
  181. predictEdbInfoData, tmpMinValue, tmpMaxValue = GetChartPredictEdbInfoDataListByRuleFinalValueHc(int(predictEdbConf.PredictEdbInfoID), finalValue, startDate, dataEndTime, frequency, realPredictEdbInfoData, predictEdbInfoData, existMap)
  182. case 11: //11:根据 季节性 规则获取预测数据
  183. var seasonConf SeasonConf
  184. tmpErr := json.Unmarshal([]byte(predictEdbConf.Value), &seasonConf)
  185. if tmpErr != nil {
  186. err = errors.New("季节性配置信息异常:" + tmpErr.Error())
  187. return
  188. }
  189. calendar := "公历"
  190. if seasonConf.Calendar == "农历" {
  191. calendar = "农历"
  192. }
  193. yearList := make([]int, 0)
  194. //选择方式,1:连续N年;2:指定年份
  195. if seasonConf.YearType == 1 {
  196. if seasonConf.NValue < 1 {
  197. err = errors.New("连续N年不允许小于1")
  198. return
  199. }
  200. currYear := time.Now().Year()
  201. for i := 0; i < seasonConf.NValue; i++ {
  202. yearList = append(yearList, currYear-i-1)
  203. }
  204. } else {
  205. yearList = seasonConf.YearList
  206. }
  207. predictEdbInfoData, tmpMinValue, tmpMaxValue, err = GetChartPredictEdbInfoDataListByRuleSeason(int(predictEdbConf.PredictEdbInfoID), yearList, calendar, startDate, dataEndTime, frequency, realPredictEdbInfoData, predictEdbInfoData, existMap)
  208. if err != nil {
  209. return
  210. }
  211. case 12: //12:根据 移动平均同比 规则获取预测数据
  212. var moveAverageConf MoveAverageConf
  213. tmpErr := json.Unmarshal([]byte(predictEdbConf.Value), &moveAverageConf)
  214. if tmpErr != nil {
  215. err = errors.New("季节性配置信息异常:" + tmpErr.Error())
  216. return
  217. }
  218. predictEdbInfoData, tmpMinValue, tmpMaxValue, err = GetChartPredictEdbInfoDataListByRuleMoveAverageTb(int(predictEdbConf.PredictEdbInfoID), moveAverageConf.NValue, moveAverageConf.Year, startDate, dataEndTime, frequency, realPredictEdbInfoData, predictEdbInfoData, existMap)
  219. if err != nil {
  220. return
  221. }
  222. case 13: //13:根据 同比增速差值 规则获取预测数据
  223. tmpValDecimal, tmpErr := decimal.NewFromString(predictEdbConf.Value)
  224. if tmpErr != nil {
  225. err = tmpErr
  226. return
  227. }
  228. tbEndValue, _ := tmpValDecimal.Float64()
  229. predictEdbInfoData, tmpMinValue, tmpMaxValue = GetChartPredictEdbInfoDataListByRuleTbzscz(int(predictEdbConf.PredictEdbInfoID), tbEndValue, dayList, frequency, realPredictEdbInfoData, predictEdbInfoData, existMap)
  230. case 14: //14:根据 一元线性拟合 规则获取预测数据
  231. var ruleConf RuleLineNhConf
  232. err = json.Unmarshal([]byte(predictEdbConf.Value), &ruleConf)
  233. if err != nil {
  234. err = errors.New("一元线性拟合配置信息异常:" + err.Error())
  235. return
  236. }
  237. // 规则计算的拟合残差值map
  238. newNhccDataMap := make(map[string]float64)
  239. if predictEdbConf.PredictEdbInfoID > 0 { //已经生成的动态数据
  240. tmpPredictEdbRuleDataList, tmpErr := predictEdbRuleDataModel.GetPredictEdbRuleDataList(int(predictEdbConf.PredictEdbInfoID), int(predictEdbConf.ConfigID), "", "")
  241. if tmpErr != nil {
  242. err = tmpErr
  243. return
  244. }
  245. for _, v := range tmpPredictEdbRuleDataList {
  246. newNhccDataMap[v.DataTime.Format(utils.FormatDate)] = v.Value
  247. }
  248. } else { //未生成的动态数据,需要使用外部传入的数据进行计算
  249. newNhccDataMap, err = getCalculateNhccData(append(realPredictEdbInfoData, predictEdbInfoData...), ruleConf)
  250. if err != nil {
  251. return
  252. }
  253. }
  254. predictEdbInfoData, tmpMinValue, tmpMaxValue, err = GetChartPredictEdbInfoDataListByRuleLineNh(int(predictEdbConf.PredictEdbInfoID), dayList, realPredictEdbInfoData, predictEdbInfoData, newNhccDataMap, existMap)
  255. if err != nil {
  256. return
  257. }
  258. case 15: //15:N年均值:过去N年同期均值。过去N年可以连续或者不连续,指标数据均用线性插值补全为日度数据后计算;
  259. predictEdbInfoData, tmpMinValue, tmpMaxValue, err = GetChartPredictEdbInfoDataListByRuleNAnnualAverage(int(predictEdbConf.PredictEdbInfoID), predictEdbConf.Value, dayList, realPredictEdbInfoData, predictEdbInfoData, existMap)
  260. if err != nil {
  261. return
  262. }
  263. case 16: //16:年度值倒推
  264. predictEdbInfoData, tmpMinValue, tmpMaxValue, err = GetChartPredictEdbInfoDataListByRuleAnnualValueInversion(int(predictEdbConf.PredictEdbInfoID), predictEdbConf.Value, dayList, frequency, realPredictEdbInfoData, predictEdbInfoData, existMap)
  265. if err != nil {
  266. return
  267. }
  268. }
  269. // 下一个规则的开始日期
  270. {
  271. lenPredictEdbInfoData := len(predictEdbInfoData)
  272. if lenPredictEdbInfoData > 0 {
  273. tmpDataEndTime, _ := time.ParseInLocation(utils.FormatDate, predictEdbInfoData[lenPredictEdbInfoData-1].DataTime, time.Local)
  274. if startDate.Before(tmpDataEndTime) {
  275. startDate = tmpDataEndTime
  276. }
  277. }
  278. }
  279. if tmpMinValue < minValue {
  280. minValue = tmpMinValue
  281. }
  282. if tmpMaxValue < maxValue {
  283. maxValue = tmpMaxValue
  284. }
  285. }
  286. return
  287. }
  288. // GetPredictEdbDayList 获取预测指标日期列表
  289. func getPredictEdbDayList(startDate, endDate time.Time, frequency string) (dayList []time.Time) {
  290. //if !utils.InArrayByStr([]string{"日度", "周度", "月度"}, frequency)
  291. switch frequency {
  292. case "日度":
  293. for currDate := startDate.AddDate(0, 0, 1); currDate.Before(endDate) || currDate.Equal(endDate); currDate = currDate.AddDate(0, 0, 1) {
  294. //周六、日排除
  295. if currDate.Weekday() == time.Sunday || currDate.Weekday() == time.Saturday {
  296. continue
  297. }
  298. dayList = append(dayList, currDate)
  299. }
  300. case "周度":
  301. //nextDate := startDate.AddDate(0, 0, 7)
  302. for currDate := startDate.AddDate(0, 0, 7); currDate.Before(endDate) || currDate.Equal(endDate); currDate = currDate.AddDate(0, 0, 7) {
  303. dayList = append(dayList, currDate)
  304. }
  305. case "旬度":
  306. for currDate := startDate.AddDate(0, 0, 1); currDate.Before(endDate) || currDate.Equal(endDate); {
  307. nextDate := currDate.AddDate(0, 0, 1)
  308. //每个月的10号、20号、最后一天,那么就写入
  309. if nextDate.Day() == 11 || nextDate.Day() == 21 || nextDate.Day() == 1 {
  310. dayList = append(dayList, currDate)
  311. }
  312. currDate = nextDate
  313. }
  314. case "月度":
  315. for currDate := startDate; currDate.Before(endDate) || currDate.Equal(endDate); {
  316. currDate = time.Date(currDate.Year(), currDate.Month(), 1, 0, 0, 0, 0, time.Now().Location()).AddDate(0, 1, -1)
  317. if !currDate.After(endDate) && !currDate.Equal(startDate) {
  318. dayList = append(dayList, currDate)
  319. }
  320. currDate = currDate.AddDate(0, 0, 1)
  321. }
  322. case "季度":
  323. for currDate := startDate; currDate.Before(endDate) || currDate.Equal(endDate); {
  324. // 每月的最后一天
  325. currDate = time.Date(currDate.Year(), currDate.Month(), 1, 0, 0, 0, 0, time.Now().Location()).AddDate(0, 1, -1)
  326. if !currDate.After(endDate) && !currDate.Equal(startDate) {
  327. // 季度日期就写入,否则不写入
  328. if currDate.Month() == 3 || currDate.Month() == 6 || currDate.Month() == 9 || currDate.Month() == 12 {
  329. dayList = append(dayList, currDate)
  330. }
  331. }
  332. currDate = currDate.AddDate(0, 0, 1)
  333. }
  334. case "半年度":
  335. for currDate := startDate; currDate.Before(endDate) || currDate.Equal(endDate); {
  336. // 每月的最后一天
  337. currDate = time.Date(currDate.Year(), currDate.Month(), 1, 0, 0, 0, 0, time.Now().Location()).AddDate(0, 1, -1)
  338. if !currDate.After(endDate) && !currDate.Equal(startDate) {
  339. // 半年度日期就写入,否则不写入
  340. if currDate.Month() == 6 || currDate.Month() == 12 {
  341. dayList = append(dayList, currDate)
  342. }
  343. }
  344. currDate = currDate.AddDate(0, 0, 1)
  345. }
  346. case "年度":
  347. for currDate := startDate; currDate.Before(endDate) || currDate.Equal(endDate); {
  348. currDate = time.Date(currDate.Year()+1, 12, 31, 0, 0, 0, 0, time.Now().Location())
  349. if !currDate.After(endDate) && !currDate.Equal(startDate) {
  350. dayList = append(dayList, currDate)
  351. }
  352. }
  353. }
  354. return
  355. }
  356. // GetPredictDataListByPredictEdbInfoId 根据预测指标id获取预测指标的数据
  357. func GetPredictDataListByPredictEdbInfoId(edbInfoId int, startDate, endDate string, isTimeBetween bool) (edbInfo *edbInfoModel.EdbInfo, dataList []*edbDataModel.EdbDataList, sourceEdbInfoItem *edbInfoModel.EdbInfo, predictEdbConf *predictEdbConfModel.PredictEdbConf, err error, errMsg string) {
  358. edbInfo, err = edbInfoModel.GetEdbInfoById(edbInfoId)
  359. if err != nil {
  360. errMsg = `获取预测指标信息失败`
  361. return
  362. }
  363. dataList, sourceEdbInfoItem, predictEdbConf, err, errMsg = GetPredictDataListByPredictEdbInfo(edbInfo, startDate, endDate, isTimeBetween)
  364. return
  365. }
  366. // GetPredictDataListByPredictEdbInfo 根据预测指标信息获取预测指标的数据
  367. func GetPredictDataListByPredictEdbInfo(edbInfo *edbInfoModel.EdbInfo, startDate, endDate string, isTimeBetween bool) (dataList []*edbDataModel.EdbDataList, sourceEdbInfoItem *edbInfoModel.EdbInfo, predictEdbConf *predictEdbConfModel.PredictEdbConf, err error, errMsg string) {
  368. // 非计算指标,直接从表里获取数据
  369. if edbInfo.EdbType != 1 {
  370. if !isTimeBetween {
  371. endDate = ``
  372. }
  373. return GetPredictCalculateDataListByPredictEdbInfo(edbInfo, startDate, endDate)
  374. }
  375. // 查找该预测指标配置
  376. predictEdbConfList, err := predictEdbConfModel.GetPredictEdbConfListById(edbInfo.EdbInfoId)
  377. if err != nil {
  378. errMsg = "获取预测指标配置信息失败"
  379. return
  380. }
  381. if len(predictEdbConfList) == 0 {
  382. errMsg = "获取预测指标配置信息失败"
  383. err = errors.New(errMsg)
  384. return
  385. }
  386. predictEdbConf = predictEdbConfList[0]
  387. // 来源指标
  388. sourceEdbInfoItem, err = edbInfoModel.GetEdbInfoById(int(predictEdbConf.SourceEdbInfoID))
  389. if err != nil {
  390. if err == utils.ErrNoRow {
  391. errMsg = "找不到来源指标信息"
  392. err = errors.New(errMsg)
  393. }
  394. return
  395. }
  396. allDataList := make([]*edbDataModel.EdbDataList, 0)
  397. //获取指标数据(实际已生成)
  398. dataList, err = edbDataModel.GetEdbDataList(sourceEdbInfoItem.Source, sourceEdbInfoItem.EdbInfoId, startDate, endDate)
  399. if err != nil {
  400. return
  401. }
  402. // 如果选择了日期,那么需要筛选所有的数据,用于未来指标的生成
  403. if startDate != `` {
  404. allDataList, err = edbDataModel.GetEdbDataList(sourceEdbInfoItem.Source, sourceEdbInfoItem.EdbInfoId, "", "")
  405. if err != nil {
  406. return
  407. }
  408. } else {
  409. allDataList = dataList
  410. }
  411. // 获取预测指标未来的数据
  412. predictDataList := make([]*edbDataModel.EdbDataList, 0)
  413. endDateStr := edbInfo.EndDate.Format(utils.FormatDate) //预测指标的结束日期
  414. if isTimeBetween { //如果是时间区间,那么
  415. reqEndDateTime, _ := time.ParseInLocation(utils.FormatDate, endDate, time.Local)
  416. // 如果选择的时间区间结束日期 晚于 当天,那么预测数据截止到当天
  417. if reqEndDateTime.Before(edbInfo.EndDate) {
  418. endDateStr = endDate
  419. }
  420. }
  421. //predictDataList, err = GetChartPredictEdbInfoDataList(*predictEdbConf, startDate, sourceEdbInfoItem.LatestDate.Format(utils.FormatDate), sourceEdbInfoItem.LatestValue, endDateStr, edbInfo.Frequency)
  422. var predictMinValue, predictMaxValue float64
  423. predictDataList, predictMinValue, predictMaxValue, err = GetChartPredictEdbInfoDataListByConfList(predictEdbConfList, startDate, sourceEdbInfoItem.LatestDate.Format(utils.FormatDate), endDateStr, edbInfo.Frequency, allDataList)
  424. if err != nil {
  425. return
  426. }
  427. dataList = append(dataList, predictDataList...)
  428. if len(predictDataList) > 0 {
  429. // 如果最小值 大于 预测值,那么将预测值作为最小值数据返回
  430. if edbInfo.MinValue > predictMinValue {
  431. edbInfo.MinValue = predictMinValue
  432. }
  433. // 如果最大值 小于 预测值,那么将预测值作为最大值数据返回
  434. if edbInfo.MaxValue < predictMaxValue {
  435. edbInfo.MaxValue = predictMaxValue
  436. }
  437. }
  438. return
  439. }
  440. // GetPredictCalculateDataListByPredictEdbInfo 根据预测运算指标信息获取预测指标的数据
  441. func GetPredictCalculateDataListByPredictEdbInfo(edbInfo *edbInfoModel.EdbInfo, startDate, endDate string) (dataList []*edbDataModel.EdbDataList, sourceEdbInfoItem *edbInfoModel.EdbInfo, predictEdbConf *predictEdbConfModel.PredictEdbConf, err error, errMsg string) {
  442. dataList, err = edbDataModel.GetEdbDataList(edbInfo.Source, edbInfo.EdbInfoId, startDate, endDate)
  443. return
  444. }