handle_data.go 966 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package models
  2. import (
  3. "eta_gn/eta_chart_lib/utils"
  4. "time"
  5. )
  6. func HandleDataByPreviousData(edbInfoDataList []*EdbDataList, handleDataMap map[string]float64) (err error) {
  7. if len(edbInfoDataList) < 2 {
  8. return
  9. }
  10. var startEdbInfoData *EdbDataList
  11. for _, v := range edbInfoDataList {
  12. handleDataMap[v.DataTime] = v.Value
  13. if startEdbInfoData == nil {
  14. startEdbInfoData = v
  15. continue
  16. }
  17. startDataTime, _ := time.ParseInLocation(utils.FormatDate, startEdbInfoData.DataTime, time.Local)
  18. currDataTime, _ := time.ParseInLocation(utils.FormatDate, v.DataTime, time.Local)
  19. betweenHour := int(currDataTime.Sub(startDataTime).Hours())
  20. betweenDay := betweenHour / 24
  21. if betweenDay <= 1 {
  22. startEdbInfoData = v
  23. continue
  24. }
  25. {
  26. for i := 1; i < betweenDay; i++ {
  27. tmpDataTime := startDataTime.AddDate(0, 0, i)
  28. handleDataMap[tmpDataTime.Format(utils.FormatDate)] = startEdbInfoData.Value
  29. }
  30. }
  31. startEdbInfoData = v
  32. }
  33. return
  34. }