|
@@ -100,6 +100,7 @@ func GetChartEdbData(chartInfoId int, startDate, endDate string, edbInfoMapping,
|
|
|
var zlFutureGoodEdbInfo *future_good_edb_info.FutureGoodEdbInfo
|
|
|
var latestDate string // 最新日期是这个
|
|
|
var regionType string // 交易所来源:“国内”,“海外”
|
|
|
+ var futureGoodEdbType int
|
|
|
{
|
|
|
// 寻找主力合约
|
|
|
zlFutureGoodEdbInfo, err = future_good_edb_info.GetFutureGoodEdbInfo(futureGoodEdbInfoMapping.EdbInfoId)
|
|
@@ -107,6 +108,7 @@ func GetChartEdbData(chartInfoId int, startDate, endDate string, edbInfoMapping,
|
|
|
return
|
|
|
}
|
|
|
regionType = zlFutureGoodEdbInfo.RegionType
|
|
|
+ futureGoodEdbType = int(zlFutureGoodEdbInfo.FutureGoodEdbType)
|
|
|
|
|
|
// 如果当前合约配置的 "画图时,日期来源的指标id" 并不是自己的话,那么就去查找对应配置的合约
|
|
|
if uint64(zlFutureGoodEdbInfo.DateSourceID) != zlFutureGoodEdbInfo.FutureGoodEdbInfoID {
|
|
@@ -318,7 +320,7 @@ func GetChartEdbData(chartInfoId int, startDate, endDate string, edbInfoMapping,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- tmpXDataList, newYDataList, err := handleResultData(regionType, yDataList, futureGoodEdbInfoList, maxIndex)
|
|
|
+ tmpXDataList, newYDataList, err := handleResultData(regionType, futureGoodEdbType, yDataList, futureGoodEdbInfoList, maxIndex)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -413,9 +415,17 @@ func BarChartData(edbInfoMapping *chartEdbMappingModel.ChartEdbInfoMappingList,
|
|
|
}
|
|
|
} else {
|
|
|
for i, v := range futureGoodMappingList {
|
|
|
- if v.Year > currYear || (v.Year == currYear && int(v.Month) > int(currMonth)) {
|
|
|
+ if v.FutureGoodEdbType == 2 {
|
|
|
+ if i == 0 {
|
|
|
+ continue
|
|
|
+ }
|
|
|
indexList = append(indexList, i)
|
|
|
- mList = append(mList, (v.Year-currYear)*12+int(v.Month)-int(currMonth))
|
|
|
+ mList = append(mList, int(v.Month))
|
|
|
+ } else {
|
|
|
+ if v.Year > currYear || (v.Year == currYear && int(v.Month) > int(currMonth)) {
|
|
|
+ indexList = append(indexList, i)
|
|
|
+ mList = append(mList, (v.Year-currYear)*12+int(v.Month)-int(currMonth))
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -587,7 +597,7 @@ func FutureGoodChartInfoRefresh(chartInfoId int) (err error) {
|
|
|
}
|
|
|
|
|
|
// handleResultData 处理成最终的结果数据
|
|
|
-func handleResultData(regionType string, yDataList []chart_info.YData, futureGoodEdbInfoList []*future_good_edb_info.FutureGoodEdbInfo, maxIndex int) (xDataList []chart_info.XData, newYDataList []chart_info.YData, err error) {
|
|
|
+func handleResultData(regionType string, futureGoodEdbType int, yDataList []chart_info.YData, futureGoodEdbInfoList []*future_good_edb_info.FutureGoodEdbInfo, maxIndex int) (xDataList []chart_info.XData, newYDataList []chart_info.YData, err error) {
|
|
|
xDataList = make([]chart_info.XData, 0)
|
|
|
newYDataList = yDataList
|
|
|
|
|
@@ -609,6 +619,89 @@ func handleResultData(regionType string, yDataList []chart_info.YData, futureGoo
|
|
|
futureGoodEdbInfoMap[int(v.FutureGoodEdbInfoID)] = v
|
|
|
}
|
|
|
|
|
|
+ if futureGoodEdbType == 2 { // FutureGoodEdbType int `description:"指标类型,1:年月是固定的合约;2:只有M+N期的合约,未固定年月"`
|
|
|
+ nList := []int{3, 15, 27}
|
|
|
+ for _, i := range nList {
|
|
|
+ xDataList = append(xDataList, chart_info.XData{
|
|
|
+ Name: fmt.Sprint("M+", i),
|
|
|
+ NameEn: fmt.Sprint("M+", i),
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ for yIndex, yData := range yDataList {
|
|
|
+ newYDataList[yIndex].XEdbInfoIdList = []int{}
|
|
|
+ newYDataList[yIndex].Value = []float64{}
|
|
|
+ tmpNList := nList
|
|
|
+
|
|
|
+ //当前的主力合约
|
|
|
+ newYDataList[yIndex].XEdbInfoIdList = append(newYDataList[yIndex].XEdbInfoIdList, yData.XEdbInfoIdList[0])
|
|
|
+ newYDataList[yIndex].Value = append(newYDataList[yIndex].Value, yData.Value[0])
|
|
|
+
|
|
|
+ xEdbInfoIdList := yData.XEdbInfoIdList[1:]
|
|
|
+ valIndex := 1
|
|
|
+ needNum := 0
|
|
|
+ for _, n := range tmpNList {
|
|
|
+ if len(xEdbInfoIdList) > 0 {
|
|
|
+ edbInfoId := xEdbInfoIdList[0]
|
|
|
+ futureGoodEdbInfo, ok := futureGoodEdbInfoMap[edbInfoId]
|
|
|
+ if !ok {
|
|
|
+ err = errors.New("找不到指标")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 当前距离最早的日期相差的N数
|
|
|
+ if int(futureGoodEdbInfo.Month) == n {
|
|
|
+ if needNum > 0 {
|
|
|
+ currVal := yData.Value[valIndex]
|
|
|
+ preVal := yData.Value[valIndex-1]
|
|
|
+ hcValDeci := decimal.NewFromFloat(currVal).Sub(decimal.NewFromFloat(preVal)).Div(decimal.NewFromInt(int64(needNum + 1)))
|
|
|
+
|
|
|
+ for tmpNum := 0; tmpNum < needNum; tmpNum++ {
|
|
|
+ newYDataList[yIndex].XEdbInfoIdList = append(newYDataList[yIndex].XEdbInfoIdList, 0)
|
|
|
+
|
|
|
+ // 赋值平均值
|
|
|
+ tmpVal, _ := decimal.NewFromFloat(preVal).Add(hcValDeci.Mul(decimal.NewFromInt(int64(tmpNum + 1)))).RoundCeil(4).Float64()
|
|
|
+ newYDataList[yIndex].Value = append(newYDataList[yIndex].Value, tmpVal)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ newYDataList[yIndex].XEdbInfoIdList = append(newYDataList[yIndex].XEdbInfoIdList, edbInfoId)
|
|
|
+ newYDataList[yIndex].Value = append(newYDataList[yIndex].Value, yData.Value[valIndex])
|
|
|
+ valIndex++
|
|
|
+ needNum = 0
|
|
|
+ if len(xEdbInfoIdList) > 0 {
|
|
|
+ xEdbInfoIdList = xEdbInfoIdList[1:]
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ needNum++
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ maxI := 0
|
|
|
+ for _, yData := range newYDataList {
|
|
|
+ lenEdb := len(yData.XEdbInfoIdList)
|
|
|
+ for i := 0; i < lenEdb; i++ {
|
|
|
+ if yData.XEdbInfoIdList[i] != 0 && !utils.InArrayByInt(yData.NoDataEdbList, yData.XEdbInfoIdList[i]) {
|
|
|
+ if maxI < i {
|
|
|
+ maxI = i
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ xDataList = xDataList[0:maxI]
|
|
|
+ for yIndex, yData := range newYDataList {
|
|
|
+ if len(yData.XEdbInfoIdList) > maxI+1 {
|
|
|
+ newYDataList[yIndex].XEdbInfoIdList = yData.XEdbInfoIdList[0 : maxI+1]
|
|
|
+ }
|
|
|
+ if len(yData.Value) > maxI+1 {
|
|
|
+ newYDataList[yIndex].Value = yData.Value[0 : maxI+1]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
nMap := make(map[int]int)
|
|
|
|
|
|
for _, v := range yDataList {
|
|
@@ -769,13 +862,13 @@ func getFutureGoodEdbInfoList(latestDateTime time.Time, tmpFutureGoodEdbInfoList
|
|
|
//海外的连续日期,目前
|
|
|
if v.FutureGoodEdbType == 2 {
|
|
|
if int(v.Month) <= maxM {
|
|
|
- addMonth := int(earliestDateTime.Month()) + int(v.Month)
|
|
|
- v.Year = earliestDateTime.Year() + addMonth/12
|
|
|
- realMonth := addMonth % 12
|
|
|
- if realMonth == 0 {
|
|
|
- realMonth = 12
|
|
|
- }
|
|
|
- v.Month = uint32(realMonth)
|
|
|
+ //addMonth := int(earliestDateTime.Month()) + int(v.Month)
|
|
|
+ //v.Year = earliestDateTime.Year() + addMonth/12
|
|
|
+ //realMonth := addMonth % 12
|
|
|
+ //if realMonth == 0 {
|
|
|
+ // realMonth = 12
|
|
|
+ //}
|
|
|
+ //v.Month = uint32(realMonth)
|
|
|
futureGoodEdbInfoList = append(futureGoodEdbInfoList, v)
|
|
|
}
|
|
|
continue
|