|
@@ -1,549 +1,510 @@
|
|
|
package models
|
|
|
|
|
|
-import (
|
|
|
- "encoding/json"
|
|
|
- "errors"
|
|
|
- "fmt"
|
|
|
- "github.com/beego/beego/v2/client/orm"
|
|
|
- "github.com/shopspring/decimal"
|
|
|
- "hongze/hongze_edb_lib/utils"
|
|
|
- "strconv"
|
|
|
- "strings"
|
|
|
- "time"
|
|
|
-)
|
|
|
-
|
|
|
-
|
|
|
-func AddCalculateCorrelation(req *EdbInfoCalculateBatchSaveReq, edbCode, uniqueCode string, sysUserId int, sysUserRealName string) (edbInfo *EdbInfo, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
- to, err := o.Begin()
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- defer func() {
|
|
|
- if err != nil {
|
|
|
- fmt.Println("AddCalculateCorrelation,Err:" + err.Error())
|
|
|
- _ = to.Rollback()
|
|
|
- } else {
|
|
|
- _ = to.Commit()
|
|
|
- }
|
|
|
- }()
|
|
|
- if req.EdbInfoId > 0 {
|
|
|
- err = errors.New("无法新增")
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- edbInfo = new(EdbInfo)
|
|
|
- edbInfo.Source = utils.DATA_SOURCE_CALCULATE_CORRELATION
|
|
|
- edbInfo.SourceName = utils.DATA_SOURCE_NAME_CALCULATE_CORRELATION
|
|
|
- edbInfo.EdbCode = edbCode
|
|
|
- edbInfo.EdbName = req.EdbName
|
|
|
- edbInfo.EdbNameSource = req.EdbName
|
|
|
- edbInfo.Frequency = req.Frequency
|
|
|
- edbInfo.Unit = req.Unit
|
|
|
- edbInfo.ClassifyId = req.ClassifyId
|
|
|
- edbInfo.SysUserId = sysUserId
|
|
|
- edbInfo.SysUserRealName = sysUserRealName
|
|
|
- edbInfo.CreateTime = time.Now()
|
|
|
- edbInfo.ModifyTime = time.Now()
|
|
|
- edbInfo.UniqueCode = uniqueCode
|
|
|
- edbInfo.CalculateFormula = req.Formula
|
|
|
- edbInfo.EdbType = 2
|
|
|
- newEdbInfoId, tmpErr := to.Insert(edbInfo)
|
|
|
- if tmpErr != nil {
|
|
|
- err = tmpErr
|
|
|
- return
|
|
|
- }
|
|
|
- edbInfo.EdbInfoId = int(newEdbInfoId)
|
|
|
-
|
|
|
-
|
|
|
- tagMap := make(map[string]int)
|
|
|
- relationEdbInfoList := make([]*EdbInfo, 0)
|
|
|
- calculateMappingItemList := make([]*EdbInfoCalculateMapping, 0)
|
|
|
- for _, v := range req.EdbInfoIdArr {
|
|
|
- tmpEdbInfo, tmpErr := GetEdbInfoById(v.EdbInfoId)
|
|
|
- if tmpErr != nil {
|
|
|
- err = tmpErr
|
|
|
- return
|
|
|
- }
|
|
|
- relationEdbInfoList = append(relationEdbInfoList, tmpEdbInfo)
|
|
|
-
|
|
|
- calculateMappingItem := new(EdbInfoCalculateMapping)
|
|
|
- calculateMappingItem.CreateTime = time.Now()
|
|
|
- calculateMappingItem.ModifyTime = time.Now()
|
|
|
- calculateMappingItem.Sort = 1
|
|
|
- calculateMappingItem.EdbCode = edbCode
|
|
|
- calculateMappingItem.EdbInfoId = edbInfo.EdbInfoId
|
|
|
- calculateMappingItem.FromEdbInfoId = tmpEdbInfo.EdbInfoId
|
|
|
- calculateMappingItem.FromEdbCode = tmpEdbInfo.EdbCode
|
|
|
- calculateMappingItem.FromEdbName = tmpEdbInfo.EdbName
|
|
|
- calculateMappingItem.FromSource = tmpEdbInfo.Source
|
|
|
- calculateMappingItem.FromSourceName = tmpEdbInfo.SourceName
|
|
|
- calculateMappingItem.FromTag = v.FromTag
|
|
|
- calculateMappingItem.Source = edbInfo.Source
|
|
|
- calculateMappingItem.SourceName = edbInfo.SourceName
|
|
|
- calculateMappingItemList = append(calculateMappingItemList, calculateMappingItem)
|
|
|
-
|
|
|
- tagMap[v.FromTag] = v.EdbInfoId
|
|
|
- }
|
|
|
- _, err = to.InsertMulti(len(calculateMappingItemList), calculateMappingItemList)
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- err = refreshAllCalculateCorrelation(to, edbInfo.EdbInfoId, edbInfo.Source, relationEdbInfoList, edbInfo.EdbCode, edbInfo.CalculateFormula, tagMap)
|
|
|
-
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-func EditCalculateCorrelation(edbInfo *EdbInfo, req *EdbInfoCalculateBatchEditReq) (err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
- to, err := o.Begin()
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- defer func() {
|
|
|
- if err != nil {
|
|
|
- fmt.Println("EditCalculateCorrelation,Err:" + err.Error())
|
|
|
- _ = to.Rollback()
|
|
|
- } else {
|
|
|
- _ = to.Commit()
|
|
|
- }
|
|
|
- }()
|
|
|
-
|
|
|
-
|
|
|
- edbInfo.EdbName = req.EdbName
|
|
|
- edbInfo.EdbNameSource = req.EdbName
|
|
|
- edbInfo.Frequency = req.Frequency
|
|
|
- edbInfo.Unit = req.Unit
|
|
|
- edbInfo.ClassifyId = req.ClassifyId
|
|
|
- edbInfo.CalculateFormula = req.Formula
|
|
|
- edbInfo.ModifyTime = time.Now()
|
|
|
- _, err = to.Update(edbInfo, "EdbName", "EdbNameSource", "Frequency", "Unit", "ClassifyId", "CalculateFormula", "ModifyTime")
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- sql := ` DELETE FROM edb_info_calculate_mapping WHERE edb_info_id = ? `
|
|
|
- _, err = to.Raw(sql, edbInfo.EdbInfoId).Exec()
|
|
|
- if err != nil {
|
|
|
- err = errors.New("删除计算指标关联关系失败,Err:" + err.Error())
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- tableName := GetEdbDataTableName(edbInfo.Source)
|
|
|
- sql = ` DELETE FROM ` + tableName + ` WHERE edb_info_id = ? `
|
|
|
- _, err = to.Raw(sql, edbInfo.EdbInfoId).Exec()
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- tagMap := make(map[string]int)
|
|
|
- relationEdbInfoList := make([]*EdbInfo, 0)
|
|
|
- calculateMappingItemList := make([]*EdbInfoCalculateMapping, 0)
|
|
|
- for _, v := range req.EdbInfoIdArr {
|
|
|
- tmpEdbInfo, tmpErr := GetEdbInfoById(v.EdbInfoId)
|
|
|
- if tmpErr != nil {
|
|
|
- err = tmpErr
|
|
|
- return
|
|
|
- }
|
|
|
- relationEdbInfoList = append(relationEdbInfoList, tmpEdbInfo)
|
|
|
-
|
|
|
- calculateMappingItem := new(EdbInfoCalculateMapping)
|
|
|
- calculateMappingItem.CreateTime = time.Now()
|
|
|
- calculateMappingItem.ModifyTime = time.Now()
|
|
|
- calculateMappingItem.Sort = 1
|
|
|
- calculateMappingItem.EdbCode = edbInfo.EdbCode
|
|
|
- calculateMappingItem.EdbInfoId = edbInfo.EdbInfoId
|
|
|
- calculateMappingItem.FromEdbInfoId = tmpEdbInfo.EdbInfoId
|
|
|
- calculateMappingItem.FromEdbCode = tmpEdbInfo.EdbCode
|
|
|
- calculateMappingItem.FromEdbName = tmpEdbInfo.EdbName
|
|
|
- calculateMappingItem.FromSource = tmpEdbInfo.Source
|
|
|
- calculateMappingItem.FromSourceName = tmpEdbInfo.SourceName
|
|
|
- calculateMappingItem.FromTag = v.FromTag
|
|
|
- calculateMappingItem.Source = edbInfo.Source
|
|
|
- calculateMappingItem.SourceName = edbInfo.SourceName
|
|
|
- calculateMappingItemList = append(calculateMappingItemList, calculateMappingItem)
|
|
|
-
|
|
|
- tagMap[v.FromTag] = v.EdbInfoId
|
|
|
- }
|
|
|
- _, err = to.InsertMulti(len(calculateMappingItemList), calculateMappingItemList)
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- err = refreshAllCalculateCorrelation(to, edbInfo.EdbInfoId, edbInfo.Source, relationEdbInfoList, edbInfo.EdbCode, edbInfo.CalculateFormula, tagMap)
|
|
|
-
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-func RefreshAllCalculateCorrelation(edbInfo *EdbInfo) (err error) {
|
|
|
- edbInfoCalculateDetailList, err := GetEdbInfoCalculateDetailList(edbInfo.EdbInfoId)
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- tagMap := make(map[string]int)
|
|
|
- relationEdbInfoList := make([]*EdbInfo, 0)
|
|
|
- for _, v := range edbInfoCalculateDetailList {
|
|
|
- tagMap[v.FromTag] = v.FromEdbInfoId
|
|
|
- fromEdbInfo, _ := GetEdbInfoById(v.FromEdbInfoId)
|
|
|
- relationEdbInfoList = append(relationEdbInfoList, fromEdbInfo)
|
|
|
- }
|
|
|
- o := orm.NewOrm()
|
|
|
- to, err := o.Begin()
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- defer func() {
|
|
|
- if err != nil {
|
|
|
- fmt.Println("RefreshAllCalculateCorrelation,Err:" + err.Error())
|
|
|
- _ = to.Rollback()
|
|
|
- } else {
|
|
|
- _ = to.Commit()
|
|
|
- }
|
|
|
- }()
|
|
|
-
|
|
|
-
|
|
|
- err = refreshAllCalculateCorrelation(to, edbInfo.EdbInfoId, edbInfo.Source, relationEdbInfoList, edbInfo.EdbCode, edbInfo.CalculateFormula, tagMap)
|
|
|
-
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-type CorrelationConfig struct {
|
|
|
- DateType int `description:"扩散指标日期;1:全部指标日期并集;2:部分指标日期并集"`
|
|
|
- CheckList []string `description:"选中的数据,A,B,C"`
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-func refreshAllCalculateCorrelation(to orm.TxOrmer, edbInfoId, source int, relationEdbInfoList []*EdbInfo, edbCode, calculateFormula string, tagMap map[string]int) (err error) {
|
|
|
- edbInfoIdStr := strconv.Itoa(edbInfoId)
|
|
|
- tableName := GetEdbDataTableName(utils.DATA_SOURCE_CALCULATE_CORRELATION)
|
|
|
-
|
|
|
-
|
|
|
- checkEdbInfoIdMap := make(map[int]int)
|
|
|
- {
|
|
|
- var config CorrelationConfig
|
|
|
- err = json.Unmarshal([]byte(calculateFormula), &config)
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- if config.DateType == 1 {
|
|
|
- for _, tmpEdbInfoId := range tagMap {
|
|
|
- checkEdbInfoIdMap[tmpEdbInfoId] = tmpEdbInfoId
|
|
|
- }
|
|
|
- } else {
|
|
|
- for _, v := range config.CheckList {
|
|
|
- if tmpEdbInfoId, ok := tagMap[v]; ok {
|
|
|
- checkEdbInfoIdMap[tmpEdbInfoId] = tmpEdbInfoId
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- existDataList, err := GetAllEdbDataListByTo(to, edbInfoId, source)
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- existDataMap := make(map[string]*EdbData, 0)
|
|
|
- removeDateMap := make(map[string]string)
|
|
|
- for _, v := range existDataList {
|
|
|
- existDataMap[v.DataTime] = v
|
|
|
- removeDateMap[v.DataTime] = ``
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- relationEdbDataMap := make(map[int]map[string]float64)
|
|
|
-
|
|
|
- var startDate, endDate time.Time
|
|
|
- for _, v := range relationEdbInfoList {
|
|
|
- var condition string
|
|
|
- var pars []interface{}
|
|
|
- condition += " AND edb_info_id=? "
|
|
|
- pars = append(pars, v.EdbInfoId)
|
|
|
- tmpDataList, tmpErr := GetEdbDataListAllByTo(to, condition, pars, v.Source, 1)
|
|
|
- if tmpErr != nil {
|
|
|
- err = tmpErr
|
|
|
- return err
|
|
|
- }
|
|
|
- if tmpDataList != nil {
|
|
|
- if _, ok2 := checkEdbInfoIdMap[v.EdbInfoId]; ok2 {
|
|
|
- lenTmpDataList := len(tmpDataList)
|
|
|
- if lenTmpDataList > 0 {
|
|
|
- tmpStartTime, _ := time.ParseInLocation(utils.FormatDate, tmpDataList[0].DataTime, time.Local)
|
|
|
- tmpEndTime, _ := time.ParseInLocation(utils.FormatDate, tmpDataList[lenTmpDataList-1].DataTime, time.Local)
|
|
|
-
|
|
|
- if startDate.IsZero() || tmpStartTime.Before(startDate) {
|
|
|
- startDate = tmpStartTime
|
|
|
- }
|
|
|
-
|
|
|
- if tmpEndTime.IsZero() || tmpEndTime.After(endDate) {
|
|
|
- endDate = tmpEndTime
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- handleDataMap := make(map[string]float64)
|
|
|
- err = HandleDataByPreviousData(tmpDataList, handleDataMap)
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- relationEdbDataMap[v.EdbInfoId] = handleDataMap
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- addSql := ` INSERT INTO ` + tableName + ` (edb_info_id,edb_code,data_time,value,create_time,modify_time,data_timestamp) values `
|
|
|
- var isAdd bool
|
|
|
-
|
|
|
- for currDate := startDate.AddDate(0, 0, 1); !currDate.After(endDate); currDate = currDate.AddDate(0, 0, 1) {
|
|
|
- currDateStr := currDate.Format(utils.FormatDate)
|
|
|
-
|
|
|
-
|
|
|
- tmpValList := make([]float64, 0)
|
|
|
- for _, dataMap := range relationEdbDataMap {
|
|
|
- currVal, ok := dataMap[currDateStr]
|
|
|
- if !ok {
|
|
|
- continue
|
|
|
- }
|
|
|
-
|
|
|
- perVal, ok := dataMap[currDate.AddDate(0, 0, -1).Format(utils.FormatDate)]
|
|
|
- if !ok {
|
|
|
- continue
|
|
|
- }
|
|
|
-
|
|
|
- var tmpVal float64
|
|
|
- if currVal > perVal {
|
|
|
- tmpVal = 1
|
|
|
- } else if currVal == perVal {
|
|
|
- tmpVal = 0.5
|
|
|
- } else {
|
|
|
- tmpVal = 0
|
|
|
- }
|
|
|
- tmpValList = append(tmpValList, tmpVal)
|
|
|
- }
|
|
|
-
|
|
|
- lenTmpValList := len(tmpValList)
|
|
|
- if lenTmpValList <= 0 {
|
|
|
- continue
|
|
|
- }
|
|
|
-
|
|
|
- currValDeci := decimal.NewFromFloat(0)
|
|
|
- for _, tmpVal := range tmpValList {
|
|
|
- currValDeci = currValDeci.Add(decimal.NewFromFloat(tmpVal))
|
|
|
- }
|
|
|
- currVal, _ := currValDeci.Div(decimal.NewFromInt(int64(lenTmpValList))).Round(4).Float64()
|
|
|
-
|
|
|
-
|
|
|
- if existData, ok := existDataMap[currDateStr]; ok {
|
|
|
-
|
|
|
- existValStr := existData.Value
|
|
|
- existValDeci, tmpErr := decimal.NewFromString(existValStr)
|
|
|
- if tmpErr != nil {
|
|
|
- err = tmpErr
|
|
|
- return
|
|
|
- }
|
|
|
- existVal, _ := existValDeci.Round(4).Float64()
|
|
|
-
|
|
|
- if existVal != currVal {
|
|
|
- err = ModifyEdbDataById(source, existData.EdbDataId, fmt.Sprint(currVal))
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
-
|
|
|
- timestamp := currDate.UnixNano() / 1e6
|
|
|
- timestampStr := fmt.Sprintf("%d", timestamp)
|
|
|
- addSql += GetAddSql(edbInfoIdStr, edbCode, currDateStr, timestampStr, fmt.Sprint(currVal))
|
|
|
- isAdd = true
|
|
|
- }
|
|
|
-
|
|
|
- delete(removeDateMap, currDateStr)
|
|
|
- }
|
|
|
-
|
|
|
- if isAdd {
|
|
|
- addSql = strings.TrimRight(addSql, ",")
|
|
|
- _, err = to.Raw(addSql).Exec()
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if len(removeDateMap) > 0 {
|
|
|
- removeDateList := make([]string, 0)
|
|
|
- for k := range removeDateMap {
|
|
|
- removeDateList = append(removeDateList, k)
|
|
|
- }
|
|
|
- removeDateStr := strings.Join(removeDateList, `","`)
|
|
|
- removeDateStr = `"` + removeDateStr + `"`
|
|
|
- sql := fmt.Sprintf(` DELETE FROM %s WHERE edb_info_id = ? and data_time in (%s) `, tableName, removeDateStr)
|
|
|
- _, err = to.Raw(sql, edbInfoId).Exec()
|
|
|
- if err != nil {
|
|
|
- err = fmt.Errorf("删除扩散指数指标数据失败,Err:" + err.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-func GetRollingCorrelationChartDataByEdbInfo(edbInfoMappingA, edbInfoMappingB *EdbInfo, leadValue int, leadUnit string, calculateValue int, calculateUnit string, startDate, endDate string) (dateData map[string]float64, err error) {
|
|
|
- yData := make([]float64, 0)
|
|
|
-
|
|
|
- baseEdbInfo := edbInfoMappingA
|
|
|
- changeEdbInfo := edbInfoMappingB
|
|
|
-
|
|
|
-
|
|
|
- aDataList := make([]*EdbInfoSearchData, 0)
|
|
|
- switch baseEdbInfo.EdbInfoType {
|
|
|
- case 0:
|
|
|
- var condition string
|
|
|
- var pars []interface{}
|
|
|
- condition += " AND edb_info_id=? "
|
|
|
- pars = append(pars, baseEdbInfo.EdbInfoId)
|
|
|
-
|
|
|
-
|
|
|
- aDataList, err = GetEdbDataListAll(condition, pars, baseEdbInfo.Source, 1)
|
|
|
- case 1:
|
|
|
- aDataList, err = GetPredictEdbDataListAllByStartDate(baseEdbInfo, 1, "")
|
|
|
- default:
|
|
|
- err = errors.New(fmt.Sprint("获取失败,指标base类型异常", baseEdbInfo.EdbInfoType))
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- bDataList := make([]*EdbInfoSearchData, 0)
|
|
|
- switch changeEdbInfo.EdbInfoType {
|
|
|
- case 0:
|
|
|
- var condition string
|
|
|
- var pars []interface{}
|
|
|
- condition += " AND edb_info_id=? "
|
|
|
- pars = append(pars, changeEdbInfo.EdbInfoId)
|
|
|
-
|
|
|
-
|
|
|
- bDataList, err = GetEdbDataListAll(condition, pars, changeEdbInfo.Source, 1)
|
|
|
- case 1:
|
|
|
- bDataList, err = GetPredictEdbDataListAllByStartDate(changeEdbInfo, 1, "")
|
|
|
- default:
|
|
|
- err = errors.New(fmt.Sprint("获取失败,指标change类型异常", baseEdbInfo.EdbInfoType))
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- frequencyDaysMap := map[string]int{
|
|
|
- "天": 1, "周": 7, "月": 30, "季": 90, "年": 365,
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- baseDataMap := make(map[string]float64)
|
|
|
- changeDataList := make([]*EdbInfoSearchData, 0)
|
|
|
- changeDataMap := make(map[string]float64)
|
|
|
-
|
|
|
-
|
|
|
- {
|
|
|
- _, e := HandleDataByLinearRegression(aDataList, baseDataMap)
|
|
|
- if e != nil {
|
|
|
- err = fmt.Errorf("获取变频指标插值法Map失败, Err: %s", e.Error())
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- {
|
|
|
- tmpNewChangeDataList, e := HandleDataByLinearRegression(bDataList, changeDataMap)
|
|
|
- if e != nil {
|
|
|
- err = fmt.Errorf("获取变频指标插值法Map失败, Err: %s", e.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- changeDataList = tmpNewChangeDataList
|
|
|
-
|
|
|
-
|
|
|
- moveUnitDays := frequencyDaysMap[leadUnit]
|
|
|
- _, changeDataMap = MoveDataDaysToNewDataList(changeDataList, leadValue*moveUnitDays)
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- calculateDay := frequencyDaysMap[calculateUnit] * calculateValue
|
|
|
-
|
|
|
-
|
|
|
- {
|
|
|
- startDateTime, _ := time.ParseInLocation(utils.FormatDate, startDate, time.Local)
|
|
|
- endDateTime, _ := time.ParseInLocation(utils.FormatDate, endDate, time.Local)
|
|
|
-
|
|
|
- for currDay := startDateTime; !currDay.After(endDateTime); currDay = currDay.AddDate(0, 0, 1) {
|
|
|
- coordinateData := make([]utils.Coordinate, 0)
|
|
|
-
|
|
|
- for i := 0; i < calculateDay; i++ {
|
|
|
- iDay := currDay.AddDate(0, 0, i).Format(utils.FormatDate)
|
|
|
- tmpCoordinate := utils.Coordinate{
|
|
|
- X: baseDataMap[iDay],
|
|
|
- Y: changeDataMap[iDay],
|
|
|
- }
|
|
|
- coordinateData = append(coordinateData, tmpCoordinate)
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- var ratio float64
|
|
|
- if len(coordinateData) > 0 {
|
|
|
- ratio = utils.ComputeCorrelation(coordinateData)
|
|
|
- }
|
|
|
- yData = append(yData, ratio)
|
|
|
- dateData[currDay.AddDate(0, 0, calculateDay).Format(utils.FormatDate)] = ratio
|
|
|
- }
|
|
|
- }
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-func MoveDataDaysToNewDataList(dataList []*EdbInfoSearchData, moveDay int) (newDataList []EdbInfoSearchData, dateDataMap map[string]float64) {
|
|
|
- dateMap := make(map[time.Time]float64)
|
|
|
- var minDate, maxDate time.Time
|
|
|
- dateDataMap = make(map[string]float64)
|
|
|
-
|
|
|
- for _, v := range dataList {
|
|
|
- currDate, _ := time.ParseInLocation(utils.FormatDate, v.DataTime, time.Local)
|
|
|
- if minDate.IsZero() || currDate.Before(minDate) {
|
|
|
- minDate = currDate
|
|
|
- }
|
|
|
- if maxDate.IsZero() || currDate.After(maxDate) {
|
|
|
- maxDate = currDate
|
|
|
- }
|
|
|
- dateMap[currDate] = v.Value
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- newDateMap := make(map[time.Time]float64)
|
|
|
- for currDate, value := range dateMap {
|
|
|
- newDate := currDate.AddDate(0, 0, moveDay)
|
|
|
- newDateMap[newDate] = value
|
|
|
- }
|
|
|
- minDate = minDate.AddDate(0, 0, moveDay)
|
|
|
- maxDate = maxDate.AddDate(0, 0, moveDay)
|
|
|
-
|
|
|
-
|
|
|
- dayNum := utils.GetTimeSubDay(minDate, maxDate)
|
|
|
-
|
|
|
- for i := 0; i <= dayNum; i++ {
|
|
|
- currDate := minDate.AddDate(0, 0, i)
|
|
|
- tmpValue, ok := newDateMap[currDate]
|
|
|
- if !ok {
|
|
|
-
|
|
|
- if len(newDataList)-1 < 0 {
|
|
|
- tmpValue = 0
|
|
|
- } else {
|
|
|
- tmpValue = newDataList[len(newDataList)-1].Value
|
|
|
- }
|
|
|
- }
|
|
|
- tmpData := EdbInfoSearchData{
|
|
|
- DataTime: currDate.Format(utils.FormatDate),
|
|
|
- Value: tmpValue,
|
|
|
- }
|
|
|
- dateDataMap[tmpData.DataTime] = tmpData.Value
|
|
|
- newDataList = append(newDataList, tmpData)
|
|
|
- }
|
|
|
- return
|
|
|
-}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|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