|
@@ -1,6 +1,7 @@
|
|
|
package models
|
|
|
|
|
|
import (
|
|
|
+ "encoding/json"
|
|
|
"errors"
|
|
|
"eta/eta_index_lib/utils"
|
|
|
"fmt"
|
|
@@ -59,7 +60,7 @@ func EditPredictCalculate(edbInfo *EdbInfo, calculateMappingList []*EdbInfoCalcu
|
|
|
}()
|
|
|
|
|
|
// 修改指标信息
|
|
|
- _, err = to.Update(edbInfo, "EdbName", "Frequency", "Unit", "ClassifyId", "CalculateFormula", "EmptyType", "MaxEmptyType")
|
|
|
+ _, err = to.Update(edbInfo, "EdbName", "Frequency", "Unit", "ClassifyId", "CalculateFormula", "EmptyType", "MaxEmptyType", "Extra")
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -223,7 +224,7 @@ func EditPredictCalculate(edbInfo *EdbInfo, calculateMappingList []*EdbInfoCalcu
|
|
|
// return
|
|
|
//}
|
|
|
|
|
|
-func AddPredictCalculateData(edbInfoIdList []*EdbInfo, edbInfo *EdbInfo, edbCode, formulaStr string, edbInfoIdBytes []string) (latestDateStr string, latestValue float64, err error) {
|
|
|
+func AddPredictCalculateData(edbInfoIdList []*EdbInfo, edbInfoTag map[string]int, edbInfo *EdbInfo, edbCode, formulaStr string, edbInfoIdBytes []string) (latestDateStr string, latestValue float64, err error) {
|
|
|
o := orm.NewOrm()
|
|
|
to, err := o.Begin()
|
|
|
if err != nil {
|
|
@@ -238,12 +239,12 @@ func AddPredictCalculateData(edbInfoIdList []*EdbInfo, edbInfo *EdbInfo, edbCode
|
|
|
}
|
|
|
}()
|
|
|
|
|
|
- latestDateStr, latestValue, err = refreshAllPredictCalculate(to, edbInfoIdList, edbInfo.EdbInfoId, edbInfo.Source, edbInfo.SubSource, edbCode, formulaStr, "", edbInfoIdBytes, edbInfo.EmptyType, edbInfo.MaxEmptyType)
|
|
|
+ latestDateStr, latestValue, err = refreshAllPredictCalculate(to, edbInfoIdList, edbInfoTag, edbInfo.EdbInfoId, edbInfo.Source, edbInfo.SubSource, edbCode, formulaStr, "", edbInfoIdBytes, edbInfo.EmptyType, edbInfo.MaxEmptyType, edbInfo.Extra)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// RefreshAllPredictCalculate 刷新预测计算指标的全部数据
|
|
|
-func RefreshAllPredictCalculate(edbInfoIdList []*EdbInfo, edbInfoId, source, subSource int, edbCode, formulaStr, startDate string, edbInfoIdBytes []string, emptyType, maxEmptyType int) (latestDateStr string, latestValue float64, err error) {
|
|
|
+func RefreshAllPredictCalculate(edbInfoIdList []*EdbInfo, edbInfoTag map[string]int, edbInfoId, source, subSource int, edbCode, formulaStr, startDate string, edbInfoIdBytes []string, emptyType, maxEmptyType int, extra string) (latestDateStr string, latestValue float64, err error) {
|
|
|
o := orm.NewOrm()
|
|
|
to, err := o.Begin()
|
|
|
if err != nil {
|
|
@@ -258,13 +259,13 @@ func RefreshAllPredictCalculate(edbInfoIdList []*EdbInfo, edbInfoId, source, sub
|
|
|
}
|
|
|
}()
|
|
|
|
|
|
- latestDateStr, latestValue, err = refreshAllPredictCalculate(to, edbInfoIdList, edbInfoId, source, subSource, edbCode, formulaStr, startDate, edbInfoIdBytes, emptyType, maxEmptyType)
|
|
|
+ latestDateStr, latestValue, err = refreshAllPredictCalculate(to, edbInfoIdList, edbInfoTag, edbInfoId, source, subSource, edbCode, formulaStr, startDate, edbInfoIdBytes, emptyType, maxEmptyType, extra)
|
|
|
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// refreshAllPredictCalculate 刷新预测计算指标的全部数据
|
|
|
-func refreshAllPredictCalculate(to orm.TxOrmer, edbInfoIdList []*EdbInfo, edbInfoId, source, subSource int, edbCode, formulaStr, startDate string, edbInfoIdBytes []string, emptyType, maxEmptyType int) (latestDateStr string, latestValue float64, err error) {
|
|
|
+func refreshAllPredictCalculate(to orm.TxOrmer, edbInfoIdList []*EdbInfo, edbInfoTag map[string]int, edbInfoId, source, subSource int, edbCode, formulaStr, startDate string, edbInfoIdBytes []string, emptyType, maxEmptyType int, extra string) (latestDateStr string, latestValue float64, err error) {
|
|
|
fmt.Println("startDate:", startDate)
|
|
|
var startDateValue float64
|
|
|
// 最小的结束日期 , 最晚的数据开始日期
|
|
@@ -273,6 +274,18 @@ func refreshAllPredictCalculate(to orm.TxOrmer, edbInfoIdList []*EdbInfo, edbInf
|
|
|
|
|
|
realSaveDataMap := make(map[string]map[int]float64)
|
|
|
saveDataMap := make(map[string]map[int]float64)
|
|
|
+ dateMap := make(map[string]struct{}) // 最终的日期数据
|
|
|
+
|
|
|
+ dateTagConfig := ""
|
|
|
+ if extra != "" {
|
|
|
+ var dateConfig CalculateEdbExtra
|
|
|
+ err = json.Unmarshal([]byte(extra), &dateConfig)
|
|
|
+ if err != nil {
|
|
|
+ err = fmt.Errorf("refreshAllCalculate,extra解析失败,Err:%s", err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ dateTagConfig = dateConfig.DateTag
|
|
|
+ }
|
|
|
|
|
|
for edbInfoIndex, v := range edbInfoIdList {
|
|
|
// 单独存储max、min函数里的指标的数据
|
|
@@ -321,7 +334,31 @@ func refreshAllPredictCalculate(to orm.TxOrmer, edbInfoIdList []*EdbInfo, edbInf
|
|
|
temp[v.EdbInfoId] = dv.Value
|
|
|
saveDataMap[dv.DataTime] = temp
|
|
|
}
|
|
|
- if edbInfoIndex == 0 {
|
|
|
+
|
|
|
+ if dateTagConfig == "all" {
|
|
|
+ if _, ok := dateMap[dv.DataTime]; !ok {
|
|
|
+ dateList = append(dateList, dv.DataTime)
|
|
|
+ dateMap[dv.DataTime] = struct{}{}
|
|
|
+ }
|
|
|
+ } else if dateTagConfig == "" { // 默认取第一个指标的时间序列
|
|
|
+ if edbInfoIndex == 0 {
|
|
|
+ if _, ok := dateMap[dv.DataTime]; !ok {
|
|
|
+ dateList = append(dateList, dv.DataTime)
|
|
|
+ dateMap[dv.DataTime] = struct{}{}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if eId, ok := edbInfoTag[dateTagConfig]; ok {
|
|
|
+ if v.EdbInfoId == eId {
|
|
|
+ if _, ok1 := dateMap[dv.DataTime]; !ok1 {
|
|
|
+ dateList = append(dateList, dv.DataTime)
|
|
|
+ dateMap[dv.DataTime] = struct{}{}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /*if edbInfoIndex == 0 {
|
|
|
dateList = append(dateList, dv.DataTime)
|
|
|
tmpDate, _ := time.ParseInLocation(utils.FormatDate, dv.DataTime, time.Local)
|
|
|
if minLatestDate.IsZero() || tmpDate.After(minLatestDate) {
|
|
@@ -330,10 +367,19 @@ func refreshAllPredictCalculate(to orm.TxOrmer, edbInfoIdList []*EdbInfo, edbInf
|
|
|
if maxStartDate.IsZero() || tmpDate.Before(maxStartDate) {
|
|
|
maxStartDate = tmpDate
|
|
|
}
|
|
|
- }
|
|
|
+ }*/
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 处理最大日期和最小日期
|
|
|
+ for _, v := range dateList {
|
|
|
+ tmpDate, _ := time.ParseInLocation(utils.FormatDate, v, time.Local)
|
|
|
+ if minLatestDate.IsZero() || tmpDate.After(minLatestDate) {
|
|
|
+ minLatestDate = tmpDate
|
|
|
+ }
|
|
|
+ if maxStartDate.IsZero() || tmpDate.Before(maxStartDate) {
|
|
|
+ maxStartDate = tmpDate
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
//数据处理,将日期内不全的数据做填补
|
|
|
HandleDateSaveDataMap(dateList, maxStartDate, minLatestDate, realSaveDataMap, saveDataMap, edbInfoIdList, emptyType)
|
|
|
|
|
@@ -368,6 +414,9 @@ func refreshAllPredictCalculate(to orm.TxOrmer, edbInfoIdList []*EdbInfo, edbInf
|
|
|
}
|
|
|
|
|
|
for sk, sv := range saveDataMap {
|
|
|
+ if _, ok := dateMap[sk]; !ok { //不在最终的日期序列里面不计算
|
|
|
+ continue
|
|
|
+ }
|
|
|
// 当空值处理类型选择了不计算时,只要有一个指标在某个日期没有值(即空值),则计算指标在该日期没有值
|
|
|
if emptyType == 1 {
|
|
|
if len(sv) != len(edbInfoIdList) {
|