|
@@ -193,7 +193,7 @@ func RefreshAllPredictCalculateCjjx(edbInfoId, source int, fromEdbInfo *EdbInfo,
|
|
|
func refreshAllPredictCalculateCjjx(to orm.TxOrmer, edbInfoId, source int, fromEdbInfo *EdbInfo, edbCode, startDate, endDate, calendar string, formulaInt int) (latestDateStr string, latestValue float64, err error) {
|
|
|
edbInfoIdStr := strconv.Itoa(edbInfoId)
|
|
|
// 获取关联指标数据
|
|
|
- dataList, err := GetPredictEdbDataListAllByStartDate(fromEdbInfo, 0, "")
|
|
|
+ dataList, err := GetPredictEdbDataListAllByStartDate(fromEdbInfo, 1, "")
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -204,6 +204,14 @@ func refreshAllPredictCalculateCjjx(to orm.TxOrmer, edbInfoId, source int, fromE
|
|
|
dateArr = append(dateArr, v.DataTime)
|
|
|
dataMap[v.DataTime] = v
|
|
|
}
|
|
|
+
|
|
|
+ // 通过插值法补全所有数据(包含周末)
|
|
|
+ handleDataMap := make(map[string]float64)
|
|
|
+ _, err = HandleDataByLinearRegression(dataList, handleDataMap)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
//获取指标所有数据
|
|
|
existDataList := make([]*EdbData, 0)
|
|
|
dataTableName := GetEdbDataTableName(source)
|
|
@@ -223,10 +231,10 @@ func refreshAllPredictCalculateCjjx(to orm.TxOrmer, edbInfoId, source int, fromE
|
|
|
addSql := ` INSERT INTO edb_data_predict_calculate_cjjx(edb_info_id,edb_code,data_time,value,create_time,modify_time,data_timestamp) values `
|
|
|
var isAdd bool
|
|
|
//日度/周度/季度/月度
|
|
|
- isCompatibility := false //是否向上下兼容35天
|
|
|
- if utils.InArrayByStr([]string{"日度", "周度", "季度", "月度"}, fromEdbInfo.Frequency) {
|
|
|
- isCompatibility = true
|
|
|
- }
|
|
|
+ //isCompatibility := false //是否向上下兼容35天
|
|
|
+ //if utils.InArrayByStr([]string{"日度", "周度", "季度", "月度"}, fromEdbInfo.Frequency) {
|
|
|
+ // isCompatibility = true
|
|
|
+ //}
|
|
|
|
|
|
// 每个年份的日期数据需要平移的天数
|
|
|
moveDayMap := make(map[int]int, 0) // 每个年份的春节公历
|
|
@@ -264,35 +272,36 @@ func refreshAllPredictCalculateCjjx(to orm.TxOrmer, edbInfoId, source int, fromE
|
|
|
hisoryPreDate = hisoryPreDate.AddDate(0, 0, moveDay)
|
|
|
}
|
|
|
|
|
|
- hisoryPreDateStr := hisoryPreDate.Format(utils.FormatDate)
|
|
|
- if findItem, ok := dataMap[hisoryPreDateStr]; ok { //上一年同期找到
|
|
|
- pastValueList = append(pastValueList, findItem.Value)
|
|
|
- } else if isCompatibility { // 如果需要兼容上下35天
|
|
|
- nextDateDay := hisoryPreDate
|
|
|
- preDateDay := hisoryPreDate
|
|
|
- for i := 0; i < 35; i++ {
|
|
|
- nextDateDayStr := nextDateDay.Format(utils.FormatDate)
|
|
|
- if findItem, ok := dataMap[nextDateDayStr]; ok { //上一年同期->下一个月找到
|
|
|
- pastValueList = append(pastValueList, findItem.Value)
|
|
|
- break
|
|
|
- } else {
|
|
|
- preDateDayStr := preDateDay.Format(utils.FormatDate)
|
|
|
- if findItem, ok := dataMap[preDateDayStr]; ok { //上一年同期->上一个月找到
|
|
|
- pastValueList = append(pastValueList, findItem.Value)
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- nextDateDay = nextDateDay.AddDate(0, 0, 1)
|
|
|
- preDateDay = preDateDay.AddDate(0, 0, -1)
|
|
|
- }
|
|
|
+ historyPreDateStr := hisoryPreDate.Format(utils.FormatDate)
|
|
|
+ if tmpValue, ok := handleDataMap[historyPreDateStr]; ok { //上一年同期找到
|
|
|
+ pastValueList = append(pastValueList, tmpValue)
|
|
|
}
|
|
|
- if av == "2022-11-28" {
|
|
|
- fmt.Println(moveDay)
|
|
|
- }
|
|
|
- }
|
|
|
- if av == "2022-11-28" {
|
|
|
- fmt.Println(pastValueList)
|
|
|
+ //else if isCompatibility { // 如果需要兼容上下35天
|
|
|
+ // nextDateDay := hisoryPreDate
|
|
|
+ // preDateDay := hisoryPreDate
|
|
|
+ // for i := 0; i < 35; i++ {
|
|
|
+ // nextDateDayStr := nextDateDay.Format(utils.FormatDate)
|
|
|
+ // if findItem, ok := dataMap[nextDateDayStr]; ok { //上一年同期->下一个月找到
|
|
|
+ // pastValueList = append(pastValueList, findItem.Value)
|
|
|
+ // break
|
|
|
+ // } else {
|
|
|
+ // preDateDayStr := preDateDay.Format(utils.FormatDate)
|
|
|
+ // if findItem, ok := dataMap[preDateDayStr]; ok { //上一年同期->上一个月找到
|
|
|
+ // pastValueList = append(pastValueList, findItem.Value)
|
|
|
+ // break
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // nextDateDay = nextDateDay.AddDate(0, 0, 1)
|
|
|
+ // preDateDay = preDateDay.AddDate(0, 0, -1)
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+ //if av == "2023-09-29" {
|
|
|
+ // fmt.Println(moveDay)
|
|
|
+ //}
|
|
|
}
|
|
|
+ //if av == "2023-09-29" {
|
|
|
+ // fmt.Println(pastValueList)
|
|
|
+ //}
|
|
|
|
|
|
if len(pastValueList) == formulaInt {
|
|
|
delete(removeDataTimeMap, av) //将待删除的日期给移除
|