123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- package models
- import (
- "eta/eta_chart_lib/utils"
- "time"
- )
- // HandleDataByPreviousData 当前日期无值时,用上一个日期的数据补充当前日期的数据
- func HandleDataByPreviousData(edbInfoDataList []*EdbDataList, handleDataMap map[string]float64) (err error) {
- if len(edbInfoDataList) < 2 {
- return
- }
- var startEdbInfoData *EdbDataList
- for _, v := range edbInfoDataList {
- handleDataMap[v.DataTime] = v.Value
- // 第一个数据就给过滤了,给后面的试用
- if startEdbInfoData == nil {
- startEdbInfoData = v
- continue
- }
- // 获取两条数据之间相差的天数
- startDataTime, _ := time.ParseInLocation(utils.FormatDate, startEdbInfoData.DataTime, time.Local)
- currDataTime, _ := time.ParseInLocation(utils.FormatDate, v.DataTime, time.Local)
- betweenHour := int(currDataTime.Sub(startDataTime).Hours())
- betweenDay := betweenHour / 24
- // 如果相差一天,那么过滤
- if betweenDay <= 1 {
- startEdbInfoData = v
- continue
- }
- // 生成对应的值
- {
- for i := 1; i < betweenDay; i++ {
- tmpDataTime := startDataTime.AddDate(0, 0, i)
- handleDataMap[tmpDataTime.Format(utils.FormatDate)] = startEdbInfoData.Value
- }
- }
- startEdbInfoData = v
- }
- return
- }
|