|
@@ -65,6 +65,7 @@ type EdbInfo struct {
|
|
|
StockCode string `description:"证券代码"`
|
|
|
Extra string `description:"指标的额外配置"`
|
|
|
IsStaticData int `description:"是否是静态指标,0否,1是"`
|
|
|
+ EndDateType int `description:"预测指标截止日期类型:0:未来日期,1未来期数"`
|
|
|
}
|
|
|
|
|
|
func (e *EdbInfo) Add() (err error) {
|
|
@@ -741,17 +742,20 @@ func UnifiedModifyPredictEdbInfoMaxAndMinInfo(edbInfo *EdbInfo, latestDateStr st
|
|
|
}
|
|
|
|
|
|
// GetChartPredictEdbInfoDataListByConfList 获取图表的预测指标的未来数据
|
|
|
-func GetChartPredictEdbInfoDataListByConfList(predictEdbConfList []*PredictEdbConfAndData, filtrateStartDateStr, latestDateStr, endDateStr, frequency, dataDateType string, realPredictEdbInfoData []*EdbInfoSearchData) (predictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64, err error) {
|
|
|
- endDate, err := time.ParseInLocation(utils.FormatDate, endDateStr, time.Local)
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
+func GetChartPredictEdbInfoDataListByConfList(predictEdbConfList []*PredictEdbConfAndData, filtrateStartDateStr, latestDateStr, endDateStr, frequency, dataDateType string, endDateType int, realPredictEdbInfoData []*EdbInfoSearchData) (predictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64, err error) {
|
|
|
+ hasEndNum := 0 //如果选择了未来期数,用来保存已经预测过的期数
|
|
|
+ var endDate time.Time
|
|
|
+ if endDateStr != `` {
|
|
|
+ endDate, err = time.ParseInLocation(utils.FormatDate, endDateStr, time.Local)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
latestDate, err := time.ParseInLocation(utils.FormatDate, latestDateStr, time.Local)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
// 开始预测数据的时间
|
|
|
startDate := latestDate
|
|
|
|
|
@@ -785,13 +789,14 @@ func GetChartPredictEdbInfoDataListByConfList(predictEdbConfList []*PredictEdbCo
|
|
|
//if predictEdbConf.EndDate.Before(dataEndTime) {
|
|
|
// dataEndTime = predictEdbConf.EndDate
|
|
|
//}
|
|
|
- endDate = predictEdbConf.EndDate
|
|
|
+ //endDate = predictEdbConf.EndDate
|
|
|
var tmpMinValue, tmpMaxValue float64 // 当前预测结果中的最大/最小值
|
|
|
-
|
|
|
- dayList := getPredictEdbDayList(startDate, endDate, frequency, dataDateType)
|
|
|
+ endNum := predictEdbConf.EndNum - hasEndNum
|
|
|
+ dayList := getPredictEdbDayList(startDate, predictEdbConf.EndDate, frequency, dataDateType, endDateType, endNum)
|
|
|
if len(dayList) <= 0 { // 如果未来没有日期的话,那么就退出当前循环,进入下一个循环
|
|
|
continue
|
|
|
}
|
|
|
+ endDate = dayList[len(dayList)-1]
|
|
|
|
|
|
switch predictEdbConf.RuleType {
|
|
|
case 1: //1:最新
|
|
@@ -868,7 +873,6 @@ func GetChartPredictEdbInfoDataListByConfList(predictEdbConfList []*PredictEdbCo
|
|
|
}
|
|
|
case 9: //9:动态环差”预测规则;
|
|
|
hcDataMap := make(map[string]float64) //规则计算的环差值map
|
|
|
-
|
|
|
if predictEdbConf.PredictEdbInfoId > 0 {
|
|
|
tmpPredictEdbRuleDataList, tmpErr := GetPredictEdbRuleDataItemList(predictEdbConf.PredictEdbInfoId, predictEdbConf.ConfigId, startDate.Format(utils.FormatDate), endDate.Format(utils.FormatDate))
|
|
|
if tmpErr != nil {
|
|
@@ -998,6 +1002,9 @@ func GetChartPredictEdbInfoDataListByConfList(predictEdbConfList []*PredictEdbCo
|
|
|
{
|
|
|
lenPredictEdbInfoData := len(predictEdbInfoData)
|
|
|
if lenPredictEdbInfoData > 0 {
|
|
|
+ if endDateType == 1 {
|
|
|
+ hasEndNum = predictEdbConf.EndNum
|
|
|
+ }
|
|
|
tmpDataEndTime, _ := time.ParseInLocation(utils.FormatDate, predictEdbInfoData[lenPredictEdbInfoData-1].DataTime, time.Local)
|
|
|
if startDate.Before(tmpDataEndTime) {
|
|
|
startDate = tmpDataEndTime
|
|
@@ -1019,69 +1026,141 @@ func GetChartPredictEdbInfoDataListByConfList(predictEdbConfList []*PredictEdbCo
|
|
|
// GetPredictEdbDayList 获取预测指标日期列表
|
|
|
|
|
|
// GetPredictEdbDayList 获取预测指标日期列表
|
|
|
-func getPredictEdbDayList(startDate, endDate time.Time, frequency, dataDateType string) (dayList []time.Time) {
|
|
|
+func getPredictEdbDayList(startDate, endDate time.Time, frequency, dataDateType string, endDateType, endNum int) (dayList []time.Time) {
|
|
|
if dataDateType == `` {
|
|
|
dataDateType = `交易日`
|
|
|
}
|
|
|
- switch frequency {
|
|
|
- case "日度":
|
|
|
- for currDate := startDate.AddDate(0, 0, 1); currDate.Before(endDate) || currDate.Equal(endDate); currDate = currDate.AddDate(0, 0, 1) {
|
|
|
- // 如果日期类型是交易日的时候,那么需要将周六、日排除
|
|
|
- if dataDateType == `交易日` && (currDate.Weekday() == time.Sunday || currDate.Weekday() == time.Saturday) {
|
|
|
- continue
|
|
|
+
|
|
|
+ if endDateType == 0 { // 截止日期
|
|
|
+ switch frequency {
|
|
|
+ case "日度":
|
|
|
+ for currDate := startDate.AddDate(0, 0, 1); currDate.Before(endDate) || currDate.Equal(endDate); currDate = currDate.AddDate(0, 0, 1) {
|
|
|
+ // 如果日期类型是交易日的时候,那么需要将周六、日排除
|
|
|
+ if dataDateType == `交易日` && (currDate.Weekday() == time.Sunday || currDate.Weekday() == time.Saturday) {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ dayList = append(dayList, currDate)
|
|
|
}
|
|
|
- dayList = append(dayList, currDate)
|
|
|
- }
|
|
|
- case "周度":
|
|
|
- //nextDate := startDate.AddDate(0, 0, 7)
|
|
|
- for currDate := startDate.AddDate(0, 0, 7); currDate.Before(endDate) || currDate.Equal(endDate); currDate = currDate.AddDate(0, 0, 7) {
|
|
|
- dayList = append(dayList, currDate)
|
|
|
- }
|
|
|
- case "旬度":
|
|
|
- for currDate := startDate.AddDate(0, 0, 1); currDate.Before(endDate) || currDate.Equal(endDate); {
|
|
|
- nextDate := currDate.AddDate(0, 0, 1)
|
|
|
- //每个月的10号、20号、最后一天,那么就写入
|
|
|
- if nextDate.Day() == 11 || nextDate.Day() == 21 || nextDate.Day() == 1 {
|
|
|
+ case "周度":
|
|
|
+ //nextDate := startDate.AddDate(0, 0, 7)
|
|
|
+ for currDate := startDate.AddDate(0, 0, 7); currDate.Before(endDate) || currDate.Equal(endDate); currDate = currDate.AddDate(0, 0, 7) {
|
|
|
dayList = append(dayList, currDate)
|
|
|
}
|
|
|
- currDate = nextDate
|
|
|
+ case "旬度":
|
|
|
+ for currDate := startDate.AddDate(0, 0, 1); currDate.Before(endDate) || currDate.Equal(endDate); {
|
|
|
+ nextDate := currDate.AddDate(0, 0, 1)
|
|
|
+ //每个月的10号、20号、最后一天,那么就写入
|
|
|
+ if nextDate.Day() == 11 || nextDate.Day() == 21 || nextDate.Day() == 1 {
|
|
|
+ dayList = append(dayList, currDate)
|
|
|
+ }
|
|
|
+ currDate = nextDate
|
|
|
+ }
|
|
|
+ case "月度":
|
|
|
+ for currDate := startDate; currDate.Before(endDate) || currDate.Equal(endDate); {
|
|
|
+ currDate = time.Date(currDate.Year(), currDate.Month(), 1, 0, 0, 0, 0, time.Now().Location()).AddDate(0, 1, -1)
|
|
|
+ if !currDate.After(endDate) && !currDate.Equal(startDate) {
|
|
|
+ dayList = append(dayList, currDate)
|
|
|
+ }
|
|
|
+ currDate = currDate.AddDate(0, 0, 1)
|
|
|
+ }
|
|
|
+ case "季度":
|
|
|
+ for currDate := startDate; currDate.Before(endDate) || currDate.Equal(endDate); {
|
|
|
+ // 每月的最后一天
|
|
|
+ currDate = time.Date(currDate.Year(), currDate.Month(), 1, 0, 0, 0, 0, time.Now().Location()).AddDate(0, 1, -1)
|
|
|
+ if !currDate.After(endDate) && !currDate.Equal(startDate) {
|
|
|
+ // 季度日期就写入,否则不写入
|
|
|
+ if currDate.Month() == 3 || currDate.Month() == 6 || currDate.Month() == 9 || currDate.Month() == 12 {
|
|
|
+ dayList = append(dayList, currDate)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ currDate = currDate.AddDate(0, 0, 1)
|
|
|
+ }
|
|
|
+ case "半年度":
|
|
|
+ for currDate := startDate; currDate.Before(endDate) || currDate.Equal(endDate); {
|
|
|
+ // 每月的最后一天
|
|
|
+ currDate = time.Date(currDate.Year(), currDate.Month(), 1, 0, 0, 0, 0, time.Now().Location()).AddDate(0, 1, -1)
|
|
|
+ if !currDate.After(endDate) && !currDate.Equal(startDate) {
|
|
|
+ // 半年度日期就写入,否则不写入
|
|
|
+ if currDate.Month() == 6 || currDate.Month() == 12 {
|
|
|
+ dayList = append(dayList, currDate)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ currDate = currDate.AddDate(0, 0, 1)
|
|
|
+ }
|
|
|
+ case "年度":
|
|
|
+ for currDate := startDate; currDate.Before(endDate) || currDate.Equal(endDate); {
|
|
|
+ currDate = time.Date(currDate.Year()+1, 12, 31, 0, 0, 0, 0, time.Now().Location())
|
|
|
+ if !currDate.After(endDate) && !currDate.Equal(startDate) {
|
|
|
+ dayList = append(dayList, currDate)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- case "月度":
|
|
|
- for currDate := startDate; currDate.Before(endDate) || currDate.Equal(endDate); {
|
|
|
- currDate = time.Date(currDate.Year(), currDate.Month(), 1, 0, 0, 0, 0, time.Now().Location()).AddDate(0, 1, -1)
|
|
|
- if !currDate.After(endDate) && !currDate.Equal(startDate) {
|
|
|
+ } else { // 截止期数
|
|
|
+ switch frequency {
|
|
|
+ case "日度":
|
|
|
+ for i := 1; i <= endNum; i++ {
|
|
|
+ currDate := startDate.AddDate(0, 0, i)
|
|
|
+ // 如果日期类型是交易日的时候,那么需要将周六、日排除
|
|
|
+ if dataDateType == `交易日` && (currDate.Weekday() == time.Sunday || currDate.Weekday() == time.Saturday) {
|
|
|
+ continue
|
|
|
+ }
|
|
|
dayList = append(dayList, currDate)
|
|
|
}
|
|
|
- currDate = currDate.AddDate(0, 0, 1)
|
|
|
- }
|
|
|
- case "季度":
|
|
|
- for currDate := startDate; currDate.Before(endDate) || currDate.Equal(endDate); {
|
|
|
- // 每月的最后一天
|
|
|
- currDate = time.Date(currDate.Year(), currDate.Month(), 1, 0, 0, 0, 0, time.Now().Location()).AddDate(0, 1, -1)
|
|
|
- if !currDate.After(endDate) && !currDate.Equal(startDate) {
|
|
|
- // 季度日期就写入,否则不写入
|
|
|
- if currDate.Month() == 3 || currDate.Month() == 6 || currDate.Month() == 9 || currDate.Month() == 12 {
|
|
|
+ case "周度":
|
|
|
+ for i := 1; i <= endNum; i++ {
|
|
|
+ currDate := startDate.AddDate(0, 0, i*7)
|
|
|
+ dayList = append(dayList, currDate)
|
|
|
+ }
|
|
|
+ case "旬度":
|
|
|
+ currDate := startDate
|
|
|
+ for i := 1; len(dayList) < endNum; i++ {
|
|
|
+ currDate = currDate.AddDate(0, 0, 1)
|
|
|
+ nextDate := currDate.AddDate(0, 0, 1)
|
|
|
+ //每个月的10号、20号、最后一天,那么就写入
|
|
|
+ if nextDate.Day() == 11 || nextDate.Day() == 21 || nextDate.Day() == 1 {
|
|
|
dayList = append(dayList, currDate)
|
|
|
}
|
|
|
}
|
|
|
- currDate = currDate.AddDate(0, 0, 1)
|
|
|
- }
|
|
|
- case "半年度":
|
|
|
- for currDate := startDate; currDate.Before(endDate) || currDate.Equal(endDate); {
|
|
|
- // 每月的最后一天
|
|
|
- currDate = time.Date(currDate.Year(), currDate.Month(), 1, 0, 0, 0, 0, time.Now().Location()).AddDate(0, 1, -1)
|
|
|
- if !currDate.After(endDate) && !currDate.Equal(startDate) {
|
|
|
- // 半年度日期就写入,否则不写入
|
|
|
- if currDate.Month() == 6 || currDate.Month() == 12 {
|
|
|
+ case "月度":
|
|
|
+ currDate := startDate
|
|
|
+ for i := 0; i <= endNum; i++ {
|
|
|
+ currDate = time.Date(currDate.Year(), currDate.Month(), 1, 0, 0, 0, 0, time.Now().Location()).AddDate(0, 1, -1)
|
|
|
+ if !currDate.Equal(startDate) {
|
|
|
dayList = append(dayList, currDate)
|
|
|
}
|
|
|
+ currDate = currDate.AddDate(0, 0, 1)
|
|
|
}
|
|
|
- currDate = currDate.AddDate(0, 0, 1)
|
|
|
- }
|
|
|
- case "年度":
|
|
|
- for currDate := startDate; currDate.Before(endDate) || currDate.Equal(endDate); {
|
|
|
- currDate = time.Date(currDate.Year()+1, 12, 31, 0, 0, 0, 0, time.Now().Location())
|
|
|
- if !currDate.After(endDate) && !currDate.Equal(startDate) {
|
|
|
+
|
|
|
+ case "季度":
|
|
|
+ currDate := startDate
|
|
|
+ endNum = endNum * 3
|
|
|
+ for i := 0; i <= endNum; i++ {
|
|
|
+ currDate = time.Date(currDate.Year(), currDate.Month(), 1, 0, 0, 0, 0, time.Now().Location()).AddDate(0, 1, -1)
|
|
|
+ if currDate.After(startDate) {
|
|
|
+ // 季度日期就写入,否则不写入
|
|
|
+ if currDate.Month() == 3 || currDate.Month() == 6 || currDate.Month() == 9 || currDate.Month() == 12 {
|
|
|
+ dayList = append(dayList, currDate)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ currDate = currDate.AddDate(0, 0, 1)
|
|
|
+ }
|
|
|
+ case "半年度":
|
|
|
+ currDate := startDate
|
|
|
+ endNum = endNum * 6
|
|
|
+ for i := 0; i <= endNum; i++ {
|
|
|
+ currDate = time.Date(currDate.Year(), currDate.Month(), 1, 0, 0, 0, 0, time.Now().Location()).AddDate(0, 1, -1)
|
|
|
+ if currDate.After(startDate) {
|
|
|
+ // 季度日期就写入,否则不写入
|
|
|
+ if currDate.Month() == 6 || currDate.Month() == 12 {
|
|
|
+ dayList = append(dayList, currDate)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ currDate = currDate.AddDate(0, 0, 1)
|
|
|
+ }
|
|
|
+ case "年度":
|
|
|
+ for i := 1; i <= endNum; i++ {
|
|
|
+ currDate := startDate.AddDate(i, 0, 0)
|
|
|
+ currDate, _ = time.ParseInLocation(utils.FormatDate, fmt.Sprintf(`%d-12-31`, currDate.Year()), time.Local)
|
|
|
dayList = append(dayList, currDate)
|
|
|
}
|
|
|
}
|
|
@@ -1154,7 +1233,7 @@ func GetPredictDataListByPredictEdbConfList(edbInfo, sourceEdbInfoItem *EdbInfo,
|
|
|
var predictMinValue, predictMaxValue float64
|
|
|
// 如果有配置的预测规则,那么就进行预测
|
|
|
if len(predictEdbConfList) > 0 {
|
|
|
- predictDataList, predictMinValue, predictMaxValue, err = GetChartPredictEdbInfoDataListByConfList(predictEdbConfList, startDate, sourceEdbInfoItem.LatestDate, endDateStr, edbInfo.Frequency, edbInfo.DataDateType, allDataList)
|
|
|
+ predictDataList, predictMinValue, predictMaxValue, err = GetChartPredictEdbInfoDataListByConfList(predictEdbConfList, startDate, sourceEdbInfoItem.LatestDate, endDateStr, edbInfo.Frequency, edbInfo.DataDateType, edbInfo.EndDateType, allDataList)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|